summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-05-26 22:25:32 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-05-26 22:25:32 +0000
commit4a3c8238a722dc1e543d412a6f7c6c36d2114061 (patch)
tree3d812ee94979db5e6c4afda09adf49a06484281b /usr.bin/cvs
parent3f25795bbe6ea9adaae9d8d55de1657a5851a326 (diff)
don't keep a pointer to the file handle in CVSENTRIES, it is only
used in cvs_ent_write(), and simplify path building a bit
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/cvs.h4
-rw-r--r--usr.bin/cvs/entries.c35
-rw-r--r--usr.bin/cvs/util.c23
3 files changed, 37 insertions, 25 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 16e5b4f9508..3c0a018e565 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.61 2005/05/26 21:25:49 jfb Exp $ */
+/* $OpenBSD: cvs.h,v 1.62 2005/05/26 22:25:31 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -254,7 +254,6 @@ struct cvs_ent {
typedef struct cvs_entries {
char *cef_path;
- FILE *cef_file;
u_int cef_flags;
TAILQ_HEAD(, cvs_ent) cef_ent;
@@ -396,6 +395,7 @@ int cvs_getargv (const char *, char **, int);
int cvs_remove_dir (const char *);
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/entries.c b/usr.bin/cvs/entries.c
index df5427356b3..df964fc8e76 100644
--- a/usr.bin/cvs/entries.c
+++ b/usr.bin/cvs/entries.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entries.c,v 1.31 2005/05/26 21:25:49 jfb Exp $ */
+/* $OpenBSD: entries.c,v 1.32 2005/05/26 22:25:31 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -53,7 +53,7 @@ CVSENTRIES*
cvs_ent_open(const char *dir, int flags)
{
size_t len;
- int exists, l;
+ int exists;
char entpath[MAXPATHLEN], ebuf[128], mode[4];
FILE *fp;
struct stat st;
@@ -63,8 +63,8 @@ cvs_ent_open(const char *dir, int flags)
exists = 0;
memset(mode, 0, sizeof(mode));
- l = snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);
- if (l == -1 || l >= (int)sizeof(entpath)) {
+ len = cvs_path_cat(dir, CVS_PATH_ENTRIES, entpath, sizeof(entpath));
+ if (len >= sizeof(entpath)) {
errno = ENAMETOOLONG;
cvs_log(LP_ERRNO, "%s", entpath);
return (NULL);
@@ -163,8 +163,6 @@ cvs_ent_close(CVSENTRIES *ep)
(void)cvs_ent_write(ep);
}
- if (ep->cef_file != NULL)
- (void)fclose(ep->cef_file);
if (ep->cef_path != NULL)
free(ep->cef_path);
@@ -412,25 +410,19 @@ cvs_ent_write(CVSENTRIES *ef)
size_t len;
char revbuf[64], timebuf[32];
struct cvs_ent *ent;
+ FILE *fp;
if (ef->cef_flags & CVS_ENTF_SYNC)
return (0);
- if (ef->cef_file == NULL) {
- ef->cef_file = fopen(ef->cef_path, "w");
- if (ef->cef_file == NULL) {
- cvs_log(LP_ERRNO, "failed to open Entries `%s'",
- ef->cef_path);
- return (-1);
- }
+ if ((fp = fopen(ef->cef_path, "w")) == NULL) {
+ cvs_log(LP_ERRNO, "failed to open Entries `%s'", ef->cef_path);
+ return (-1);
}
-
- /* reposition ourself at beginning of file */
- rewind(ef->cef_file);
TAILQ_FOREACH(ent, &(ef->cef_ent), ce_list) {
if (ent->ce_type == CVS_ENT_DIR) {
- putc('D', ef->cef_file);
+ putc('D', fp);
timebuf[0] = '\0';
revbuf[0] = '\0';
} else {
@@ -447,17 +439,16 @@ cvs_ent_write(CVSENTRIES *ef)
}
}
- fprintf(ef->cef_file, "/%s/%s%s/%s/%s/%s\n", ent->ce_name,
+ fprintf(fp, "/%s/%s%s/%s/%s/%s\n", ent->ce_name,
(ent->ce_status == CVS_ENT_REMOVED) ? "-" : "", revbuf,
timebuf, "", "");
}
/* terminating line */
- fprintf(ef->cef_file, "D\n");
+ putc('D', fp);
+ putc('\n', fp);
ef->cef_flags |= CVS_ENTF_SYNC;
- fclose(ef->cef_file);
- ef->cef_file = NULL;
-
+ fclose(fp);
return (0);
}
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index 12ea00ad898..2bbf3efa57c 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.28 2005/05/24 20:04:43 joris Exp $ */
+/* $OpenBSD: util.c,v 1.29 2005/05/26 22:25:31 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -559,3 +559,24 @@ cvs_remove_dir(const char *path)
return (CVS_EX_OK);
}
+size_t
+cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen)
+{
+ size_t len;
+
+ len = strlcpy(dst, base, dlen);
+ if (len >= dlen - 1) {
+ errno = ENAMETOOLONG;
+ cvs_log(LP_ERRNO, "%s", dst);
+ } else {
+ dst[len] = '/';
+ dst[len + 1] = '\0';
+ len = strlcat(dst, end, dlen);
+ if (len >= dlen) {
+ errno = ENAMETOOLONG;
+ cvs_log(LP_ERRNO, "%s", dst);
+ }
+ }
+
+ return (len);
+}