int foldline(Source * s) { int n = 1; /* skip pending white spaces */ while ((s->inp[n] == ' ') || (s->inp[n] == '\t')) { n++; if ((s->inp + n >= s->inl) && (fillbuf(s) == EOF)) break; } /* refill buffer */ while (s->inp + (n + 1) >= s->inl && fillbuf(s) != EOF); /* skip DOS line ends */ if (((s->inp[n] == '\r') && (s->inp[n+1] == '\n')) || ((s->inp[n] == '\n') && (s->inp[n+1] == '\r'))) n++; if ((s->inp[n] == '\n') || (s->inp[n] == '\r')) { memmove(s->inp, s->inp + n + 1, s->inl - s->inp + n + 2); s->inl -= n + 1; return 1; } return 0; }
static void validate_memcpy_overlap(void) { size_t srcalign, dstalign, size; const size_t maxsize = 256; int comp; printf("testing memcpy for correctness in overlap cases\n"); for (dstalign = 0; dstalign < 64; dstalign++) { for (size = 0; size < maxsize; size++) { fillbuf(src, maxsize * 2, 567); fillbuf(src2, maxsize * 2, 567); /* Case one will check cpy memory is the same - fwd*/ memcpy(src + dstalign, src, size); comp = memcmp(src + dstalign, src2, size); if (comp != 0) { printf("ERROR (Case1): dstalign %zu, size %zu, ret %d\n", dstalign, size, comp); } fillbuf(src, maxsize * 2, 8588485); fillbuf(src2, maxsize * 2, 8588485); /* Case two will check cpy memory is the same - bkwd*/ memcpy(src, src + dstalign, size); comp = memcmp(src, src2 + dstalign, size); if (comp != 0) { printf("ERROR (Case2): dstalign %zu, size %zu, ret %d\n", dstalign, size, comp); } } } }
static void validate_memcpy(void) { size_t srcalign, dstalign, size; const size_t maxsize = 256; printf("testing memcpy for correctness\n"); /* * do the simple tests to make sure that memcpy doesn't color outside * the lines for all alignment cases */ for (srcalign = 0; srcalign < 64; srcalign++) { for (dstalign = 0; dstalign < 64; dstalign++) { // printf("srcalign %zu, dstalign %zu\n", srcalign, dstalign); for (size = 0; size < maxsize; size++) { // printf("srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size); fillbuf(src, maxsize * 2, 567); fillbuf(src2, maxsize * 2, 567); fillbuf(dst, maxsize * 2, 123514); fillbuf(dst2, maxsize * 2, 123514); memcpy(dst + dstalign, src + srcalign, size); mymemcpy(dst2 + dstalign, src2 + srcalign, size); int comp = memcmp(dst, dst2, maxsize * 2); if (comp != 0) { printf("error! srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size); } } } } }
static void validate_memset(void) { size_t dstalign, size; int c; const size_t maxsize = 256; printf("testing memset for correctness\n"); for (dstalign = 0; dstalign < 64; dstalign++) { printf("align %zd\n", dstalign); for (size = 0; size < maxsize; size++) { for (c = 0; c < 256; c++) { fillbuf(dst, maxsize * 2, 123514); fillbuf(dst2, maxsize * 2, 123514); memset(dst + dstalign, c, size); mymemset(dst2 + dstalign, c, size); int comp = memcmp(dst, dst2, maxsize * 2); if (comp != 0) { printf("error! align %zu, c %d, size %zu\n", dstalign, c, size); } } } } }
void CLhaArchive::read_pt_len(short nn, short nbit, short i_special) { short i, c, n; n = getbits(nbit); if (n == 0) { c = getbits(nbit); for (i = 0; i < nn; i++) gpHufData->pt_len[i] = 0; for (i = 0; i < 256; i++) gpHufData->pt_table[i] = c; } else { i = 0; while (i < n) { c = bitbuf >> (16 - 3); if (c == 7) { unsigned short mask = 1 << (16 - 4); while (mask & bitbuf) { mask >>= 1; c++; } } fillbuf((c < 7) ? 3 : c - 3); gpHufData->pt_len[i++] = (unsigned char)c; if (i == i_special) { c = getbits(2); while (--c >= 0) gpHufData->pt_len[i++] = 0; } } while (i < nn) gpHufData->pt_len[i++] = 0; make_table(nn, gpHufData->pt_len, 8, gpHufData->pt_table); }
static void init_getbits (lzh_globals_x *G) { G->bitbuf = 0; G->subbitbuf = 0; G->bitcount = 0; fillbuf (G, BITBUFSIZ); }
static ushort getbits (lzh_globals_x *G, int n) { ushort x; x = G->bitbuf >> (BITBUFSIZ - n); fillbuf (G, n); return x; }
static void init_getbits (void) { bitbuf = 0; subbitbuf = 0; bitcount = 0; fillbuf (BITBUFSIZ); }
void CLzhDepacker::init_getbits (void) { bitbuf = 0; subbitbuf = 0; bitcount = 0; fillbuf (BITBUFSIZ); }
ushort CLzhDepacker::getbits (int n) { ushort x; x = bitbuf >> (BITBUFSIZ - n); fillbuf (n); return x; }
static void read_pt_len(int nn, int nbit, int i_special) { int i, c, n; unsigned short mask; n = getbits(nbit); if (n == 0) { c = getbits(nbit); for (i = 0; i < nn; i++) pt_len[i] = 0; for (i = 0; i < 256; i++) pt_table[i] = c; } else { i = 0; while (i < n) { c = bitbuf >> (BITBUFSIZ - 3); if (c == 7) { mask = 1U << (BITBUFSIZ - 1 - 3); while (mask & bitbuf) { mask >>= 1; c++; } } fillbuf((c < 7) ? 3 : c - 3); pt_len[i++] = c; if (i == i_special) { c = getbits(2); while (--c >= 0) pt_len[i++] = 0; } } while (i < nn) pt_len[i++] = 0; make_table(nn, pt_len, 8, pt_table); }
static ushort getbits (int n) { ushort x; x = bitbuf >> (BITBUFSIZ - n); fillbuf (n); return x; }
static void random_writes(int fd, char *buf, uint64_t nblocks, int64_t n) { for (int64_t i = 0; n == -1 || i < n; i++) { fillbuf(buf); rwc_pwrite(fd, buf, BLOCKSZ, (lrand48() % nblocks) * BLOCKSZ); } }
/* * runtest: write the data to the file. Read the data from the file and compare. * For each iteration, write data starting at offse+iter*bufsize * location in the file and read from there. */ int runtest(int fd_r, int fd_w, int childnum, int action) { off64_t seekoff; int i, bufsize = BUFSIZE; char *buf1, *buf2; buf1 = valloc(BUFSIZE); buf2 = valloc(BUFSIZE); if (!buf1 || !buf2) { tst_resm(TBROK | TERRNO, "valloc() failed"); free(buf1); free(buf2); return -1; } /* Allocate for buffers and data pointers */ seekoff = offset + bufsize * childnum; /* seek, write, read and verify */ for (i = 0; i < iter; i++) { fillbuf(buf1, bufsize, childnum+i); if (lseek(fd_w, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before write failed: %s", strerror(errno)); return (-1); } if (write(fd_w, buf1, bufsize) < bufsize) { tst_resm(TFAIL, "write failed: %s", strerror(errno)); return (-1); } if (action == READ_DIRECT) { /* Make sure data is on to disk before read */ if (fsync(fd_w) < 0) { tst_resm(TFAIL, "fsync failed: %s", strerror(errno)); return (-1); } } if (lseek(fd_r, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before read failed: %s", strerror(errno)); return (-1); } int ret; if ((ret = read(fd_r, buf2, bufsize)) < bufsize) { tst_resm(TFAIL, "read failed: %s", strerror(errno)); return (-1); } if (bufcmp(buf1, buf2, bufsize) != 0) { tst_resm(TFAIL, "comparsion failed. Child=%d offset=%d", childnum, (int)seekoff); return (-1); } } return 0; }
void vfillbuf(struct iovec *iv, int vcnt, char value) { int i; for (i = 0; i < vcnt; iv++, i++) { fillbuf(iv->iov_base, iv->iov_len, (char)value); } }
/* * Fill a destination buffer with the bitwise complement of the source * buffer to prevent accidental matches. */ static void spoilbuf(char *buf, size_t len) { size_t i; fillbuf(buf, len); for (i = 0; i < len; i++) buf[i] = ~buf[i]; }
void inputInit() { limit = cp = &buffer[MAXLINE+1]; bsize = -1; lineno = 0; file = NULL; fillbuf(); if (cp >= limit) cp = limit; nextline(); }
/* * runtest: write the data to the file. Read the data from the file and compare. * For each iteration, write data starting at offse+iter*bufsize * location in the file and read from there. * * XXX (garrcoop): shouldn't use libltp APIs because it runs forked. */ int runtest(int fd_r, int fd_w, int childnum, int action) { char *buf1; char *buf2; off_t seekoff; int bufsize = BUFSIZE; int i; /* Allocate for buffers */ seekoff = offset+bufsize * childnum; if ((buf1 = valloc(bufsize)) == 0) { tst_resm(TFAIL|TERRNO, "valloc for buf1 failed"); return(-1); } if ((buf2 = valloc(bufsize)) == 0) { tst_resm(TFAIL|TERRNO, "valloc for buf2 failed"); return(-1); } /* seek, write, read and verify */ for (i = 0; i < iter; i++) { fillbuf(buf1, bufsize, childnum+i); if (lseek(fd_w, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL|TERRNO, "lseek (fd_w, ..) failed"); return(-1); } if (write(fd_w, buf1, bufsize) < bufsize) { tst_resm(TFAIL|TERRNO, "write failed"); return(-1); } if (action == READ_DIRECT) { /* Make sure data is on to disk before read */ if (fsync(fd_w) < 0) { tst_resm(TFAIL|TERRNO, "fsync failed"); return(-1); } } if (lseek(fd_r, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL|TERRNO, "lseek(fd_r, ..) failed"); return(-1); } if (read(fd_r, buf2, bufsize) < bufsize) { tst_resm(TFAIL|TERRNO, "read failed"); return(-1); } if (bufcmp(buf1, buf2, bufsize) != 0) { tst_resm(TFAIL, "comparsion failed; child=%d offset=%d", childnum, (int)seekoff); return(-1); } } tst_exit(); }
int foldline(Source *s) { while (s->inp+1 >= s->inl && fillbuf(s)!=EOF) ; if (s->inp[1] == '\n') { memmove(s->inp, s->inp+2, s->inl-s->inp+3); s->inl -= 2; return 1; } return 0; }
/// \brief Pre increment inline IStreamIterator& operator++() { if (m_readpos+1 >= m_readsize) { fillbuf(); } else { ++m_readpos; } return *this; }
/* skip to '\n' */ static void skip_line(void) { for (;;) { char *q = strchr(bufp, '\n'); if (q) { bufp = q; break; } bufp = buf+(BUFFER_SIZE-1); if (!eof) fillbuf(); } }
void decode_start_stub() { #if SFX_LEVEL>=ARJ subbitbuf=0; #endif bitbuf=0; byte_buf=0; bitcount=0; fillbuf(CHAR_BIT*2); #if SFX_LEVEL>=ARJSFXV mem_stats(); #endif }
/* ------------------------------------------------------------------------ */ unsigned short decode_p_st0(/*void*/) { int i, j; j = pt_table[lhabitbuf >> 8]; if (j < np) { fillbuf(pt_len[j]); } else { fillbuf(8); i = lhabitbuf; do { if ((short) i < 0) j = lha_right[j]; else j = lha_left[j]; i <<= 1; } while (j >= np); fillbuf(pt_len[j] - 8); } return (j << 6) + getbits(6); }
/* ------------------------------------------------------------------------ */ unsigned short decode_c_st0(/*void*/) { int i, j; static unsigned short blocksize = 0; if (blocksize == 0) { /* read block head */ blocksize = getbits(BUFBITS); /* read block blocksize */ read_tree_c(); if (getbits(1)) { read_tree_p(); } else { ready_made(1); } lha_make_table(NP, pt_len, 8, pt_table); } blocksize--; j = c_table[lhabitbuf >> 4]; if (j < N1) fillbuf(c_len[j]); else { fillbuf(12); i = lhabitbuf; do { if ((short) i < 0) j = lha_right[j]; else j = lha_left[j]; i <<= 1; } while (j >= N1); fillbuf(c_len[j] - 12); } if (j == N1 - 1) j += getbits(EXTRABITS); return j; }
static void sequential_writes(int fd, char *buf, uint64_t nblocks, int64_t n) { for (int64_t i = 0; n == -1 || i < n; i++) { fillbuf(buf); static uint64_t j = 0; if (j == 0) j = lrand48() % nblocks; rwc_pwrite(fd, buf, BLOCKSZ, j * BLOCKSZ); j++; if (j >= nblocks) j = 0; } }
/* have seen ?; handle the trigraph it starts (if any) else 0 */ int trigraph(Source * s) { uchar c; while (s->inp + 2 >= s->inl && fillbuf(s) != EOF); ; if (s->inp[1] != '?') return 0; c = 0; switch (s->inp[2]) { case '=': c = '#'; break; case '(': c = '['; break; case '/': c = '\\'; break; case ')': c = ']'; break; case '\'': c = '^'; break; case '<': c = '{'; break; case '!': c = '|'; break; case '>': c = '}'; break; case '-': c = '~'; break; } if (c) { *s->inp = c; memmove(s->inp + 1, s->inp + 3, s->inl - s->inp + 2); s->inl -= 2; } return c; }
void input_init(int argc, char *argv[]) { static int inited; if (inited) return; inited = 1; main_init(argc, argv); limit = cp = &buffer[MAXLINE+1]; bsize = -1; lineno = 0; file = NULL; fillbuf(); if (cp >= limit) cp = limit; nextline(); }
int aflinbuf(FILE *f, int mem) { off_t fsize; afgetfsize(f, &fsize); bufsize = ((size_t) mem) * 1048576; /* printf("aflinbuf: %i %lu %lu\n", mem, (unsigned long) fsize, (unsigned long) bufsize);*/ bufsize = fsize < bufsize ? fsize : bufsize; fbuf = f; if (createbuf() < 0) return -1; if (fillbuf() < 0) return -1; return 0; }
/* resynch - set line number/file name in # n [ "file" ], #pragma, etc. */ static void resynch(void) { for (cp++; *cp == ' ' || *cp == '\t'; ) cp++; if (limit - cp < MAXLINE) fillbuf(); if (strncmp((char *)cp, "pragma", 6) == 0) { cp += 6; pragma(); } else if (strncmp((char *)cp, "ident", 5) == 0) { cp += 5; ident(); } else if (*cp >= '0' && *cp <= '9') { line: for (lineno = 0; *cp >= '0' && *cp <= '9'; ) lineno = 10*lineno + *cp++ - '0'; lineno--; while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '"') { file = (char *)++cp; while (*cp && *cp != '"' && *cp != '\n') cp++; file = stringn(file, (char *)cp - file); if (*cp == '\n') warning("missing \" in preprocessor line\n"); if (firstfile == 0) firstfile = file; } } else if (strncmp((char *)cp, "line", 4) == 0) { for (cp += 4; *cp == ' ' || *cp == '\t'; ) cp++; if (*cp >= '0' && *cp <= '9') goto line; if (Aflag >= 2) warning("unrecognized control line\n"); } else if (Aflag >= 2 && *cp != '\n') warning("unrecognized control line\n"); while (*cp) if (*cp++ == '\n') if (cp == limit + 1) { nextline(); if (cp == limit) break; } else break; }
void nextline() { do { if (cp >= limit) { fillbuf(); if (cp >= limit) cp = limit; if (cp == limit) return; } else lineno++; for (line = (char *)cp; *cp==' ' || *cp=='\t'; cp++) ; } while (*cp == '\n' && cp == limit); if (*cp == '#') { resynch(); nextline(); } }