summaryrefslogtreecommitdiff
path: root/usr.bin/rcs/rcsprog.c
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-03-16 03:51:19 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-03-16 03:51:19 +0000
commitfbd528cb17247e0819312318a58a52348021cd77 (patch)
tree6defd4000552ad4c2ee7ba6eed8925f4407771d1 /usr.bin/rcs/rcsprog.c
parente7a47e1c362fb1550b46fce8b36c8e27b3901d4d (diff)
Simplify rcs_statfile() by having it call rcs_choosefile().
ok xsa and niallo
Diffstat (limited to 'usr.bin/rcs/rcsprog.c')
-rw-r--r--usr.bin/rcs/rcsprog.c76
1 files changed, 17 insertions, 59 deletions
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c
index 229b6830924..9bcc606b20f 100644
--- a/usr.bin/rcs/rcsprog.c
+++ b/usr.bin/rcs/rcsprog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.c,v 1.74 2006/03/15 03:29:01 ray Exp $ */
+/* $OpenBSD: rcsprog.c,v 1.75 2006/03/16 03:51:18 ray Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -352,77 +352,35 @@ rcs_choosefile(const char *filename)
return (ret);
}
+/*
+ * Find the name of an RCS file, given a file name `fname'. If an RCS
+ * file is found, the name is copied to the `len' sized buffer `out'.
+ * Returns 0 if RCS file was found, -1 otherwise.
+ */
int
rcs_statfile(char *fname, char *out, size_t len)
{
- int found;
- char defaultsuffix[] = RCS_DEFAULT_SUFFIX;
- char filev[MAXPATHLEN], fpath[MAXPATHLEN];
- char *ext, *slash;
struct stat st;
+ char *rcspath;
- found = 0;
-
- if (rcs_suffixes != NULL)
- ext = rcs_suffixes;
- else
- ext = defaultsuffix;
-
- for (;;) {
- /*
- * GNU documentation says -x,v/ specifies two suffixes,
- * namely the ,v one and an empty one (which matches
- * everything).
- * The problem is that they don't follow this rule at
- * all, and their documentation seems flawed.
- * We try to be compatible, so let's do so.
- */
- if (*ext == '\0')
- break;
-
- if ((slash = strchr(ext, '/')) != NULL)
- *slash = '\0';
-
- if (strlcpy(filev, fname, sizeof(filev)) >= sizeof(filev) ||
- strlcat(filev, ext, sizeof(filev)) >= sizeof(filev))
- fatal("rcs_statfile: path truncation");
-
- if (stat(RCSDIR, &st) != -1 && (st.st_mode & S_IFDIR)) {
- if (strlcpy(fpath, RCSDIR,
- sizeof(fpath)) >= sizeof(fpath) ||
- strlcat(fpath, "/",
- sizeof(fpath)) >= sizeof(fpath) ||
- strlcat(fpath, filev,
- sizeof(fpath)) >= sizeof(fpath))
- fatal("rcs_statfile: path truncation");
- } else {
- if (strlcpy(fpath, filev,
- sizeof(fpath)) >= sizeof(fpath))
- fatal("rcs_statfile: path truncation");
- }
-
- if ((stat(fpath, &st) != -1) || (rcsflags & RCS_CREATE)) {
- found++;
- break;
- }
-
- if (slash == NULL)
- break;
-
- *slash++ = '/';
- ext = slash;
- }
+ /* XXX - do this in rcs_choosefile? */
+ if ((rcspath = rcs_choosefile(fname)) == NULL)
+ fatal("rcs_statfile: path truncation");
- if (found != 1) {
+ /* File not found. */
+ if (stat(rcspath, &st) == -1) {
if ((strcmp(__progname, "rcsclean") != 0)
&& (strcmp(__progname, "ci") != 0))
- cvs_log(LP_ERRNO, "%s", fpath);
+ cvs_log(LP_ERRNO, "%s", rcspath);
+ xfree(rcspath);
return (-1);
}
- if (strlcpy(out, fpath, len) >= len)
+ if (strlcpy(out, rcspath, len) >= len)
fatal("rcs_statfile: path truncation");
+ xfree(rcspath);
+
return (0);
}