summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-08-01 05:14:18 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-08-01 05:14:18 +0000
commit9686dd68fffdd5f80a02cf9a3f544e3692872c08 (patch)
tree4f003f44f95f10aec4a59992d97d1bc5ef3f2e79
parent33d6871812607a9cc12519f2ef296dbcc42d5bd6 (diff)
Reduce rcs_buf_release() usage, improving binary support.
OK niallo@
-rw-r--r--usr.bin/rcs/co.c17
-rw-r--r--usr.bin/rcs/ident.c13
-rw-r--r--usr.bin/rcs/merge.c15
-rw-r--r--usr.bin/rcs/rcsmerge.c16
4 files changed, 25 insertions, 36 deletions
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c
index ce42c96ff5a..b8c09691cc0 100644
--- a/usr.bin/rcs/co.c
+++ b/usr.bin/rcs/co.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: co.c,v 1.95 2006/06/03 03:05:10 niallo Exp $ */
+/* $OpenBSD: co.c,v 1.96 2006/08/01 05:14:17 ray Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -239,7 +239,7 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
struct stat st;
struct rcs_delta *rdp;
struct rcs_lock *lkp;
- char *content, msg[128], *fdate;
+ char msg[128], *fdate;
time_t rcsdate, givendate;
RCSNUM *rev;
@@ -454,12 +454,9 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
}
}
- if (flags & PIPEOUT) {
- rcs_buf_putc(bp, '\0');
- content = rcs_buf_release(bp);
- printf("%s", content);
- xfree(content);
- } else {
+ if (flags & PIPEOUT)
+ rcs_buf_write_fd(bp, STDOUT_FILENO);
+ else {
(void)unlink(dst);
if ((fd = open(dst, O_WRONLY|O_CREAT|O_TRUNC, mode)) < 0)
@@ -475,8 +472,6 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
if (fchmod(fd, mode) == -1)
warn("%s", dst);
- rcs_buf_free(bp);
-
if (flags & CO_REVDATE) {
struct timeval tv[2];
memset(&tv, 0, sizeof(tv));
@@ -489,6 +484,8 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
(void)close(fd);
}
+ rcs_buf_free(bp);
+
return (0);
}
diff --git a/usr.bin/rcs/ident.c b/usr.bin/rcs/ident.c
index fa7c39f059d..972d4495407 100644
--- a/usr.bin/rcs/ident.c
+++ b/usr.bin/rcs/ident.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ident.c,v 1.20 2006/05/09 12:33:42 ray Exp $ */
+/* $OpenBSD: ident.c,v 1.21 2006/08/01 05:14:17 ray Exp $ */
/*
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
@@ -107,7 +107,6 @@ ident_line(FILE *fp)
{
int c;
BUF *bp;
- char *keyw;
size_t len;
bp = rcs_buf_alloc(512, BUF_AUTOEXT);
@@ -140,13 +139,13 @@ ident_line(FILE *fp)
/* append trailing KEYDELIM */
rcs_buf_putc(bp, c);
- rcs_buf_putc(bp, '\0');
- keyw = rcs_buf_release(bp);
- bp = NULL;
- found++;
- printf(" %c%s\n", KEYDELIM, keyw);
+ /* Append newline for printing. */
+ rcs_buf_putc(bp, '\n');
+ printf(" %c", KEYDELIM);
+ rcs_buf_write_fd(bp, STDOUT_FILENO);
+ found++;
out:
if (bp != NULL)
rcs_buf_free(bp);
diff --git a/usr.bin/rcs/merge.c b/usr.bin/rcs/merge.c
index 7b449da3631..8f73a6fbadc 100644
--- a/usr.bin/rcs/merge.c
+++ b/usr.bin/rcs/merge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: merge.c,v 1.2 2006/05/15 06:58:03 xsa Exp $ */
+/* $OpenBSD: merge.c,v 1.3 2006/08/01 05:14:17 ray Exp $ */
/*
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
@@ -33,7 +33,6 @@ int
merge_main(int argc, char **argv)
{
int ch, flags, labels, status;
- char *fcont;
const char *label[3];
BUF *bp;
extern char *optarg;
@@ -91,18 +90,14 @@ merge_main(int argc, char **argv)
else
status = 0;
- if (flags & PIPEOUT) {
- rcs_buf_putc(bp, '\0');
- fcont = rcs_buf_release(bp);
- (void)printf("%s", fcont);
- xfree(fcont);
- } else {
+ if (flags & PIPEOUT)
+ rcs_buf_write_fd(bp, STDOUT_FILENO);
+ else {
/* XXX */
if (rcs_buf_write(bp, argv[0], 0644) < 0)
warnx("rcs_buf_write failed");
-
- rcs_buf_free(bp);
}
+ rcs_buf_free(bp);
return (status);
}
diff --git a/usr.bin/rcs/rcsmerge.c b/usr.bin/rcs/rcsmerge.c
index 312aafe5700..0bfab7a7e2f 100644
--- a/usr.bin/rcs/rcsmerge.c
+++ b/usr.bin/rcs/rcsmerge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsmerge.c,v 1.46 2006/05/27 05:49:14 ray Exp $ */
+/* $OpenBSD: rcsmerge.c,v 1.47 2006/08/01 05:14:17 ray Exp $ */
/*
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
@@ -33,7 +33,7 @@ int
rcsmerge_main(int argc, char **argv)
{
int fd, ch, flags, kflag, status;
- char *fcont, fpath[MAXPATHLEN], r1[16], r2[16], *rev_str1, *rev_str2;
+ char fpath[MAXPATHLEN], r1[16], r2[16], *rev_str1, *rev_str2;
RCSFILE *file;
RCSNUM *rev1, *rev2;
BUF *bp;
@@ -151,19 +151,17 @@ rcsmerge_main(int argc, char **argv)
else
status = 0;
- if (flags & PIPEOUT) {
- rcs_buf_putc(bp, '\0');
- fcont = rcs_buf_release(bp);
- printf("%s", fcont);
- xfree(fcont);
- } else {
+ if (flags & PIPEOUT)
+ rcs_buf_write_fd(bp, STDOUT_FILENO);
+ else {
/* XXX mode */
if (rcs_buf_write(bp, argv[0], 0644) < 0)
warnx("rcs_buf_write failed");
- rcs_buf_free(bp);
}
+ rcs_buf_free(bp);
+
out:
rcs_close(file);