本文整理汇总了C++中Bseek函数的典型用法代码示例。如果您正苦于以下问题:C++ Bseek函数的具体用法?C++ Bseek怎么用?C++ Bseek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bseek函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findCDir
static int
findCDir(Biobuf *bin)
{
int64_t ecoff;
int32_t off;
int entries, zclen;
ecoff = Bseek(bin, -ZECHeadSize, 2);
if(ecoff < 0)
sysfatal("can't seek to header");
if(get4(bin) != ZECHeader)
sysfatal("bad magic number on directory");
get2(bin);
get2(bin);
get2(bin);
entries = get2(bin);
get4(bin);
off = get4(bin);
zclen = get2(bin);
while(zclen-- > 0)
get1(bin);
if(Bseek(bin, off, 0) != off)
sysfatal("can't seek to contents");
return entries;
}
示例2: getentry
Entry
getentry(long b)
{
long e, n, dtop;
static Entry ans;
static int anslen = 0;
e = (*dict->nextoff)(b+1);
ans.doff = b;
if(e < 0) {
dtop = Bseek(bdict, 0L, 2);
if(b < dtop) {
e = dtop;
} else {
err("couldn't seek to entry");
ans.start = 0;
ans.end = 0;
}
}
n = e-b;
if(n) {
if(n > anslen) {
ans.start = realloc(ans.start, n);
if(!ans.start) {
err("out of memory");
exits("nomem");
}
anslen = n;
}
Bseek(bdict, b, 0);
n = Bread(bdict, ans.start, n);
ans.end = ans.start + n;
}
return ans;
}
示例3: doread
char *
doread(Ram *r, int64_t off, int32_t cnt)
{
int i, err;
Block bs;
ZipHead zh;
static Qid oqid;
static char buf[Maxbuf];
static uint8_t *cache = nil;
if (cnt > Maxbuf)
sysfatal("file too big (>%d)", Maxbuf);
if (Bseek(bin, r->addr & 0x7FFFFFFFFFFFFFFFLL, 0) < 0)
sysfatal("seek failed");
memset(&zh, 0, sizeof(zh));
if (!header(bin, &zh))
sysfatal("cannot get local header");
switch(zh.meth){
case 0:
if (Bseek(bin, off, 1) < 0)
sysfatal("seek failed");
if (Bread(bin, buf, cnt) != cnt)
sysfatal("read failed");
break;
case 8:
if (r->qid.path != oqid.path){
oqid = r->qid;
if (cache)
free(cache);
cache = emalloc(r->ndata);
bs.pos = cache;
bs.limit = cache+r->ndata;
if ((err = inflate(&bs, blwrite, bin, (int(*)(void*))Bgetc)) != FlateOk)
sysfatal("inflate failed - %s", flateerr(err));
if (blockcrc(crctab, crc, cache, r->ndata) != zh.crc)
fprint(2, "%s - crc failed", r->name);
if ((r->addr & High64) && MUNGE_CR){
for (i = 0; i < r->ndata -1; i++)
if (cache[i] == '\r' && cache[i +1] == '\n')
cache[i] = ' ';
}
}
memcpy(buf, cache+off, cnt);
break;
default:
sysfatal("%d - unsupported compression method", zh.meth);
break;
}
return buf;
}
示例4: Bfilelen
int64_t
Bfilelen(void *vb)
{
Biobuf *b;
int64_t n;
b = vb;
n = Bseek(b, 0L, 2);
Bseek(b, 0L, 0);
return n;
}
示例5: locate
int
locate(void)
{
vlong top, bot, mid;
long c;
int n;
bot = 0;
top = Bseek(dfile, 0, 2);
for(;;) {
mid = (top+bot) / 2;
Bseek(dfile, mid, 0);
do
c = Bgetrune(dfile);
while(c>=0 && c!='\n');
mid = Boffset(dfile);
if(!getword(dfile, entry, sizeof(entry)/sizeof(entry[0])))
break;
rcanon(entry, word);
n = compare(key, word);
switch(n) {
case -2:
case -1:
case 0:
if(top <= mid)
break;
top = mid;
continue;
case 1:
case 2:
bot = mid;
continue;
}
break;
}
Bseek(dfile, bot, 0);
while(getword(dfile, entry, sizeof(entry)/sizeof(entry[0]))) {
rcanon(entry, word);
n = compare(key, word);
switch(n) {
case -2:
return 0;
case -1:
if(exact)
return 0;
case 0:
return 1;
case 1:
case 2:
continue;
}
}
return 0;
}
示例6: Creadblock
void
Creadblock(Cdimg *cd, void *buf, ulong block, ulong len)
{
assert(block != 0); /* nothing useful there */
Bflush(&cd->bwr);
if(Bseek(&cd->brd, block*Blocksize, 0) != block*Blocksize)
sysfatal("error seeking to block %lud", block);
if(Bread(&cd->brd, buf, len) != len)
sysfatal("error reading %lud bytes at block %lud: %r %lld", len, block, Bseek(&cd->brd, 0, 2));
}
示例7: pgwnextoff
/*
* Return offset into bdict where next webster entry after fromoff starts.
* Webster entries start with <p><hw>
*/
long
pgwnextoff(long fromoff)
{
long a, n;
int c;
a = Bseek(bdict, fromoff, 0);
if(a != fromoff)
return -1;
n = 0;
for(;;) {
c = Bgetc(bdict);
if(c < 0)
break;
if(c == '<' && Bgetc(bdict) == 'p' && Bgetc(bdict) == '>') {
c = Bgetc(bdict);
if(c == '<') {
if (Bgetc(bdict) == 'h' && Bgetc(bdict) == 'w'
&& Bgetc(bdict) == '>')
n = 7;
} else if (c == '{')
n = 4;
if(n)
break;
}
}
return (Boffset(bdict)-n);
}
示例8: oreadblock
int
oreadblock(Ofile *f, int block, uint32_t off, char *buf, int nbuf)
{
int n;
if(block < 0 || block >= f->nblock) {
werrstr("attempt to read %x/%lx\n", block, f->nblock);
return -1;
}
if(off >= Blocksize){
print("offset too far into block\n");
return 0;
}
if(off+nbuf > Blocksize)
nbuf = Blocksize-off;
/* blocks start numbering at -1 [sic] */
off += (block+1)*Blocksize;
if(Bseek(f->b, off, 0) != off){
print("seek failed\n");
return -1;
}
n = Bread(f->b, buf, nbuf);
if(n < 0)
print("Bread failed: %r");
return n;
}
示例9: pcollgnextoff
int32_t
pcollgnextoff(int32_t fromoff)
{
int c, state = 0, defoff = -1;
if(Bseek(bdict, fromoff, 0) < 0)
return -1;
while((c = Bgetc(bdict)) >= 0){
if(c == '\r')
defoff = Boffset(bdict);
switch(state){
case 0:
if(c == 0x05)
state = 1;
break;
case 1:
if(c == 'h')
state = 2;
else
state = 0;
break;
case 2:
if(c == 0x06)
return (Boffset(bdict)-3);
else
state = 0;
break;
}
}
return defoff;
}
示例10: contentinit
void
contentinit(void)
{
static Biobuf *b = nil;
static Qid qid;
char *file, *s;
Suffix *this;
file = "/sys/lib/mimetype";
if(b == nil){ /* first time */
b = Bopen(file, OREAD);
if(b == nil)
sysfatal("can't read from %s", file);
}
if(updateQid(Bfildes(b), &qid) == 0)
return;
Bseek(b, 0, 0);
while(suffixes!=nil){
this = suffixes;
suffixes = suffixes->next;
free(this->suffix);
free(this->generic);
free(this->specific);
free(this->encoding);
free(this);
}
while((s = Brdline(b, '\n')) != nil){
s[Blinelen(b) - 1] = 0;
suffixes = parsesuffix(s, suffixes);
}
}
示例11: okfile
static int
okfile(char *cp, Biobuf *fp)
{
char *buf;
int len;
char *bp, *ep;
int c;
len = strlen(cp);
Bseek(fp, 0, 0);
/* one iteration per system name in the file */
while(buf = Brdline(fp, '\n')) {
ep = &buf[Blinelen(fp)];
for(bp=buf; bp < ep;){
while(isspace(*bp) || *bp==',')
bp++;
if(strncmp(bp, cp, len) == 0) {
c = *(bp+len);
if(isspace(c) || c==',')
return 1;
}
while(bp < ep && (!isspace(*bp)) && *bp!=',')
bp++;
}
}
/* didn't find it, prohibit forwarding */
return 0;
}
示例12: pswritepage
static int
pswritepage(Document *d, int fd, int page)
{
Biobuf *b = d->b;
PSInfo *ps = d->extra;
int t, n, i;
long begin, end;
char buf[8192];
if(page == -1)
begin = ps->psoff;
else
begin = ps->page[page].offset;
end = ps->page[page+1].offset;
if(chatty) {
fprint(2, "writepage(%d)... from #%ld to #%ld...\n",
page, begin, end);
}
Bseek(b, begin, 0);
t = end-begin;
n = sizeof(buf);
if(n > t) n = t;
while(t > 0 && (i=Bread(b, buf, n)) > 0) {
if(write(fd, buf, i) != i)
return -1;
t -= i;
if(n > t)
n = t;
}
return end-begin;
}
示例13: dcmd
void
dcmd(char *arname, int count, char **files)
{
Armember *bp;
int fd, i;
if (!count)
return;
fd = openar(arname, ORDWR, 0);
Binit(&bar, fd, OREAD);
Bseek(&bar,seek(fd,0,1), 1);
astart = newtempfile(artemp);
for (i = 0; bp = getdir(&bar); i++) {
if(match(count, files)) {
mesg('d', file);
skip(&bar, bp->size);
if (strcmp(file, symdef) == 0)
allobj = 0;
} else if (i == 0 && strcmp(file, symdef) == 0)
skip(&bar, bp->size);
else {
scanobj(&bar, astart, bp->size);
arcopy(&bar, astart, bp);
}
}
close(fd);
install(arname, astart, 0, 0, 0);
}
示例14: skip
/*
* Skip an archive member
*/
void
skip(Biobuf *bp, long len)
{
if (len & 01)
len++;
Bseek(bp, len, 1);
}
示例15: main
void
main(int argc, char *argv[])
{
int i;
Biobuf *bin;
Binit(&bout, 1, OWRITE);
argv0 = argv[0];
ARGBEGIN {
case 'a': aflag = 1; break;
case 'g': gflag = 1; break;
case 'h': hflag = 1; break;
case 'n': nflag = 1; break;
case 's': sflag = 1; break;
case 'u': uflag = 1; break;
} ARGEND
if (argc > 1)
multifile++;
for(i=0; i<argc; i++){
filename = argv[i];
bin = Bopen(filename, OREAD);
if(bin == 0){
error("cannot open %s", filename);
continue;
}
if (isar(bin))
doar(bin);
else{
Bseek(bin, 0, 0);
dofile(bin);
}
Bterm(bin);
}
exits(errs);
}