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


C++ dirfstat函数代码示例

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


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

示例1: attachprocess

void
attachprocess(void)
{
	char buf[100];
	Dir *sym, *mem;
	int fd;

	if (!adrflg) {
		dprint("used pid$a\n");
		return;
	}
	sym = dirfstat(fsym);
	sprint(buf, "/proc/%lu/mem", adrval);
	corfil = buf;
	setcor();
	sprint(buf, "/proc/%lu/text", adrval);
	fd = open(buf, OREAD);
	mem = nil;
	if (sym==nil || fd < 0 || (mem=dirfstat(fd))==nil
				|| sym->qid.path != mem->qid.path)
		dprint("warning: text images may be inconsistent\n");
	free(sym);
	free(mem);
	if (fd >= 0)
		close(fd);
}
开发者ID:Requaos,项目名称:harvey,代码行数:26,代码来源:setup.c

示例2: checkqid

void
checkqid(int f1, int pid)
{
	int fd;
	Dir *d1, *d2;
	char buf[128];

	if(kernel || rdebug)
		return;

	d1 = dirfstat(f1);
	if(d1 == nil)
		fatal("checkqid: (qid not checked) dirfstat: %r");

	sprint(buf, "/proc/%d/text", pid);
	fd = open(buf, OREAD);
	if(fd < 0 || (d2 = dirfstat(fd)) == nil){
		fatal("checkqid: (qid not checked) dirstat %s: %r", buf);
		return;	/* not reached */
	}

	close(fd);

	if(d1->qid.path != d2->qid.path || d1->qid.vers != d2->qid.vers || d1->qid.type != d2->qid.type){
		print("path %llux %llux vers %lud %lud type %d %d\n",
			d1->qid.path, d2->qid.path, d1->qid.vers, d2->qid.vers, d1->qid.type, d2->qid.type);
		print("warning: image does not match text for pid %d\n", pid);
	}
	free(d1);
	free(d2);
}
开发者ID:JamesLinus,项目名称:inferno,代码行数:31,代码来源:main.c

示例3: readfile

char*
readfile(char *dir, char *name, int *np)
{
	char *file, *data;
	int fd, len;
	Dir *d;

	if(np != nil)
		*np = 0;
	file = estrstrdup(dir, name);
	fd = open(file, OREAD);
	if(fd < 0)
		return nil;
	d = dirfstat(fd);
	free(file);
	len = 0;
	if(d != nil)
		len = d->length;
	free(d);
	data = emalloc(len+1);
	read(fd, data, len);
	close(fd);
	if(np != nil)
		*np = len;
	return data;
}
开发者ID:Requaos,项目名称:harvey,代码行数:26,代码来源:mesg.c

示例4: ls

void
ls(char *file)
{
	Dir *d;
	int fd, i, nd;

	fd = open(file, OREAD);
	if(fd < 0)
		return;

	/*
	 * read box to find all messages
	 * each one has a directory, and is in numerical order
	 */
	d = dirfstat(fd);
	if(d == nil){
		close(fd);
		return;
	}
	if(!(d->mode & DMDIR)){
		fprint(2, "file %s\n", file);
		free(d);
		close(fd);
		return;
	}
	free(d);
	while((nd = dirread(fd, &d)) > 0){
		for(i = 0; i < nd; i++){
			fprint(2, "%s/%s %c\n", file, d[i].name, "-d"[(d[i].mode & DMDIR) == DMDIR]);
		}
		free(d);
	}
	close(fd);
}
开发者ID:99years,项目名称:plan9,代码行数:34,代码来源:debug.c

示例5: armove

/*
 *	Copy the file referenced by fd to the temp file
 */
void
armove(Biobuf *b, Arfile *ap, Armember *bp)
{
    char *cp;
    Dir *d;

    if ((d = dirfstat(Bfildes(b))) == nil) {
        fprint(2, "ar: cannot stat %s: %r\n", file);
        return;
    }
    trim(file, bp->hdr.name, sizeof(bp->hdr.name));
    for (cp = strchr(bp->hdr.name, 0);		/* blank pad on right */
            cp < bp->hdr.name+sizeof(bp->hdr.name); cp++)
        *cp = ' ';
    sprint(bp->hdr.date, "%-12ld", d->mtime);
    sprint(bp->hdr.uid, "%-6d", 0);
    sprint(bp->hdr.gid, "%-6d", 0);
    sprint(bp->hdr.mode, "%-8lo", d->mode);
    sprint(bp->hdr.size, "%-10lld", (vlong)d->length);
    strncpy(bp->hdr.fmag, ARFMAG, 2);
    bp->size = d->length;
    bp->date = d->mtime;
    arread(b, bp, bp->size);
    if (d->length&0x01)
        d->length++;
    if (ap) {
        arinsert(ap, bp);
        ap->size += d->length+SAR_HDR;
    }
    free(d);
}
开发者ID:tusharsoni,项目名称:Inferno,代码行数:34,代码来源:ar.c

