当前位置: 首页>>代码示例>>C++>>正文


C++ Bopen函数代码示例

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


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

示例1: s_allocinstack

/* initialize */
extern Sinstack *
s_allocinstack(char *file)
{
	Sinstack *sp;
	Biobuf *fp;

	fp = Bopen(file, OREAD);
	if(fp == nil)
		return nil;

	sp = malloc(sizeof *sp);
	sp->depth = 0;
	sp->fp[0] = fp;
	return sp;
}
开发者ID:99years,项目名称:plan9,代码行数:16,代码来源:s_rdinstack.c

示例2: openPW

static Biobuf*
openPW(char *id, int mode)
{
	int nfn = strlen(SECSTORE_DIR)+strlen(id)+20;
	char *fn;
	Biobuf *b;

	if(validatefile(id) == nil || strcmp(id,".") == 0)
		return nil;
	fn = emalloc(nfn);
	snprint(fn, nfn, "%s/who/%s", SECSTORE_DIR, id);
	b = Bopen(fn, mode);
	free(fn);
	return b;
}
开发者ID:AustenConrad,项目名称:plan-9,代码行数:15,代码来源:password.c

示例3: readlife

void
readlife(char *filename)
{
	int c, i, j;
	char name[256];
	Biobuf *bp;

	if ((bp = Bopen(filename, OREAD)) == nil) {
		snprint(name, sizeof name, "/sys/games/lib/life/%s", filename);
		if ((bp = Bopen(name, OREAD)) == nil)
			sysfatal("can't read %s: %r", name);
	}
	draw(screen, screen->r, display->white, nil, ZP);
	for (i = 0; i != NLIFE; i++) {
		row[i] = col[i] = 0;
		for (j = 0; j != NLIFE; j++)
			life[i][j] = 0;
	}
	c = 0;
	for (i = 1; i != NLIFE - 1 && c >= 0; i++) {
		j = 1;
		while ((c = Bgetc(bp)) >= 0 && c != '\n')
			if (j != NLIFE - 1)
				switch (c) {
				case '.':
					j++;
					break;
				case 'x':
					birth(i, j);
					j++;
					break;
				}
	}
	Bterm(bp);
	centerlife();
}
开发者ID:npe9,项目名称:harvey,代码行数:36,代码来源:life.c

示例4: readjobs

/*
 * parse user's cron file
 * other lines: minute hour monthday month weekday host command
 */
Job *
readjobs(char *file, User *user)
{
	Biobuf *b;
	Job *j, *jobs;
	Dir *d;
	int line;

	d = dirstat(file);
	if(!d)
		return nil;
	b = Bopen(file, OREAD);
	if(!b){
		free(d);
		return nil;
	}
	jobs = nil;
	user->lastqid = d->qid;
	free(d);
	for(line = 1; savec = Brdline(b, '\n'); line++){
		savec[Blinelen(b) - 1] = '\0';
		while(*savec == ' ' || *savec == '\t')
			savec++;
		if(*savec == '#' || *savec == '\0')
			continue;
		if(strlen(savec) > 1024){
			clog("%s: line %d: line too long", user->name, line);
			continue;
		}
		j = emalloc(sizeof *j);
		j->time.min = gettime(0, 59);
		if(j->time.min && (j->time.hour = gettime(0, 23))
		&& (j->time.mday = gettime(1, 31))
		&& (j->time.mon = gettime(1, 12))
		&& (j->time.wday = gettime(0, 6))
		&& getname(&j->host)){
			j->cmd = emalloc(strlen(savec) + 1);
			strcpy(j->cmd, savec);
			j->next = jobs;
			jobs = j;
		}else{
			clog("%s: line %d: syntax error", user->name, line);
			free(j);
		}
	}
	Bterm(b);
	return jobs;
}
开发者ID:99years,项目名称:plan9,代码行数:52,代码来源:cron.c

示例5: http

