本文整理汇总了C++中devopen函数的典型用法代码示例。如果您正苦于以下问题:C++ devopen函数的具体用法?C++ devopen怎么用?C++ devopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了devopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例11: pmcopen
static Chan*
pmcopen(Chan *c, int omode)
{
if (!iseve())
error(Eperm);
return devopen(c, omode, nil, 0, pmcgen);
}
示例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);
}
示例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;
}
示例14: acpiopen
static Chan*
acpiopen(Chan *c, int omode)
{
if( !iseve() ) {
error( Eperm );
}
return devopen( c, omode, acpidir, nelem(acpidir), devgen);
}
示例15: dsoopen
static Chan*
dsoopen(Chan *c, int omode)
{
if(!iseve())
error(Eperm);
return devopen(c, omode, dsotab, nfichtab+2, devgen);
}