• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ devopen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中devopen函数的典型用法代码示例。如果您正苦于以下问题:C++ devopen函数的具体用法?C++ devopen怎么用?C++ devopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了devopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: slip_init

/*---------------------------------------------------------------------------*/
void
slip_init(void)
{
  setvbuf(stdout, NULL, _IOLBF, 0);     /* Line buffered output. */

  if(slip_config_host != NULL) {
    if(slip_config_port == NULL) {
      slip_config_port = "60001";
    }
    slipfd = connect_to_server(slip_config_host, slip_config_port);
    if(slipfd == -1) {
      err(1, "can't connect to ``%s:%s''", slip_config_host,
          slip_config_port);
    }

  } else if(slip_config_siodev != NULL) {
    if(strcmp(slip_config_siodev, "null") == 0) {
      /* Disable slip */
      return;
    }
    slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
    if(slipfd == -1) {
      err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
    }

  } else {
    static const char *siodevs[] = {
      "ttyUSB0", "cuaU0", "ucom0"       /* linux, fbsd6, fbsd5 */
    };
    int i;

    for(i = 0; i < 3; i++) {
      slip_config_siodev = siodevs[i];
      slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
      if(slipfd != -1) {
        break;
      }
    }
    if(slipfd == -1) {
      err(1, "can't open siodev");
    }
  }

  select_set_callback(slipfd, &slip_callback);

  if(slip_config_host != NULL) {
    printf("********SLIP opened to ``%s:%s''\n", slip_config_host,
           slip_config_port);
  } else {
    printf("********SLIP started on ``/dev/%s''\n", slip_config_siodev);
    stty_telos(slipfd);
  }

  timer_set(&send_delay_timer, 0);
  slip_send(slipfd, SLIP_END);
  inslip = fdopen(slipfd, "r");
  if(inslip == NULL) {
    err(1, "main: fdopen");
  }
}
开发者ID:calvincoetzee,项目名称:6lbr,代码行数:61,代码来源:slip-dev.c


示例2: slip_init

/*---------------------------------------------------------------------------*/
void
slip_init(void)
{
  setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */

  if(slip_config_siodev != NULL) {
    slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
    if(slipfd == -1) {
      err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
    }
  } else {
    static const char *siodevs[] = {
      "ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */
    };
    int i;
    for(i = 0; i < 3; i++) {
      slip_config_siodev = siodevs[i];
      slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
      if(slipfd != -1) {
	break;
      }
    }
    if(slipfd == -1) {
      err(1, "can't open siodev");
    }
  }

  fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
  stty_telos(slipfd);

  slip_send(slipfd, SLIP_END);
  inslip = fdopen(slipfd, "r");
  if(inslip == NULL) err(1, "main: fdopen");
}
开发者ID:mwasilak,项目名称:contiki-mirror,代码行数:35,代码来源:slip-dev.c


示例3: poweropen

static Chan*
poweropen(Chan* c, int omode)
{
	Puser *p;

	if(c->qid.type & QTDIR)
		return devopen(c, omode, powertab, nelem(powertab), devgen);
	switch(c->qid.path){
	case Qdata:
		p = mallocz(sizeof(Puser), 1);
		if(p == nil)
			error(Enovmem);
		p->state = Pwridle;
		p->ref = 1;
		if(waserror()){
			free(p);
			nexterror();
		}
		c = devopen(c, omode, powertab, nelem(powertab), devgen);
		c->aux = p;
		qlock(&pwrusers);
		p->next = pwrusers.list;
		pwrusers.list = p;	/* note: must place on front of list for correct shutdown ordering */
		qunlock(&pwrusers);
		poperror();
		break;
	case Qctl:
		c = devopen(c, omode, powertab, nelem(powertab), devgen);
		break;
	}
	return c;
}
开发者ID:8l,项目名称:inferno,代码行数:32,代码来源:devpower.c


示例4: devlogfsopen