示例6: copyData

/*
 * copies while holding the mail lock,
 * then tries to copy permissions and group ownership
 */
static int
copyData(int ffd, int tfd, MbLock *ml)
{
	Dir *fd, td;
	char buf[BufSize];
	int n;

	for(;;){
		n = read(ffd, buf, BufSize);
		if(n <= 0){
			if(n < 0)
				return 0;
			break;
		}
		if(write(tfd, buf, n) != n)
			return 0;
		mbLockRefresh(ml);
	}
	fd = dirfstat(ffd);
	if(fd != nil){
		nulldir(&td);
		td.mode = fd->mode;
		if(dirfwstat(tfd, &td) >= 0){
			nulldir(&td);
			td.gid = fd->gid;
			dirfwstat(tfd, &td);
		}
	}
	return 1;
}
开发者ID:AustenConrad,项目名称:plan-9,代码行数:34,代码来源:folder.c

示例7: openfont

Font*
openfont(Display *d, char *name)
{
	Font *fnt;
	int fd, i, n;
	char *buf;
	Dir *dir;

	fd = open(name, OREAD);
	if(fd < 0)
		return 0;

	dir = dirfstat(fd);
	if(dir == nil){
    Err0:
		close(fd);
		return 0;
	}
	n = dir->length;
	free(dir);
	buf = malloc(n+1);
	if(buf == 0)
		goto Err0;
	buf[n] = 0;
	i = read(fd, buf, n);
	close(fd);
	if(i != n){
		free(buf);
		return 0;
	}
	fnt = buildfont(d, buf, name);
	free(buf);
	return fnt;
}
开发者ID:keedon,项目名称:harvey,代码行数:34,代码来源:openfont.c

示例8: fscreate

void
fscreate(Chan *c, char *name, int mode, ulong perm)
{
	Dir *d;
	Cname *n;

	if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		error(Efilename);
	n = addelem(newcname(FS(c)->name->s), name);
	osenter();
	FS(c)->fd = create(n->s, mode, perm);
	osleave();
	if(FS(c)->fd < 0) {
		cnameclose(n);
		fserr(FS(c));
	}
	d = dirfstat(FS(c)->fd);
	if(d == nil) {
		cnameclose(n);
		close(FS(c)->fd);
		FS(c)->fd = -1;
		fserr(FS(c));
	}
	c->qid = d->qid;
	free(d);

	cnameclose(FS(c)->name);
	FS(c)->name = n;

	c->mode = openmode(mode);
	c->offset = 0;
	FS(c)->offset = 0;
	c->flag |= COPEN;
}
开发者ID:8l,项目名称:inferno,代码行数:34,代码来源:devfs.c

示例9: ndbchanged

/*
 *  return true if any part of the database has changed
 */
int
ndbchanged(struct ndb *db)
{
	/* TODO: implement me (no one calls this yet) */
	assert(0);
	return 0;
#if 0
	struct ndb *ndb;
	struct dir *d;

/* FIX ME */
	for(ndb = db; ndb != NULL; ndb = ndb->next){
		d = dirfstat(Bfildes(&ndb->b));
		if(d == NULL)
			continue;
		if(ndb->qid.path != d->qid.path
		|| ndb->qid.vers != d->qid.vers){
			free(d);
			return 1;
		}
		free(d);
	}
	return 0;
#endif
}
开发者ID:dhootha,项目名称:akaros,代码行数:28,代码来源:ndbopen.c

示例10: ndbreopen

/*
 *  dump any cached information, forget the hash tables, and reopen a single file
 */
