diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-05-28 17:25:19 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-05-28 17:25:19 +0000 |
commit | ba54056f0ec2e5f1552b8ce2356271757127969c (patch) | |
tree | 237a3343e2eceafd37a35e6b879287cf7778dee7 /usr.bin/cvs/util.c | |
parent | 4d7e39ac1a71def26ae9e6a35bbd5c9cf678ad51 (diff) |
several fixes to the file api:
- default to CVS_FILE when something is totally unknown
- cvs_get_repository_path() now returns the full repository path for
the given argument.
- cvs_get_repository_name() returns the contents of CVS/Repository
to the caller.
- allow command callbacks to specify if our recursion code needs
to skip the directory or not.
- when checking for a admin directory, make sure it is in fact
a directory. if it is not we dont want to recurse inside.
Diffstat (limited to 'usr.bin/cvs/util.c')
-rw-r--r-- | usr.bin/cvs/util.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 2c0b9677399..8eacf9ac418 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.80 2006/05/27 16:18:23 joris Exp $ */ +/* $OpenBSD: util.c,v 1.81 2006/05/28 17:25:18 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -568,31 +568,39 @@ cvs_hack_time(time_t oldtime, int togmt) } void -cvs_get_repo(const char *dir, char *dst, size_t len) +cvs_get_repository_path(const char *dir, char *dst, size_t len) { int l; - FILE *fp; - char *s, buf[MAXPATHLEN], fpath[MAXPATHLEN]; + char buf[MAXPATHLEN]; - if (strlcpy(buf, dir, sizeof(buf)) >= sizeof(buf)) - fatal("cvs_get_repo: truncation"); + cvs_get_repository_name(dir, buf, sizeof(buf)); + l = snprintf(dst, len, "%s/%s", current_cvsroot->cr_dir, buf); + if (l == -1 || l >= (int)len) + fatal("cvs_get_repository_path: overflow"); +} + +void +cvs_get_repository_name(const char *dir, char *dst, size_t len) +{ + int l; + FILE *fp; + char *s, fpath[MAXPATHLEN]; l = snprintf(fpath, sizeof(fpath), "%s/%s", dir, CVS_PATH_REPOSITORY); if (l == -1 || l >= (int)sizeof(fpath)) - fatal("cvs_get_repo: overflow"); + fatal("cvs_get_repository_name: overflow"); if ((fp = fopen(fpath, "r")) != NULL) { - fgets(buf, sizeof(buf), fp); + fgets(dst, len, fp); - if ((s = strrchr(buf, '\n')) != NULL) + if ((s = strchr(dst, '\n')) != NULL) *s = '\0'; (void)fclose(fp); + } else { + if (strlcpy(dst, dir, len) >= len) + fatal("cvs_get_repository_name: overflow"); } - - l = snprintf(dst, len, "%s/%s", current_cvsroot->cr_dir, buf); - if (l == -1 || l >= (int)len) - fatal("cvs_get_repo: overflow"); } void |