a while ago.
OK zinovik nicm
-/* $OpenBSD: buf.c,v 1.15 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: buf.c,v 1.16 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
#define BUF_INCR 128
struct buf {
- u_int cb_flags;
-
/* buffer handle, buffer size, and data length */
u_char *cb_buf;
size_t cb_size;
* once the buffer is no longer needed.
*/
BUF *
-buf_alloc(size_t len, u_int flags)
+buf_alloc(size_t len)
{
BUF *b;
else
b->cb_buf = NULL;
- b->cb_flags = flags;
b->cb_size = len;
b->cb_len = 0;
* Sets errno on error.
*/
BUF *
-buf_load(const char *path, u_int flags)
+buf_load(const char *path)
{
int fd;
ssize_t ret;
errno = EFBIG;
goto out;
}
- buf = buf_alloc(st.st_size, flags);
+ buf = buf_alloc(st.st_size);
for (bp = buf->cb_buf; ; bp += (size_t)ret) {
len = SIZE_LEFT(buf);
ret = read(fd, bp, len);
bp = b->cb_buf + b->cb_len;
if (bp == (b->cb_buf + b->cb_size)) {
/* extend */
- if (b->cb_flags & BUF_AUTOEXT)
- buf_grow(b, (size_t)BUF_INCR);
- else
- errx(1, "buf_putc failed");
+ buf_grow(b, BUF_INCR);
/* the buffer might have been moved */
bp = b->cb_buf + b->cb_len;
* buf_append()
*
* Append <len> bytes of data pointed to by <data> to the buffer <b>. If the
- * buffer is too small to accept all data, it will attempt to append as much
- * data as possible, or if the BUF_AUTOEXT flag is set for the buffer, it
+ * buffer is too small to accept all data, it
* will get resized to an appropriate size to accept all data.
* Returns the number of bytes successfully appended to the buffer.
*/
rlen = len;
if (left < len) {
- if (b->cb_flags & BUF_AUTOEXT) {
- buf_grow(b, len - left);
- bp = b->cb_buf + b->cb_len;
- } else
- rlen = bep - bp;
+ buf_grow(b, len - left);
+ bp = b->cb_buf + b->cb_len;
}
memcpy(bp, data, rlen);
-/* $OpenBSD: buf.h,v 1.10 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: buf.h,v 1.11 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
#include <sys/types.h>
-/* flags */
-#define BUF_AUTOEXT 1 /* autoextend on append */
-
typedef struct buf BUF;
-BUF *buf_alloc(size_t, u_int);
-BUF *buf_load(const char *, u_int);
+BUF *buf_alloc(size_t);
+BUF *buf_load(const char *);
void buf_free(BUF *);
void *buf_release(BUF *);
u_char buf_getc(BUF *, size_t);
-/* $OpenBSD: ci.c,v 1.208 2010/07/23 23:59:32 ray Exp $ */
+/* $OpenBSD: ci.c,v 1.209 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
b1 = b2 = b3 = NULL;
path1 = path2 = NULL;
- if ((b1 = buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
+ if ((b1 = buf_load(pb->filename)) == NULL) {
warnx("failed to load file: `%s'", pb->filename);
goto out;
}
goto out;
}
b2 = rcs_kwexp_buf(b2, pb->file, pb->frev);
-
- if ((b3 = buf_alloc(128, BUF_AUTOEXT)) == NULL) {
- warnx("failed to allocated buffer for diff");
- goto out;
- }
+ b3 = buf_alloc(128);
(void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
buf_write_stmp(b1, path1);
pb->frev = pb->file->rf_head;
/* Load file contents */
- if ((bp = buf_load(pb->filename, BUF_AUTOEXT)) == NULL)
+ if ((bp = buf_load(pb->filename)) == NULL)
return (-1);
/* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */
}
/* Load file contents */
- if ((bp = buf_load(pb->filename, BUF_AUTOEXT)) == NULL)
+ if ((bp = buf_load(pb->filename)) == NULL)
return (-1);
/* Get default values from working copy if -k specified */
}
len = c - start + 1;
- buf = buf_alloc(len + 1, 0);
+ buf = buf_alloc(len + 1);
buf_append(buf, start, len);
/* XXX - Not binary safe. */
-/* $OpenBSD: co.c,v 1.111 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: co.c,v 1.112 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
return (-1);
}
} else {
- bp = buf_alloc(1, 0);
+ bp = buf_alloc(1);
}
/*
-/* $OpenBSD: diff3.c,v 1.30 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: diff3.c,v 1.31 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
if ((flags & MERGE_EFLAG) && !(flags & MERGE_OFLAG))
oflag = 0;
- if ((b1 = buf_load(av[0], BUF_AUTOEXT)) == NULL)
+ if ((b1 = buf_load(av[0])) == NULL)
goto out;
- if ((b2 = buf_load(av[1], BUF_AUTOEXT)) == NULL)
+ if ((b2 = buf_load(av[1])) == NULL)
goto out;
- if ((b3 = buf_load(av[2], BUF_AUTOEXT)) == NULL)
+ if ((b3 = buf_load(av[2])) == NULL)
goto out;
- d1 = buf_alloc(128, BUF_AUTOEXT);
- d2 = buf_alloc(128, BUF_AUTOEXT);
- diffb = buf_alloc(128, BUF_AUTOEXT);
+ d1 = buf_alloc(128);
+ d2 = buf_alloc(128);
+ diffb = buf_alloc(128);
(void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
(void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);
rcsnum_tostr(rev1, r1, sizeof(r1));
rcsnum_tostr(rev2, r2, sizeof(r2));
- if ((b1 = buf_load(workfile, BUF_AUTOEXT)) == NULL)
+ if ((b1 = buf_load(workfile)) == NULL)
goto out;
if (!(flags & QUIET))
if ((b3 = rcs_getrev(rf, rev2)) == NULL)
goto out;
- d1 = buf_alloc(128, BUF_AUTOEXT);
- d2 = buf_alloc(128, BUF_AUTOEXT);
- diffb = buf_alloc(128, BUF_AUTOEXT);
+ d1 = buf_alloc(128);
+ d2 = buf_alloc(128);
+ diffb = buf_alloc(128);
(void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
(void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);
-/* $OpenBSD: ident.c,v 1.27 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: ident.c,v 1.28 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
BUF *bp;
size_t len;
- bp = buf_alloc(512, BUF_AUTOEXT);
+ bp = buf_alloc(512);
while ((c = getc(fp)) != VALDELIM) {
if (c == EOF)
-/* $OpenBSD: rcs.c,v 1.59 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: rcs.c,v 1.60 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
len = rdp->rd_tlen;
if (len == 0) {
- rbuf = buf_alloc(1, 0);
+ rbuf = buf_alloc(1);
buf_empty(rbuf);
return (rbuf);
}
- rbuf = buf_alloc(len, BUF_AUTOEXT);
+ rbuf = buf_alloc(len);
buf_append(rbuf, rdp->rd_text, len);
isbranch = 0;
if ((nextbuf = rcs_getrev(rf, nextrdp->rd_num)) == NULL)
errx(1, "error getting revision");
- newdiff = buf_alloc(64, BUF_AUTOEXT);
+ newdiff = buf_alloc(64);
/* calculate new diff */
(void)xasprintf(&path_tmp1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
errx(1, "rcs_expand_keywords: string truncated");
/* Concatenate everything together. */
- tmpbuf = buf_alloc(len + strlen(expbuf), BUF_AUTOEXT);
+ tmpbuf = buf_alloc(len + strlen(expbuf));
/* Append everything before keyword. */
buf_append(tmpbuf, buf_get(newbuf),
start - (unsigned char *)buf_get(newbuf));
-/* $OpenBSD: rcsclean.c,v 1.51 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: rcsclean.c,v 1.52 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
warnx("failed to get needed revision");
goto out;
}
- if ((b2 = buf_load(fname, 0)) == NULL) {
+ if ((b2 = buf_load(fname)) == NULL) {
warnx("failed to load `%s'", fname);
goto out;
}
-/* $OpenBSD: rcsdiff.c,v 1.76 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: rcsdiff.c,v 1.77 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
tv[0].tv_sec = (long)rcs_rev_getdate(file, rev);
tv[1].tv_sec = tv[0].tv_sec;
- if ((b2 = buf_load(filename, BUF_AUTOEXT)) == NULL) {
+ if ((b2 = buf_load(filename)) == NULL) {
warnx("failed to load file: `%s'", filename);
goto out;
}
-/* $OpenBSD: rcsutil.c,v 1.34 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: rcsutil.c,v 1.35 2010/07/28 09:07:11 ray Exp $ */
/*
* Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
size_t len;
char *buf;
- bp = buf_alloc(0, BUF_AUTOEXT);
+ bp = buf_alloc(0);
if (isatty(STDIN_FILENO))
(void)fprintf(stderr, "%s", prompt);
if (isatty(STDIN_FILENO))
/* Description is in file <in>. */
if (in != NULL && *in != '-') {
- if ((bp = buf_load(in, BUF_AUTOEXT)) == NULL)
+ if ((bp = buf_load(in)) == NULL)
return (-1);
buf_putc(bp, '\0');
content = buf_release(bp);
return (NULL);
}
- res = buf_alloc(1024, BUF_AUTOEXT);
+ res = buf_alloc(1024);
TAILQ_FOREACH(lp, &dlines->l_lines, l_list) {
if (lp->l_line == NULL)
continue;