summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2010-10-20 19:53:53 +0000
committertobias <tobias@openbsd.org>2010-10-20 19:53:53 +0000
commit394437e69217ff52d485085d17fba7362e00e4bf (patch)
tree8bb593072c9cb02626742068bc3a45a5fa38c5a3
parentMark repeating keys with "(repeat)" in the key list. (diff)
downloadwireguard-openbsd-394437e69217ff52d485085d17fba7362e00e4bf.tar.xz
wireguard-openbsd-394437e69217ff52d485085d17fba7362e00e4bf.zip
Remove the need for rp_file in parser structure, instead keep only one
FILE pointer in RCSFILE. This fixes some ugliness in closing an fdopen()ed FILE and its underlying file descriptor. Notified by Joerg Sonnenberger <joerg at britannica dot bec to de> discussed with and ok nicm
-rw-r--r--usr.bin/cvs/rcs.c9
-rw-r--r--usr.bin/cvs/rcs.h7
-rw-r--r--usr.bin/cvs/rcsparse.c28
-rw-r--r--usr.bin/rcs/co.c6
-rw-r--r--usr.bin/rcs/rcs.c9
-rw-r--r--usr.bin/rcs/rcs.h6
-rw-r--r--usr.bin/rcs/rcsparse.c28
-rw-r--r--usr.bin/rcs/rcsutil.c11
8 files changed, 55 insertions, 49 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index cf497afb73c..ebffcca0445 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.304 2010/10/15 08:46:23 tobias Exp $ */
+/* $OpenBSD: rcs.c,v 1.305 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -176,7 +176,10 @@ rcs_open(const char *path, int fd, int flags, ...)
rfp->rf_path = xstrdup(path);
rfp->rf_flags = flags | RCS_SLOCK | RCS_SYNCED;
rfp->rf_mode = fmode;
- rfp->rf_fd = fd;
+ if (fd == -1)
+ rfp->rf_file = NULL;
+ else if ((rfp->rf_file = fdopen(fd, "r")) == NULL)
+ fatal("rcs_open: %s: fdopen: %s", path, strerror(errno));
rfp->rf_dead = 0;
TAILQ_INIT(&(rfp->rf_delta));
@@ -252,6 +255,8 @@ rcs_close(RCSFILE *rfp)
if (rfp->rf_branch != NULL)
rcsnum_free(rfp->rf_branch);
+ if (rfp->rf_file != NULL)
+ fclose(rfp->rf_file);
if (rfp->rf_path != NULL)
xfree(rfp->rf_path);
if (rfp->rf_comment != NULL)
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index 702e13dc4e5..98b20eeae8a 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.96 2010/09/03 08:37:52 tobias Exp $ */
+/* $OpenBSD: rcs.h,v 1.97 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -26,6 +26,9 @@
#ifndef RCS_H
#define RCS_H
+
+#include <stdio.h>
+
#include "buf.h"
#define RCS_DIFF_DIV \
@@ -169,7 +172,7 @@ struct rcs_delta {
typedef struct rcs_file {
- int rf_fd;
+ FILE *rf_file;
int rf_dead;
char *rf_path;
mode_t rf_mode;
diff --git a/usr.bin/cvs/rcsparse.c b/usr.bin/cvs/rcsparse.c
index c9df8c4e460..e894be629f0 100644
--- a/usr.bin/cvs/rcsparse.c
+++ b/usr.bin/cvs/rcsparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsparse.c,v 1.2 2010/10/20 06:51:26 tobias Exp $ */
+/* $OpenBSD: rcsparse.c,v 1.3 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2010 Tobias Stoeckmann <tobias@openbsd.org>
*
@@ -78,7 +78,6 @@ struct rcs_pdata {
size_t rp_tlen;
struct rcs_delta *rp_delta;
- FILE *rp_file;
int rp_lineno;
int rp_msglineno;
int rp_token;
@@ -230,10 +229,7 @@ rcsparse_init(RCSFILE *rfp)
pdp->rp_token = -1;
pdp->rp_lineno = 1;
pdp->rp_msglineno = 1;
- if ((pdp->rp_file = fdopen(rfp->rf_fd, "r")) == NULL) {
- xfree(pdp);
- return (1);
- }
+
/* ditch the strict lock */
rfp->rf_flags &= ~RCS_SLOCK;
rfp->rf_pdata = pdp;
@@ -343,8 +339,6 @@ rcsparse_free(RCSFILE *rfp)
pdp = rfp->rf_pdata;
- if (pdp->rp_file != NULL)
- (void)fclose(pdp->rp_file);
if (pdp->rp_buf != NULL)
xfree(pdp->rp_buf);
if (pdp->rp_token == RCS_TYPE_REVISION)
@@ -850,13 +844,13 @@ rcsparse_string(RCSFILE *rfp, int allowed)
*bp = '\0';
for (;;) {
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == '@') {
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == EOF) {
return (EOF);
} else if (c != '@') {
- ungetc(c, pdp->rp_file);
+ ungetc(c, rfp->rf_file);
break;
}
}
@@ -905,9 +899,9 @@ rcsparse_token(RCSFILE *rfp, int allowed)
c = EOF;
do {
pre = c;
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == EOF) {
- if (ferror(pdp->rp_file)) {
+ if (ferror(rfp->rf_file)) {
rcsparse_warnx(rfp, "error during parsing");
return (0);
}
@@ -924,7 +918,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
switch (c) {
case '@':
ret = rcsparse_string(rfp, allowed);
- if (ret == EOF && ferror(pdp->rp_file)) {
+ if (ret == EOF && ferror(rfp->rf_file)) {
rcsparse_warnx(rfp, "error during parsing");
return (0);
}
@@ -966,7 +960,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
for (;;) {
if (c == EOF) {
- if (ferror(pdp->rp_file))
+ if (ferror(rfp->rf_file))
rcsparse_warnx(rfp, "error during parsing");
else
rcsparse_warnx(rfp, "unexpected end of file");
@@ -976,7 +970,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
RBUF_PUTC(c);
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (isspace(c)) {
if (c == '\n')
@@ -984,7 +978,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
RBUF_PUTC('\0');
break;
} else if (c == ';' || c == ':' || c == ',') {
- ungetc(c, pdp->rp_file);
+ ungetc(c, rfp->rf_file);
RBUF_PUTC('\0');
break;
} else if (!isgraph(c)) {
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c
index 23101957a28..8e674303d60 100644
--- a/usr.bin/rcs/co.c
+++ b/usr.bin/rcs/co.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: co.c,v 1.114 2010/09/08 15:15:50 tobias Exp $ */
+/* $OpenBSD: co.c,v 1.115 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -366,8 +366,8 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags,
/*
* File inherits permissions from its ,v file
*/
- if (file->rf_fd != -1) {
- if (fstat(file->rf_fd, &st) == -1)
+ if (file->rf_file != NULL) {
+ if (fstat(fileno(file->rf_file), &st) == -1)
err(1, "%s", file->rf_path);
file->rf_mode = mode = st.st_mode;
} else {
diff --git a/usr.bin/rcs/rcs.c b/usr.bin/rcs/rcs.c
index 0c27b338126..1d58cb5cdc2 100644
--- a/usr.bin/rcs/rcs.c
+++ b/usr.bin/rcs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.68 2010/10/15 08:44:12 tobias Exp $ */
+/* $OpenBSD: rcs.c,v 1.69 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -185,7 +185,10 @@ rcs_open(const char *path, int fd, int flags, ...)
rfp->rf_path = xstrdup(path);
rfp->rf_flags = flags | RCS_SLOCK | RCS_SYNCED;
rfp->rf_mode = fmode;
- rfp->rf_fd = fd;
+ if (fd == -1)
+ rfp->rf_file = NULL;
+ else if ((rfp->rf_file = fdopen(fd, "r")) == NULL)
+ err(1, "rcs_open: fdopen: `%s'", path);
TAILQ_INIT(&(rfp->rf_delta));
TAILQ_INIT(&(rfp->rf_access));
@@ -260,6 +263,8 @@ rcs_close(RCSFILE *rfp)
if (rfp->rf_branch != NULL)
rcsnum_free(rfp->rf_branch);
+ if (rfp->rf_file != NULL)
+ fclose(rfp->rf_file);
if (rfp->rf_path != NULL)
xfree(rfp->rf_path);
if (rfp->rf_comment != NULL)
diff --git a/usr.bin/rcs/rcs.h b/usr.bin/rcs/rcs.h
index 4c7c0549ac9..1af66b21c8b 100644
--- a/usr.bin/rcs/rcs.h
+++ b/usr.bin/rcs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.12 2010/10/05 15:16:48 tobias Exp $ */
+/* $OpenBSD: rcs.h,v 1.13 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -29,6 +29,8 @@
#include <sys/queue.h>
+#include <stdio.h>
+
#include "buf.h"
#define RCS_DIFF_MAXARG 32
@@ -187,7 +189,7 @@ struct rcs_delta {
typedef struct rcs_file {
- int rf_fd;
+ FILE *rf_file;
char *rf_path;
mode_t rf_mode;
u_int rf_flags;
diff --git a/usr.bin/rcs/rcsparse.c b/usr.bin/rcs/rcsparse.c
index dff4c8214e2..b8a8b42fb21 100644
--- a/usr.bin/rcs/rcsparse.c
+++ b/usr.bin/rcs/rcsparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsparse.c,v 1.3 2010/10/20 06:51:26 tobias Exp $ */
+/* $OpenBSD: rcsparse.c,v 1.4 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2010 Tobias Stoeckmann <tobias@openbsd.org>
*
@@ -77,7 +77,6 @@ struct rcs_pdata {
size_t rp_tlen;
struct rcs_delta *rp_delta;
- FILE *rp_file;
int rp_lineno;
int rp_msglineno;
int rp_token;
@@ -229,10 +228,7 @@ rcsparse_init(RCSFILE *rfp)
pdp->rp_token = -1;
pdp->rp_lineno = 1;
pdp->rp_msglineno = 1;
- if ((pdp->rp_file = fdopen(rfp->rf_fd, "r")) == NULL) {
- xfree(pdp);
- return (1);
- }
+
/* ditch the strict lock */
rfp->rf_flags &= ~RCS_SLOCK;
rfp->rf_pdata = pdp;
@@ -342,8 +338,6 @@ rcsparse_free(RCSFILE *rfp)
pdp = rfp->rf_pdata;
- if (pdp->rp_file != NULL)
- (void)fclose(pdp->rp_file);
if (pdp->rp_buf != NULL)
xfree(pdp->rp_buf);
if (pdp->rp_token == RCS_TYPE_REVISION)
@@ -849,13 +843,13 @@ rcsparse_string(RCSFILE *rfp, int allowed)
*bp = '\0';
for (;;) {
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == '@') {
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == EOF) {
return (EOF);
} else if (c != '@') {
- ungetc(c, pdp->rp_file);
+ ungetc(c, rfp->rf_file);
break;
}
}
@@ -904,9 +898,9 @@ rcsparse_token(RCSFILE *rfp, int allowed)
c = EOF;
do {
pre = c;
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (c == EOF) {
- if (ferror(pdp->rp_file)) {
+ if (ferror(rfp->rf_file)) {
rcsparse_warnx(rfp, "error during parsing");
return (0);
}
@@ -923,7 +917,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
switch (c) {
case '@':
ret = rcsparse_string(rfp, allowed);
- if (ret == EOF && ferror(pdp->rp_file)) {
+ if (ret == EOF && ferror(rfp->rf_file)) {
rcsparse_warnx(rfp, "error during parsing");
return (0);
}
@@ -965,7 +959,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
for (;;) {
if (c == EOF) {
- if (ferror(pdp->rp_file))
+ if (ferror(rfp->rf_file))
rcsparse_warnx(rfp, "error during parsing");
else
rcsparse_warnx(rfp, "unexpected end of file");
@@ -975,7 +969,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
RBUF_PUTC(c);
- c = getc(pdp->rp_file);
+ c = getc(rfp->rf_file);
if (isspace(c)) {
if (c == '\n')
@@ -983,7 +977,7 @@ rcsparse_token(RCSFILE *rfp, int allowed)
RBUF_PUTC('\0');
break;
} else if (c == ';' || c == ':' || c == ',') {
- ungetc(c, pdp->rp_file);
+ ungetc(c, rfp->rf_file);
RBUF_PUTC('\0');
break;
} else if (!isgraph(c)) {
diff --git a/usr.bin/rcs/rcsutil.c b/usr.bin/rcs/rcsutil.c
index 54f737f5c52..5ea5dd12285 100644
--- a/usr.bin/rcs/rcsutil.c
+++ b/usr.bin/rcs/rcsutil.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsutil.c,v 1.36 2010/09/08 15:15:50 tobias Exp $ */
+/* $OpenBSD: rcsutil.c,v 1.37 2010/10/20 19:53:53 tobias Exp $ */
/*
* Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -50,7 +50,10 @@ rcs_get_mtime(RCSFILE *file)
struct stat st;
time_t mtime;
- if (fstat(file->rf_fd, &st) == -1) {
+ if (file->rf_file == NULL)
+ return (-1);
+
+ if (fstat(fileno(file->rf_file), &st) == -1) {
warn("%s", file->rf_path);
return (-1);
}
@@ -70,13 +73,13 @@ rcs_set_mtime(RCSFILE *file, time_t mtime)
{
static struct timeval tv[2];
- if (mtime == -1)
+ if (file->rf_file == NULL || mtime == -1)
return;
tv[0].tv_sec = mtime;
tv[1].tv_sec = tv[0].tv_sec;
- if (futimes(file->rf_fd, tv) == -1)
+ if (futimes(fileno(file->rf_file), tv) == -1)
err(1, "utimes");
}