Lines Matching defs:buf
62 shf->buf = (unsigned char *)&shf[1];
138 shf->buf = alloc(bsize, ATEMP);
141 shf->buf = NULL;
144 shf->buf = (unsigned char *)&shf[1];
149 shf->rp = shf->wp = shf->buf;
171 if (!shf || !shf->buf || shf->bsize < bsize)
174 /* assumes shf->buf and shf->bsize already set up */
176 shf->rp = shf->wp = shf->buf;
192 * returned, if it is NULL, shf is allocated. If writing and buf is NULL
198 shf_sopen(char *buf, ssize_t bsize, int sflags, struct shf *shf)
210 if (!buf && (sflags & SHF_WR) && (sflags & SHF_DYNAMIC)) {
214 buf = alloc(bsize, shf->areap);
217 shf->buf = shf->rp = shf->wp = (unsigned char *)buf;
243 afree(shf->buf, shf->areap);
259 shf->rp = shf->buf;
275 unsigned char *s = shf->buf;
313 shf->rp = shf->buf;
357 nbuf = aresize2(shf->buf, 2, shf->wbsize, shf->areap);
358 shf->rp = nbuf + (shf->rp - shf->buf);
359 shf->wp = nbuf + (shf->wp - shf->buf);
363 shf->buf = nbuf;
366 ssize_t n, ntowrite = shf->wp - shf->buf;
367 unsigned char *buf = shf->buf;
370 n = write(shf->fd, buf, ntowrite);
378 if (buf != shf->buf) {
383 memmove(shf->buf, buf,
385 shf->wp = shf->buf + ntowrite;
389 buf += n;
393 shf->wp = shf->buf;
399 shf->wp = shf->buf;
430 shf->rp = shf->buf;
432 n = blocking_read(shf->fd, (char *)shf->buf, shf->rbsize);
441 shf->rp = shf->buf;
450 * Read a buffer from shf. Returns the number of bytes read into buf, if
455 shf_read(char *buf, ssize_t bsize, struct shf *shf)
473 memcpy(buf, shf->rp, ncopy);
474 buf += ncopy;
485 * Read up to a newline or -1. The newline is put in buf; buf is always
487 * before end of file, returns a pointer to the NUL byte in buf
491 shf_getse(char *buf, ssize_t bsize, struct shf *shf)
495 char *orig_buf = buf;
511 *buf = '\0';
512 return (buf == orig_buf ? NULL : buf);
520 memcpy(buf, (char *) shf->rp, ncopy);
523 buf += ncopy;
526 if (buf > orig_buf + 1 && ord(buf[-2]) == ORD('\r') &&
527 ord(buf[-1]) == ORD('\n')) {
528 buf--;
530 buf[-1] = '\n';
535 if (!bsize && ord(buf[-1]) == ORD('\r')) {
538 buf[-1] = '\n';
543 *buf = '\0';
544 return (buf);
573 (shf->rp == shf->buf && shf->rnleft))
579 if (shf->rp == shf->buf)
580 shf->rp = shf->buf + shf->rbsize;
658 shf_write(const char *buf, ssize_t nbytes, struct shf *shf)
671 (shf->wp != shf->buf || nbytes < shf->wnleft)) {
674 memcpy(shf->wp, buf, ncopy);
676 buf += ncopy;
698 n = write(shf->fd, buf, ncopy);
712 buf += n;
720 memcpy(shf->wp, buf, nbytes);
743 shf_snprintf(char *buf, ssize_t bsize, const char *fmt, ...)
749 if (!buf || bsize <= 0)
750 internal_errorf("shf_snprintf: buf %zX, bsize %zd",
751 (size_t)buf, bsize);
753 shf_sopen(buf, bsize, SHF_WR, &shf);