diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-07-13 16:20:45 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-07-13 16:20:45 +0000 |
commit | d3f73890db9153a5eabf3a9247dac6edecffec9b (patch) | |
tree | d4191d5a4632a7cf69a374870e47f9a3e7ee8f47 /usr.bin/cvs | |
parent | 0147d73439fae6cc68545c98899dbd920e45b067 (diff) |
add cvs_rcs_getpath() function. Returns the path of the RCS file if it
does exist. Will save us code duplication.
ok joris@ jfb@.
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/cvs.h | 37 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 31 |
2 files changed, 50 insertions, 18 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index 20724293f50..f05dbab6c49 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.68 2005/07/07 14:27:57 joris Exp $ */ +/* $OpenBSD: cvs.h,v 1.69 2005/07/13 16:20:44 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -113,6 +113,7 @@ /* server-side paths */ #define CVS_PATH_ROOT "CVSROOT" +#define CVS_PATH_EMPTYDIR CVS_PATH_ROOT "/Emptydir" #define CVS_PATH_COMMITINFO CVS_PATH_ROOT "/commitinfo" #define CVS_PATH_CONFIG CVS_PATH_ROOT "/config" #define CVS_PATH_CVSIGNORE CVS_PATH_ROOT "/cvsignore" @@ -351,7 +352,7 @@ int cvs_var_unset (const char *); const char* cvs_var_get (const char *); -/* from root.c */ +/* root.c */ struct cvsroot* cvsroot_parse (const char *); void cvsroot_free (struct cvsroot *); struct cvsroot* cvsroot_get (const char *); @@ -376,27 +377,29 @@ int cvs_hist_parse (CVSHIST *); struct cvs_hent* cvs_hist_getnext (CVSHIST *); int cvs_hist_append (CVSHIST *, struct cvs_hent *); -/* from logmsg.c */ +/* logmsg.c */ char* cvs_logmsg_open (const char *); char* cvs_logmsg_get (const char *, struct cvs_flist *, struct cvs_flist *, struct cvs_flist *); int cvs_logmsg_send (struct cvsroot *, const char *); - +/* date.y */ time_t cvs_date_parse (const char *); -int cvs_readrepo (const char *, char *, size_t); -int cvs_modetostr (mode_t, char *, size_t); -int cvs_strtomode (const char *, mode_t *); -int cvs_splitpath (const char *, char *, size_t, char **); -int cvs_mkadmin (const char *, const char *, const char *); -int cvs_cksum (const char *, char *, size_t); -int cvs_exec (int, char **, int []); -int cvs_getargv (const char *, char **, int); -int cvs_remove_dir (const char *); -int cvs_create_dir (const char *, int, char *, char *); -char** cvs_makeargv (const char *, int *); -void cvs_freeargv (char **, int); -size_t cvs_path_cat (const char *, const char *, char *, size_t); +/* util.c */ +int cvs_readrepo (const char *, char *, size_t); +int cvs_modetostr (mode_t, char *, size_t); +int cvs_strtomode (const char *, mode_t *); +int cvs_splitpath (const char *, char *, size_t, char **); +int cvs_mkadmin (const char *, const char *, const char *); +int cvs_cksum (const char *, char *, size_t); +int cvs_exec (int, char **, int []); +int cvs_getargv (const char *, char **, int); +int cvs_remove_dir (const char *); +int cvs_create_dir (const char *, int, char *, char *); +char* cvs_rcs_getpath (CVSFILE *, char *, size_t); +char** cvs_makeargv (const char *, int *); +void cvs_freeargv (char **, int); +size_t cvs_path_cat (const char *, const char *, char *, size_t); #endif /* CVS_H */ diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 19fd6fcb638..9bed15887e3 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.34 2005/06/17 15:09:55 joris Exp $ */ +/* $OpenBSD: util.c,v 1.35 2005/07/13 16:20:44 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -708,3 +708,32 @@ cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen) return (len); } + +/* + * cvs_rcs_getpath() + * + * Get the RCS path of the file <file> and store it in <buf>, which is + * of size <len>. For portability, it is recommended that <buf> always be + * at least MAXPATHLEN bytes long. + * Returns a pointer to the start of the path on success, or NULL on failure. + */ +char* +cvs_rcs_getpath(CVSFILE *file, char *buf, size_t len) +{ + int l; + char *repo; + struct cvsroot *root; + + root = CVS_DIR_ROOT(file); + repo = CVS_DIR_REPO(file); + + l = snprintf(buf, len, "%s/%s/%s%s", + root->cr_dir, repo, file->cf_name, RCS_FILE_EXT); + if (l == -1 || l >= (int)len) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", buf); + return (NULL); + } + + return (buf); +} |