summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall O'Higgins <niallo@cvs.openbsd.org>2005-12-02 01:13:13 +0000
committerNiall O'Higgins <niallo@cvs.openbsd.org>2005-12-02 01:13:13 +0000
commitdd18888db8b50829025fd576d65182580bbf7f0b (patch)
treeb280ec9ea3803a1e66f1a7fb2cb515002826add2
parent016dee85f2139d586928ee42edbeb852479197f9 (diff)
- fix up checkin_choose_rcsfile() to give us a path like the one GNU print,
instead of always returning an absolute path. ok joris@
-rw-r--r--usr.bin/rcs/ci.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index 5582837ba81..a1dc7922b2d 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.75 2005/12/02 00:15:35 niallo Exp $ */
+/* $OpenBSD: ci.c,v 1.76 2005/12/02 01:13:12 niallo Exp $ */
/*
* Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -748,41 +748,58 @@ checkin_mtimedate(struct checkin_params *pb)
static char *
checkin_choose_rcsfile(const char *filename)
{
- char fullpath[MAXPATHLEN], *basepath;
+ char name[MAXPATHLEN], *basepath;
+ const char *ptr;
size_t len;
struct stat sb;
- if (realpath(filename, fullpath) == NULL) {
- cvs_log(LP_ERRNO, "realpath failed: `%s'", filename);
+ if ((basepath = malloc(MAXPATHLEN)) == NULL) {
+ cvs_log(LP_ERRNO, "could not allocate memory");
return (NULL);
}
- len = strlen(fullpath);
- while (fullpath[len] != '/')
- len--;
- if (len > 0) {
+ if (strchr(filename, '/') == NULL) {
+ strlcat(basepath, RCSDIR"/", MAXPATHLEN);
+ if ((stat(basepath, &sb) == 0) && (sb.st_mode & S_IFDIR)) {
+ /* <path>/RCS/<filename>,v */
+ strlcat(basepath, filename, MAXPATHLEN);
+ strlcat(basepath, RCS_FILE_EXT, MAXPATHLEN);
+ } else {
+ /* <path>/<filename>,v */
+ memset(basepath, '\0', MAXPATHLEN);
+ strlcpy(basepath, filename, MAXPATHLEN);
+ strlcat(basepath, RCS_FILE_EXT, MAXPATHLEN);
+ }
+ } else {
+ ptr = filename;
+ /* Walk backwards till we find the base directory */
+ len = strlen(filename);
+ ptr += len + 1;
+ while (filename[len] != '/') {
+ len--;
+ ptr--;
+ }
/*
* Need two bytes extra for trailing slash and
* NUL-termination.
*/
len += 2;
- if ((basepath = malloc(MAXPATHLEN)) == NULL) {
- cvs_log(LP_ERRNO, "could not allocate memory");
+ if (len > MAXPATHLEN) {
+ free(basepath);
return (NULL);
}
- strlcpy(basepath, fullpath, len);
+ strlcpy(basepath, filename, len);
+ strlcpy(name, ptr, MAXPATHLEN);
strlcat(basepath, RCSDIR"/", MAXPATHLEN);
if ((stat(basepath, &sb) == 0) && (sb.st_mode & S_IFDIR)) {
/* <path>/RCS/<filename>,v */
- strlcat(basepath, filename, MAXPATHLEN);
+ strlcat(basepath, name, MAXPATHLEN);
strlcat(basepath, RCS_FILE_EXT, MAXPATHLEN);
} else {
/* <path>/<filename>,v */
memset(basepath, '\0', MAXPATHLEN);
- strlcpy(basepath, fullpath, len);
- strlcat(basepath, filename, MAXPATHLEN);
+ strlcpy(basepath, filename, MAXPATHLEN);
strlcat(basepath, RCS_FILE_EXT, MAXPATHLEN);
}
- return (basepath);
- } else
- return (NULL);
+ }
+ return (basepath);
}