int
ndbreopen(struct ndb *db)
{
	int fd;
	struct dir *d;

	/* forget what we know about the open files */
	if(db->isopen){
		_ndbcacheflush(db);
		hffree(db);
		fclose(db->b);
		db->mtime = 0;
		db->isopen = 0;
	}

	/* try the open again */
	db->b = fopen(db->file, "r");
	if(! db->b)
		return -1;
#if 0
	d = dirfstat(fd);
	if(d == NULL){
		close(fd);
		return -1;
	}

	db->qid = d->qid;
	db->mtime = d->mtime;
	db->length = d->length;
	free(d);
#endif
	db->isopen = 1;
	return 0;
}
开发者ID:alfongj,项目名称:akaros,代码行数:37,代码来源:ndbopen.c

示例11: main

void
main(int argc, char *argv[])
{
    Dir *d;
    char *p, *file;
    int fd, len;

    ARGBEGIN{
    case 'p':
        usepass = 1;
        break;
    case 'v':
        verb = 1;
        break;
    case 'a':
        convaes = 1;
        break;
    default:
        usage();
    } ARGEND

    if(argc != 1)
        usage();
    file = argv[0];

    /* get original key */
    if(usepass) {
        print("enter password file is encoded with\n");
        getpass(&okey, nil, 0, 1);
    } else {
        getauthkey(&okey);
    }
    if(!verb) {
        print("enter password to reencode with\n");
        getpass(&nkey, nil, 0, 1);
    }

    fd = open(file, ORDWR);
    if(fd < 0)
        error("can't open %s: %r\n", file);
    d = dirfstat(fd);
    if(d == nil)
        error("can't stat %s: %r\n", file);
    len = d->length;
    p = malloc(len);
    if(p == nil)
        error("out of memory");
    if(read(fd, p, len) != len)
        error("can't read key file: %r\n");
    len = convert(&p, len);
    if(pwrite(fd, p, len, 0) != len)
        error("can't write key file: %r\n");
    close(fd);
    exits(nil);
}
开发者ID:srk-cmu,项目名称:9problems,代码行数:55,代码来源:convkeys.c

示例12: print_item

void
print_item(char *file)
{
	char name[4096], *p, *ep;
	Dir *dbuf;
	int f, c;
	int bol, bop;

	sprint(name, "%s/%s", NEWS, file);
	f = open(name, OREAD);
	if(f < 0) {
		fprint(2, "news: ");
		perror(name);
		return;
	}
	strcpy(name, "...");
	dbuf = dirfstat(f);
	if(dbuf == nil)
		return;
	Bprint(&bout, "\n%s (%s) %s\n", file,
		dbuf->muid[0]? dbuf->muid : dbuf->uid,
		asctime(localtime(dbuf->mtime)));
	free(dbuf);

	bol = 1;	/* beginning of line ...\n */
	bop = 1;	/* beginning of page ...\n\n */
	for(;;) {
		c = read(f, name, sizeof(name));
		if(c <= 0)
			break;
		p = name;
		ep = p+c;
		while(p < ep) {
			c = *p++;
			if(c == '\n') {
				if(!bop) {
					Bputc(&bout, c);
					if(bol)
						bop = 1;
					bol = 1;
				}
				continue;
			}
			if(bol) {
				Bputc(&bout, '\t');
				bol = 0;
				bop = 0;
			}
			Bputc(&bout, c);
		}
	}
	if(!bol)
		Bputc(&bout, '\n');
	close(f);
}
开发者ID:00001,项目名称:plan9port,代码行数:55,代码来源:news.c

示例13: main

