summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/util.c
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2006-03-17 08:51:46 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2006-03-17 08:51:46 +0000
commit54c45ec4af9c4db50ed7a048accb4d2848d0a767 (patch)
tree8da4136138f8118eab762112eac24a4f5268fdbe /usr.bin/cvs/util.c
parent7b682b3417ffb86bfa19d25ced33eca7604ca193 (diff)
rlog_strsplit() -> cvs_strsplit() and move it to util.c so it can be reused
by `cvs log' and some other RCS utilities. "Looks good" ray@.
Diffstat (limited to 'usr.bin/cvs/util.c')
-rw-r--r--usr.bin/cvs/util.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index 161e06eb216..05abcf7b39c 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,6 +1,8 @@
-/* $OpenBSD: util.c,v 1.70 2006/03/15 19:59:36 niallo Exp $ */
+/* $OpenBSD: util.c,v 1.71 2006/03/17 08:51:45 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
+ * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org>
+ * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1044,3 +1046,28 @@ cvs_yesno(void)
return (ret);
}
+/*
+ * cvs_strsplit()
+ *
+ * Split a string <str> of <sep>-separated values and allocate
+ * an argument vector for the values found.
+ */
+char **
+cvs_strsplit(char *str, const char *sep)
+{
+ char **argv, **nargv;
+ char *cp, *p;
+ int i = 0;
+
+ cp = xstrdup(str);
+ argv = (char **)xmalloc((i+1) * sizeof(char *));
+
+ while ((p = strsep(&cp, sep)) != NULL) {
+ argv[i++] = p;
+ nargv = (char **)xrealloc((void *)argv, (i+1) * sizeof(char *));
+ argv = nargv;
+ }
+ argv[i] = NULL;
+
+ return (argv);
+}