summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjfb <jfb@openbsd.org>2005-03-05 05:58:39 +0000
committerjfb <jfb@openbsd.org>2005-03-05 05:58:39 +0000
commit4580e1eed91b29042a62a64c01be48630623ad50 (patch)
tree228b7b35eba8bf14234342884646dfd546482295
parentidentify ID tokens correctly and fix parsing of RCS files containing (diff)
downloadwireguard-openbsd-4580e1eed91b29042a62a64c01be48630623ad50.tar.xz
wireguard-openbsd-4580e1eed91b29042a62a64c01be48630623ad50.zip
add RCS error codes and a global variable to hold the last error
and make the code less verbose at the same time
-rw-r--r--usr.bin/cvs/rcs.c39
-rw-r--r--usr.bin/cvs/rcs.h13
-rw-r--r--usr.bin/cvs/rcsnum.c9
3 files changed, 48 insertions, 13 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 7f4e79cfbb4..2aaab689cbd 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.31 2005/03/05 05:02:15 jfb Exp $ */
+/* $OpenBSD: rcs.c,v 1.32 2005/03/05 05:58:39 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -146,6 +146,18 @@ static struct rcs_key {
#define RCS_NKEYS (sizeof(rcs_keys)/sizeof(rcs_keys[0]))
+static const char *rcs_errstrs[] = {
+ "No error",
+ "No such entry",
+ "Duplicate entry found",
+ "Bad RCS number",
+};
+
+#define RCS_NERR (sizeof(rcs_errstrs)/sizeof(rcs_errstrs[0]))
+
+
+int rcs_errno = RCS_ERR_NOERR;
+
static int rcs_write (RCSFILE *);
static int rcs_parse (RCSFILE *);
@@ -418,8 +430,7 @@ rcs_access_add(RCSFILE *file, const char *login)
/* first look for duplication */
TAILQ_FOREACH(ap, &(file->rf_access), ra_list) {
if (strcmp(ap->ra_name, login) == 0) {
- cvs_log(LP_ERR, "attempt to add duplicate access `%s'",
- login);
+ rcs_errno = RCS_ERR_DUPENT;
return (-1);
}
}
@@ -464,7 +475,7 @@ rcs_access_remove(RCSFILE *file, const char *login)
break;
if (ap == NULL) {
- cvs_log(LP_ERR, "%s: no access for `%s'", file->rf_path, login);
+ rcs_errno = RCS_ERR_NOENT;
return (-1);
}
@@ -493,8 +504,7 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum)
/* first look for duplication */
TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) {
if (strcmp(symp->rs_name, sym) == 0) {
- cvs_log(LP_ERR, "attempt to add duplicate symbol `%s'",
- sym);
+ rcs_errno = RCS_ERR_DUPENT;
return (-1);
}
}
@@ -547,7 +557,7 @@ rcs_sym_remove(RCSFILE *file, const char *sym)
break;
if (symp == NULL) {
- cvs_log(LP_ERR, "%s: no such symbol `%s'", file->rf_path, sym);
+ rcs_errno = RCS_ERR_NOENT;
return (-1);
}
@@ -837,7 +847,7 @@ rcs_getrev(RCSFILE *rfp, RCSNUM *rev)
res = rcsnum_cmp(rfp->rf_head, rev, 0);
if (res == 1) {
- cvs_log(LP_ERR, "sorry, can't travel in the future yet");
+ rcs_errno = RCS_ERR_NOENT;
return (NULL);
}
@@ -1041,6 +1051,19 @@ rcs_kflag_get(const char *flags)
return (fl);
}
+/*
+ * rcs_errstr()
+ *
+ * Get the error string matching the RCS error code <code>.
+ */
+const char*
+rcs_errstr(int code)
+{
+ if ((code < 0) || (code > (int)RCS_NERR))
+ return (NULL);
+ return (rcs_errstrs[code]);
+}
+
void
rcs_kflag_usage(void)
{
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index ecc9b382a6b..092eb656dba 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.13 2005/03/05 05:00:56 jfb Exp $ */
+/* $OpenBSD: rcs.h,v 1.14 2005/03/05 05:58:39 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -38,6 +38,7 @@
#define RCS_DIFF_DIV \
"==================================================================="
+#define RCSDIR "RCS"
#define RCS_FILE_EXT ",v"
#define RCS_HEAD_INIT "1.1"
@@ -83,6 +84,12 @@
/* delta flags */
#define RCS_RD_DEAD 0x01 /* dead */
+/* RCS error codes */
+#define RCS_ERR_NOERR 0
+#define RCS_ERR_NOENT 1
+#define RCS_ERR_DUPENT 2
+#define RCS_ERR_BADNUM 3
+
typedef struct rcs_num {
u_int rn_len;
@@ -159,6 +166,9 @@ typedef struct rcs_file {
} RCSFILE;
+extern int rcs_errno;
+
+
RCSFILE* rcs_open (const char *, int, ...);
void rcs_close (RCSFILE *);
int rcs_access_add (RCSFILE *, const char *);
@@ -176,6 +186,7 @@ const char* rcs_desc_get (RCSFILE *);
int rcs_desc_set (RCSFILE *, const char *);
int rcs_kwexp_set (RCSFILE *, int);
int rcs_kwexp_get (RCSFILE *);
+const char* rcs_errstr (int);
int rcs_kflag_get (const char *);
void rcs_kflag_usage (void);
diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c
index ccbb696ad88..9dba1f603bf 100644
--- a/usr.bin/cvs/rcsnum.c
+++ b/usr.bin/cvs/rcsnum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsnum.c,v 1.8 2005/02/25 20:32:48 jfb Exp $ */
+/* $OpenBSD: rcsnum.c,v 1.9 2005/03/05 05:58:39 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -74,7 +74,9 @@ rcsnum_parse(const char *str)
if ((rcsnum_aton(str, &ep, num) < 0) || (*ep != '\0')) {
rcsnum_free(num);
- return (NULL);
+ num = NULL;
+ if (*ep != '\0')
+ rcs_errno = RCS_ERR_BADNUM;
}
return (num);
@@ -230,9 +232,8 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump)
nump->rn_len++;
tmp = realloc(nump->rn_id,
(nump->rn_len + 1) * sizeof(u_int16_t));
- if (tmp == NULL) {
+ if (tmp == NULL)
goto rcsnum_aton_failed;
- }
nump->rn_id = (u_int16_t *)tmp;
nump->rn_id[nump->rn_len] = 0;
continue;