void
main(int argc, char *argv[])
{
	Dir *d;
	char *p, *np, *file, key[DESKEYLEN];
	int fd, len;

	ARGBEGIN{
	case 'v':
		verb = 1;
		break;
	case 'p':
		usepass = 1;
		break;
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();
	file = argv[0];

	/* get original key */
	if(usepass){
		print("enter password file is encoded with\n");
		getpass(authkey, nil, 0, 1);
	} else
		getauthkey(authkey);
	print("enter password to reencode with\n");
	getpass(key, nil, 0, 1);

	fd = open(file, ORDWR);
	if(fd < 0)
		error("can't open %s: %r\n", file);
	d = dirfstat(fd);
	if(d == nil)
		error("can't stat %s: %r\n", file);
	len = d->length;
	p = malloc(len);
	if(!p)
		error("out of memory");
	np = malloc((len/OKEYDBLEN)*KEYDBLEN + KEYDBOFF);
	if(!np)
		error("out of memory");
	if(read(fd, p, len) != len)
		error("can't read key file: %r\n");
	len = convert(p, np, key, len);
	if(verb)
		exits(0);
	if(pwrite(fd, np, len, 0) != len)
		error("can't write key file: %r\n");
	close(fd);
	exits(0);
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:54,代码来源:convkeys2.c

示例14: hintprint

void
hintprint(HConnect *hc, Hio *hout, char *uri, int thresh, int havej)
{
	int i, j, pr, prefix, fd, siz, havei, newhint = 0, n;
	char *query, *sf, etag[32], *wurl;
	Dir *dir;
	Hint *h, *haveh;

	query = hstrdup(hc, uri);
	urlcanon(query);
	j = urllookup(hashstr(query));
	if(j < 0)
		return;
	query = strrchr(uri,'/');
	if(!query)
		return;  /* can't happen */
	prefix = query-uri+1;  /* = strlen(dirname)+1 */
	h = hints[j];
	for(i=0; i<nhint[j]; i++){
		if(havej > 0 && havej < URLmax){ /* exclude hints client has */
			haveh = hints[havej];
			for(havei=0; havei<nhint[havej]; havei++)
				if( haveh[havei].url == h[i].url)
					goto continuei;
		}
		sf = urlname[h[i].url];
		pr = h[i].prob;
		if(pr<thresh)
			break;
		n = strlen(webroot) + strlen(sf) + 1;
		wurl = halloc(hc, n);
		strcpy(wurl, webroot);
		strcat(wurl, sf);
		fd = open(wurl, OREAD);
		if(fd<0)
			continue;
		dir = dirfstat(fd);
		if(dir == nil){
			close(fd);
			continue;
		}
		close(fd);
		snprint(etag, sizeof(etag), "\"%lluxv%lx\"", dir->qid.path, dir->qid.vers);
		siz = (int)( log((double)dir->length) * RECIPLOG2 + 0.9999);
		free(dir);
		if(strncmp(uri,sf,prefix)==0 && strchr(sf+prefix,'/')==0 && sf[prefix]!=0)
			sf = sf+prefix;
		hprint(hout, "Fresh: %d,%s,%d,%s\r\n", pr, etag, siz, sf);
		newhint++;
continuei: ;
	}
	if(newhint)
		hprint(hout, "Fresh: have/%d\r\n", j);
}
开发者ID:aahud,项目名称:harvey,代码行数:54,代码来源:hints.c

示例15: mminit

void
mminit(char *file, int mode)
{
	Dir *d;
	uintptr va;
	void *p, *np;
	int hashsize; /* make it a power of two -- see why later */

	ventifd = open(file, mode);
	if (ventifd < 0)
		sysfatal("Can't open %s: %r\n", file);
	d = dirfstat(ventifd);
	if (! d)
		sysfatal("Can't stat %s: %r", file);

	/* allocate: size for the file, 1/32 that size for the map, and 
	 * start it at the 1 GB boundary, please. 
	 */
	/* get top of heap */
	p = segbrk(0, 0);
	va = (uintptr)p;
	/* no non-nix systems we just usr sbrk and only have little pages */
	hashsize = d->length/32;
	maxmap = hashsize / sizeof(*maps);
	hashb = log2(maxmap);
	if (va == (uintptr)-1) {
		p = sbrk(0);
		va = (uintptr)p;
		maps = (void *)va;
		va += hashsize;
		mmventidatabase = mmventidata = (void *)va;
		va += d->length;
		va = ROUNDUP((va), 4096);
		if (brk((void *)va) < 0)
			sysfatal("brk to %#p failed\n", (void *)va);
	} else {
		va = ROUNDUP((va), 1ULL*GiB);
		maps = (void *)va;
		va += hashsize;
		mmventidatabase = mmventidata = (void *)va;
		va += d->length;
		va = ROUNDUP((va), 1ULL*GiB);
		segbrk(0, (void *)va);
	}
	fprint(2, "mmventidatabase is %#p\n", mmventidatabase);

	fprint(2, "File size %lld, hashsize %d, maps %#p, data %#p\n", d->length, 
		hashsize, maps, mmventidata);
	/* morecore */
	np=(void*)va;
	segbrk(p, np);

	reload();
}
开发者ID:CoryXie,项目名称:nix-os,代码行数:54,代码来源:mmventi.c


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