static Chan*
devlogfsopen(Chan *c, int omode)
{
	int instance, qid, qt;

	omode = openmode(omode);
	SPLITPATH(c->qid.path, c->qid.type, instance, qid, qt);
#ifdef CALLTRACE
	print("devlogfsopen(c = 0x%.8lux, omode = %o, instance = %d, qid = %d, qt = %d)\n",
		(ulong)c, omode, instance, qid, qt);
#endif


	rlock(&devlogfslist.rwlock);
	if (waserror()) {
		runlock(&devlogfslist.rwlock);
#ifdef CALLTRACE
		print("devlogfsopen(c = 0x%.8lux, omode = %o) - error %s\n", (ulong)c, omode, up->env->errstr);
#endif
		nexterror();
	}

	if (DATAQID(qid, qt)) {
		Devlogfs *d;
		d = devlogfsfind(instance);
		if (d == nil)
			error(Enodev);
		if (strcmp(up->env->user, eve) != 0)
			error(Eperm);
		if (qid == Qfs && d->state != BootOpen)
			error(Eperm);
		if (d->server == nil) {
			errorany(logfsservernew(d->lb, d->ll, is, d->openflags, d->logfstrace, &d->server));
			d->state = NeedVersion;
		}
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
		incref(&d->ref);
		c->aux = d;
	}
	else if (qid == Qctl || qid == Qusers) {
		if (strcmp(up->env->user, eve) != 0)
			error(Eperm);
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
	}
	else
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
	poperror();
	runlock(&devlogfslist.rwlock);
#ifdef CALLTRACE
	print("devlogfsopen(c = 0x%.8lux, omode = %o) - return\n", (ulong)c, omode);
#endif
	return c;
}
开发者ID:8l,项目名称:inferno,代码行数:53,代码来源:devlogfs.c


示例5: cmd_ctty

int cmd_ctty(char *param)
{ int fin, fout;
  int failed;

  if(!param || !*param) {
    displayString(TEXT_CMDHELP_CTTY);
    return 1;
  }

#ifdef DEBUG
  devAttr(0);
  devAttr(1);
  devAttr(2);
#endif

  if((fin = devopen(param, O_BINARY | O_RDONLY)) < 0
   || (fout = devopen(param, O_BINARY | O_WRONLY)) < 0) {
    close(fin);     /* if fin failed, close(-1) won't hurt */
    error_no_rw_device(param);
    return 1;
  }

  fflush(stdin);      /* prepare asynchroneous changes of internal fd's */
  fflush(stdout);
  fflush(stderr);

  /* Now change the file descriptors:
    0 := rdonly
    1,2 := wronly

    if CTTY is called within a pipe or its I/O is redirected,
    oldinfd or oldoutfd is not equal to -1. In such case the
    old*fd is modified in order to effect the file descriptor
    after the redirections are restored. Otherwise a pipe or
    redirection would left CTTY in a half-made status.
  */
  failed = dup2(fout, 2);   /* no redirection support */
  if(oldinfd == -1) {     /* stdin not redirected */
    failed = dup2(fin, 0) || failed;
    close(fin);
  } else  oldinfd = fin;
  if(oldoutfd == -1) {      /* stdout not redirected */
    failed = dup2(fout, 1) || failed;
    close(fout);
  } else  oldoutfd = fout;

  if(failed)
    error_ctty_dup(param);

  return failed;
}
开发者ID:TijmenW,项目名称:FreeDOS,代码行数:51,代码来源:ctty.c


示例6: devopen

static struct chan *consopen(struct chan *c, int omode)
{
    c->aux = NULL;
    c = devopen(c, omode, consdir, ARRAY_SIZE(consdir), devgen);
    switch ((uint32_t) c->qid.path) {
    case Qconsctl:
        kref_get(&kbd.ctl, 1);
        break;

    case Qkprint:
        if (atomic_swap(&kprintinuse, 1) != 0) {
            c->flag &= ~COPEN;
            error(EADDRINUSE, "kprintinuse lock failed");
        }
        if (kprintoq == NULL) {
            kprintoq = qopen(8 * 1024, Qcoalesce, 0, 0);
            if (kprintoq == NULL) {
                c->flag &= ~COPEN;
                error(ENOMEM, "Can't allocate kprintoq");
            }
            qdropoverflow(kprintoq, 1);
        } else
            qreopen(kprintoq);
        c->iounit = qiomaxatomic;
        break;
    }
    return c;
}
开发者ID:ihategit,项目名称:akaros,代码行数:28,代码来源:cons.c


示例7: consopen

static Chan*
consopen(Chan *c, int omode)
{
	c->aux = nil;
	c = devopen(c, omode, consdir, nelem(consdir), devgen);
	switch((ulong)c->qid.path){
	case Qkprint:
		if(tas(&kprintinuse) != 0){
			c->flag &= ~COPEN;
			error(Einuse);
		}
		if(kprintoq == nil){
			kprintoq = qopen(8*1024, Qcoalesce, 0, 0);
			if(kprintoq == nil){
				c->flag &= ~COPEN;
				error(Enomem);
			}
			qnoblock(kprintoq, 1);
		}else
			qreopen(kprintoq);
		c->iounit = qiomaxatomic;
		break;
	}
	return c;
}
开发者ID:vrthra,项目名称:9front-tmp,代码行数:25,代码来源:devcons.c