void
http(Ticketreq *tr)
{
	Ticket t;
	char tbuf[TICKETLEN+1];
	char key[DESKEYLEN];
	char *p;
	Biobuf *b;
	int n;

	n = strlen(tr->uid);
	b = Bopen("/sys/lib/httppasswords", OREAD);
	if(b == nil){
		replyerror("no password file", raddr);
		return;
	}

	/* find key */
	for(;;){
		p = Brdline(b, '\n');
		if(p == nil)
			break;
		p[Blinelen(b)-1] = 0;
		if(strncmp(p, tr->uid, n) == 0)
		if(p[n] == ' ' || p[n] == '\t'){
			p += n;
			break;
		}
	}
	Bterm(b);
	if(p == nil) {
		randombytes((uchar*)key, DESKEYLEN);
	} else {
		while(*p == ' ' || *p == '\t')
			p++;
		passtokey(key, p);
	}

	/* send back a ticket encrypted with the key */
	randombytes((uchar*)t.chal, CHALLEN);
	mkkey(t.key);
	tbuf[0] = AuthOK;
	t.num = AuthHr;
	safecpy(t.cuid, tr->uid, sizeof(t.cuid));
	safecpy(t.suid, tr->uid, sizeof(t.suid));
	convT2M(&t, tbuf+1, key);
	write(1, tbuf, sizeof(tbuf));
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:48,代码来源:authsrv.c

示例6: buildre

void
buildre(Dreprog *re[3])
{
	Biobuf *b;

	if((b = Bopen(refile, OREAD)) == nil)
		sysfatal("open %s: %r", refile);

	re[0] = Breaddfa(b);
	re[1] = Breaddfa(b);
	re[2] = Breaddfa(b);

	if(re[0]==nil || re[1]==nil || re[2]==nil)
		sysfatal("Breaddfa: %r");
	Bterm(b);
}
开发者ID:00001,项目名称:plan9port,代码行数:16,代码来源:msgtok.c

示例7: opn

Biobuf*
opn(char *p)
{
	Biobuf *fd;

	while ((fd = Bopen(p, OREAD)) == 0) {
		if(msflag || p == devnull)
			fatal("Cannot open file %s - quitting\n", p);
		else {
			fprint(2, "Deroff: Cannot open file %s - continuing\n", p);
			p = devnull;
		}
	}
	linect = 0;
	return(fd);
}
开发者ID:n-t-roff,项目名称:Plan9_troff,代码行数:16,代码来源:deroff.c

示例8: main

void
main(int argc, char *argv[])
{
	Biobuf stdin, stdout;

	while (--argc > 0 && (*++argv)[0] == '-'){
		switch ((*argv)[1]){
		case 's':
			strict = 1;
			continue;
		case 'j':
			join = 1;
			continue;
		case 'l':
			if((*argv)[2] != '\0'){
				maxleng = atoi( &((*argv)[2]) );
			}
			else{
				maxleng = atoi(*++argv);
				argc--;
			}
			maxtabs = maxleng/TABLENG - 2;
			maxleng -= (maxleng + 5)/10;
			continue;
		default:
			fprint(2, "cb: illegal option %c\n", *argv[1]);
			exits("boom");
		}
	}
	Binit(&stdout, 1, OWRITE);
	output = &stdout;
	if (argc <= 0){
		Binit(&stdin, 0, OREAD);
		input = &stdin;
		work();
	} else {
		while (argc-- > 0){
			if ((input = Bopen( *argv, OREAD)) == 0){
				fprint(2, "cb: cannot open input file %s\n", *argv);
				exits("boom");
			}
			work();
			argv++;
		}
	}
	exits(0);
}
开发者ID:00001,项目名称:plan9port,代码行数:47,代码来源:cb.c

示例9: prepare

Biobuf *
prepare(int i, char *arg)
{
	struct line *p;
	int j, h;
	Biobuf *bp;
	char *cp, buf[MAXLINELEN];
	int nbytes;
	Rune r;

	bp = Bopen(arg, OREAD);
	if (!bp) {
		panic(mflag ? 0: 2, "cannot open %s: %r\n", arg);
		return 0;
	}
	if (binary)
		return bp;
	nbytes = Bread(bp, buf, MIN(1024, MAXLINELEN));
	if (nbytes > 0) {
		cp = buf;
		while (cp < buf+nbytes-UTFmax) {
			/*
			 * heuristic for a binary file in the
			 * brave new UNICODE world
			 */
			cp += chartorune(&r, cp);
			if (r == 0 || (r > 0x7f && r <= 0xa0)) {
				binary++;
				return bp;
			}
		}
		Bseek(bp, 0, 0);
	}
	p = MALLOC(struct line, 3);
	for (j = 0; h = readhash(bp, buf); p[j].value = h)
		p = REALLOC(p, struct line, (++j+3));
	len[i] = j;
	file[i] = p;
	input[i] = bp;			/*fix*/
	if (i == 0) {			/*fix*/
		file1 = arg;
		firstchange = 0;
	}
	else
		file2 = arg;
	return bp;
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:47,代码来源:diffio.c

示例10: mapinit

static void
mapinit(char *mapfile)
{
	int nf;
	char *ln;
	char *fields[2];
	Biobuf *bp;
	Map *map;

	if (mapfile == nil)
		return;
	bp = Bopen(mapfile, OREAD);
	if (bp == nil)
		sysfatal("can't read %s", mapfile);
	devmap = nil;
	while ((ln = Brdline(bp, '\n')) != nil) {
		ln[Blinelen(bp)-1] = '\0';
		if (*ln == '\0' || *ln == '#')
			continue;
		nf = tokenize(ln, fields, nelem(fields));
		if (nf != 2)
			continue;
		if(testconfig(fields[0]) != 0) {
			print("bad `from' device %s in %s\n",
				fields[0], mapfile);
			continue;
		}
		map = malloc(sizeof *map);
		map->from = strdup(fields[0]);
		map->to =   strdup(fields[1]);
		map->fdev = iconfig(fields[0]);
		map->tdev = nil;
		if (access(map->to, AEXIST) < 0) {
			/*
			 * map->to isn't an existing file, so it had better be
			 * a config string for a device.
			 */
			if(testconfig(fields[1]) == 0)
				map->tdev = iconfig(fields[1]);
		}
		/* else map->to is the replacement file name */
		map->next = devmap;
		devmap = map;
	}
	Bterm(bp);
}
开发者ID:Requaos,项目名称:harvey,代码行数:46,代码来源:main.c

示例11: topcmd

static int
topcmd(char *arg)
{
	int done, i, lines, n;
	char buf[40], *p;
	Biobuf *b;

	if(*arg == 0)
		return senderr("TOP requires a message number");
	n = atoi(arg)-1;
	if(n < 0 || n >= nmsg || msg[n].deleted)
		return senderr("no such message");
	arg = nextarg(arg);
	if(*arg == 0)
		return senderr("TOP requires a line count");
	lines = atoi(arg);
	if(lines < 0)
		return senderr("bad args to TOP");
	snprint(buf, sizeof buf, "%d/raw", msg[n].upasnum);
	if((b = Bopen(buf, OREAD)) == nil)
		return senderr("message disappeared");
	sendok("");
	while(p = Brdstr(b, '\n', 1)){
		if(p[0]=='.')
			Bputc(&out, '.');
		Bwrite(&out, p, strlen(p));
		Bwrite(&out, "\r\n", 2);
		done = p[0]=='\0';
		free(p);
		if(done)
			break;
	}
	for(i=0; i<lines; i++){
		p = Brdstr(b, '\n', 1);
		if(p == nil)
			break;
		if(p[0]=='.')
			Bwrite(&out, ".", 1);
		Bwrite(&out, p, strlen(p));
		Bwrite(&out, "\r\n", 2);
		free(p);
	}
	sendcrnl(".");
	Bterm(b);
	return 0;
}
开发者ID:npe9,项目名称:harvey,代码行数:46,代码来源:pop3.c

示例12: main

void
main(int argc, char **argv)
{
	int i;
	long a, ae;
	char *p;
	Entry e;

	Binit(&boutbuf, 1, OWRITE);
	dict = &dicts[0];
	ARGBEGIN {
		case 'd':
			p = ARGF();
			dict = 0;
			if(p) {
				for(i=0; dicts[i].name; i++)
					if(strcmp(p, dicts[i].name)==0) {
						dict = &dicts[i];
						break;
					}
			}
			if(!dict) {
				err("unknown dictionary: %s", p);
				exits("nodict");
			}
			break;
		case 'D':
			debug++;
			break;
	ARGEND }
	USED(argc,argv);
	bdict = Bopen(dict->path, OREAD);
	ae = Bseek(bdict, 0, 2);
	if(!bdict) {
		err("can't open dictionary %s", dict->path);
		exits("nodict");
	}
	for(a = 0; a < ae; a = (*dict->nextoff)(a+1)) {
		linelen = 0;
		e = getentry(a);
		Bprint(bout, "%ld\t", a);
		linelen = 4;	/* only has to be approx right */
		(*dict->printentry)(e, 'h');
	}
	exits(0);
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:46,代码来源:mkindex.c

示例13: dssread

Img*
dssread(char *file)
{
	int nx, ny, scale, sumall;
	Pix  *p, *pend;
	uint8_t buf[21];
	Biobuf *bp;
	Img *ip;

	if(debug)
		Bprint(&bout, "reading %s\n", file);
	bp = Bopen(file, OREAD);
	if(bp == 0)
		return 0;
	if(Bread(bp, buf, sizeof(buf)) != sizeof(buf) ||
	   buf[0] != 0xdd || buf[1] != 0x99){
		werrstr("bad format");
		return 0;
	}
	nx = getlong(buf+2);
	ny = getlong(buf+6);
	scale = getlong(buf+10);
	sumall = getlong(buf+14);
	if(debug)
		fprint(2, "%s: nx=%d, ny=%d, scale=%d, sumall=%d, nbitplanes=%d,%d,%d\n",
			file, nx, ny, scale, sumall, buf[18], buf[19], buf[20]);
	ip = malloc(sizeof(Img) + (nx*ny-1)*sizeof(int));
	if(ip == 0){
		Bterm(bp);
		werrstr("no memory");
		return 0;
	}
	ip->nx = nx;
	ip->ny = ny;
	dodecode(bp, ip->a, nx, ny, buf+18);
	ip->a[0] = sumall;	/* sum of all pixels */
	Bterm(bp);
	if(scale > 1){
		p = ip->a;
		pend = &ip->a[nx*ny];
		while(p < pend)
			*p++ *= scale;
	}
	hinv(ip->a, nx, ny);
	return ip;
}
开发者ID:aahud,项目名称:harvey,代码行数:46,代码来源:dssread.c

示例14: listkeys

static int
listkeys(Key **kp)
{
	Biobuf *b;
	Key *k;
	int nk;
	char *p, *f[20];
	int nf;
	mpint *mod, *ek;
	
	*kp = nil;
	if((b = Bopen("/mnt/factotum/ctl", OREAD)) == nil)
		return -1;
	
	k = nil;
	nk = 0;
	while((p = Brdline(b, '\n')) != nil){
		p[Blinelen(b)-1] = '\0';
		nf = tokenize(p, f, nelem(f));
		if(nf == 0 || strcmp(f[0], "key") != 0)
			continue;
		p = find(f, nf, "proto");
		if(p == nil || strcmp(p, "rsa") != 0)
			continue;
		p = find(f, nf, "n");
		if(p == nil || (mod = strtomp(p, nil, 16, nil)) == nil)
			continue;
		p = find(f, nf, "ek");
		if(p == nil || (ek = strtomp(p, nil, 16, nil)) == nil){
			mpfree(mod);
			continue;
		}
		p = find(f, nf, "comment");
		if(p == nil)
			p = "";
		k = erealloc(k, (nk+1)*sizeof(k[0]));
		k[nk].mod = mod;
		k[nk].ek = ek;
		k[nk].comment = emalloc(strlen(p)+1);
		strcpy(k[nk].comment, p);
		nk++;
	}
	Bterm(b);
	*kp = k;
	return nk;	
}
开发者ID:bhanug,项目名称:harvey,代码行数:46,代码来源:agent.c

示例15: main

int
main(int argc, char *argv[])
{
	int i;
	Biobuf in, *inp;
	Rune r;

	for(i=0; i<nelem(htmlchars); i++){
		chartorune(&r, htmlchars[i].utf);
		htmlchars[i].value = r;
	}
	qsort(htmlchars, nelem(htmlchars), sizeof(htmlchars[0]), hccmp);

	ARGBEGIN{
	case 't':
		title = ARGF();
		if(title == nil)
			usage();
		break;
	case 'd':
		debug++;
		break;
	default:
		usage();
	}ARGEND

	Binit(&bout, 1, OWRITE);
	if(argc == 0){
		header(title);
		Binit(&in, 0, OREAD);
		process(&in, "<stdin>");
	}else{
		header(title);
		for(i=0; i<argc; i++){
			inp = Bopen(argv[i], OREAD);
			if(inp == nil)
				sysfatal("can't open %s: %r", argv[i]);
			process(inp, argv[i]);
			Bterm(&(inp->Biobufhdr));
		}
	}
	flush();
	trailer();
	exits(nil);
}
开发者ID:n-t-roff,项目名称:Plan9_troff,代码行数:45,代码来源:troff2html.c


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