示例8: main

int 
main(void)
{
	struct open_file	f;
	void	*entry;
	char	*addr;
	int error;

#ifdef DEBUG
	printf("bootxx: open...\n");
#endif
	f.f_flags = F_RAW;
	if (devopen(&f, 0, &addr)) {
		putstr("bootxx: devopen failed\n");
		return 1;
	}

	addr = (char*)LOADADDR;
	error = copyboot(&f, addr);
	f.f_dev->dv_close(&f);
	if (!error) {
#ifdef DEBUG
		printf("bootxx: start 0x%x\n", (long)addr);
#endif
		entry = addr;
		chain_to(entry);
	}
	/* copyboot had a problem... */
	return 0;
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:30,代码来源:bootxx.c


示例9: uartopen

static Chan*
uartopen(Chan *c, int omode)
{
	Uart *p;

	c = devopen(c, omode, uartdir, uartndir, devgen);

	switch(UARTTYPE(c->qid.path)){
	case Qctl:
	case Qdata:
		p = uart[UARTID(c->qid.path)];
		qlock(&p->ql);
		if(p->opens == 0 && uartenable(p) == nil){
			qunlock(&p->ql);
			c->flag &= ~COPEN;
			error(Enodev);
		}
		p->opens++;
		qunlock(&p->ql);
		break;
	}

	c->iounit = qiomaxatomic;
	return c;
}
开发者ID:dancrossnyc,项目名称:harvey,代码行数:25,代码来源:devuart.c


示例10: main

main()
{
	struct open_file	f;
	char	*addr;
	int n, error;

	bootdev_type = BUGDEV_DISK;

	printf("Boot: bug device: ctrl=%d, dev=%d\n", 
		bugargs.ctrl_lun, bugargs.dev_lun);
	printf("\nbootxx: first level bootstrap program [%s]\n\n", version);

	f.f_flags = F_RAW;
	if (devopen(&f, 0, &addr)) {
		printf("bootxx: open failed\n");
		_rtt();
	}

	addr = (char *)STAGE2_RELOC;
	error = copyboot(&f, addr);
	f.f_dev->dv_close(&f);
	if (!error) {
		bugexec((void (*)())addr);
	}
	/* copyboot had a problem... */
	_rtt();
}
开发者ID:alenichev,项目名称:openbsd-kernel,代码行数:27,代码来源:bootxx.c


示例11: pmcopen

static Chan*
pmcopen(Chan *c, int omode)
{
	if (!iseve())
		error(Eperm);
	return devopen(c, omode, nil, 0, pmcgen);
}
开发者ID:qioixiy,项目名称:harvey,代码行数:7,代码来源:devpmc.c


示例12: printd

static struct chan *rootopen(struct chan *c, int omode)
{
	int p;
	printd("rootopen: omode %o\n", omode);
	p = c->qid.path;
	return devopen(c, omode, rootdata[p].ptr, rootdata[p].size, rootgen);
}
开发者ID:anandab,项目名称:akaros,代码行数:7,代码来源:root.c


示例13: gpioopen

Chan*
gpioopen(Chan *c, int omode)
{
	int type;
	
	c = devopen(c, omode, 0, 0, gpiogen);
	
	type = FILE_TYPE(c->qid);
	
	switch(type)
	{
	case Qdata:
		c->iounit = 1;
		break;
	case Qctl:
		break;
	case Qevent:
		lock(&eventlock);
		if(eventinuse != 0){
			c->flag &= ~COPEN;
			unlock(&eventlock);
			error(Einuse);
		}
		eventinuse = 1;
		unlock(&eventlock);
		eventvalue = 0;
		c->iounit = 4;
	}

	return c;
}
开发者ID:sirnewton01,项目名称:rpi-9front,代码行数:31,代码来源:gpio.c


示例14: acpiopen

static Chan*
acpiopen(Chan *c, int omode)
{
	if( !iseve() ) {
		error( Eperm );
	}
	return devopen( c, omode, acpidir, nelem(acpidir), devgen);
}
开发者ID:enukane,项目名称:acpi9,代码行数:8,代码来源:devacpi.c


示例15: dsoopen

static Chan*
dsoopen(Chan *c, int omode)
{
	if(!iseve())
		error(Eperm);

	return devopen(c, omode, dsotab, nfichtab+2, devgen);
}
开发者ID:LuisGP,项目名称:Plan9,代码行数:8,代码来源:devdso.C


示例16: rootopen

static Chan*
rootopen(Chan *c, int omode)
{
	int p;

	p = rootdata[c->qid.path].dotdot;
	return devopen(c, omode, rootdata[p].ptr, rootdata[p].size, rootgen);
}
开发者ID:8l,项目名称:inferno,代码行数:8,代码来源:devroot.c


示例17: cmd_ctty

int cmd_ctty(char *param)
{ int f, attr, failed;

  if(!param || !*param) {
    displayString(TEXT_CMDHELP_CTTY);
    return 1;
  }

#ifdef DEBUG
  devAttr(0);
  devAttr(1);
  devAttr(2);
#endif

  if((f = devopen(param, O_RDWR)) < 0) {
    error_no_rw_device(param);
    return 1;
  }

  if(((attr = fdattr(f)) & 0x80) == 0
   || write(f, "\r\n", 2) != 2) {		/* need \r as in bin mode */
    close(f);
    error_no_rw_device(param);
    return 1;
  }

	/* Now inform the system that this device is the new console
		now; STDIN and STDOUT flag are the most lowest two bits  */
	fdsetattr(f, (attr & 0xFF) | 0x03);

  fflush(stdin);      /* prepare asynchroneous changes of internal fd's */
  fflush(stdout);
  fflush(stderr);

  /* Now change the file descriptors:
    0 := rdonly
    1,2 := wronly

    if CTTY is called within a pipe or its I/O is redirected,
    oldinfd or oldoutfd is not equal to -1. In such case the
    old*fd is modified in order to effect the file descriptor
    after the redirections are restored. Otherwise a pipe or
    redirection would left CTTY in a half-made status.
  */
  failed = dup2(f, 2);   /* no redirection support */
  if(oldinfd != -1)
  	close(oldinfd);
  oldinfd = f;
  if(oldoutfd != -1)
  	close(oldoutfd);
  if((oldoutfd = dup(f)) == -1)
  	failed = 1;

  if(failed)
    error_ctty_dup(param);

  return failed;
}
开发者ID:aquashift,项目名称:86Duino_DuinOS,代码行数:58,代码来源:ctty.c


示例18: cmd_type

int cmd_type(char *param)
{
    char buf[256];
    char **argv;
    int argc, opts, ec = E_None;
    int fd, len;

    if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
        return 1;

    /* Because no option was passed into scanCmdline() no
    	option can have been processed */
    assert(opts == 0);

    if(!argc) {
        error_req_param_missing();
        ec = E_Useage;
        goto errRet;
    }

    for(argc = 0; argv[argc]; ++argc) {
        if((fd = devopen(argv[argc], O_RDONLY)) == 0) {
            error_sfile_not_found(argv[argc]);
            ec = E_Other;
            break;
        }

        while((len = dos_read(fd, buf, sizeof(buf))) >= 0) {
            char *bufp, *p;
            if(cbreak) {
                dos_close(fd);
                ec = E_CBreak;
                goto errRet;
            }
            bufp = buf;
            for(p = buf; p < buf+len; p++) {
                if(*p == 26) break; /* CTRL-Z */
                if(*p == '\r' || *p == '\n') {
                    if(p > bufp) dos_write(1, bufp, p - bufp);
                    if(*p == '\n') dos_write(1, "\r\n", 2);
                    bufp = p + 1;
                }
            }
            dos_write(1, bufp, p - bufp);
            if (len < sizeof(buf) || *p == 26) break;
        }
        dos_close(fd);
        if(cbreak) {
            ec = E_CBreak;
            break;
        }
    }

errRet:
    freep(argv);

    return ec;
}
开发者ID:FDOS,项目名称:freecom,代码行数:58,代码来源:type.c


示例19: outportw

void
outportw(int32_t port, uint16_t data)
{
	if(iowfd == -1)
		iowfd = devopen("#P/iow", ORDWR);

	if(pwrite(iowfd, &data, sizeof(data), port) != sizeof(data))
		error("outportw(0x%4.4lx, 0x%2.2X): %r\n", port, data);
}
开发者ID:dancrossnyc,项目名称:harvey,代码行数:9,代码来源:io.c


示例20: wrmsr

void
wrmsr(long port, uvlong data)
{
	if(msrfd == -1)
		msrfd = devopen("#P/msr", ORDWR);

	if(pwrite(msrfd, &data, sizeof(data), port) != sizeof(data))
		error("wrmsr(0x%4.4lx, 0x%2.2lluX): %r\n", port, data);
}
开发者ID:vrthra,项目名称:9front-tmp,代码行数:9,代码来源:io.c



注:本文中的devopen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ devres_add函数代码示例发布时间:2022-05-30
下一篇:
C++ devname函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap