[mpich2-commits] r8006 - in mpich2/trunk/src/mpl: include src
goodell at mcs.anl.gov
goodell at mcs.anl.gov
Tue Feb 22 08:24:09 CST 2011
Author: goodell
Date: 2011-02-22 08:24:08 -0600 (Tue, 22 Feb 2011)
New Revision: 8006
Modified:
mpich2/trunk/src/mpl/include/mplstr.h
mpich2/trunk/src/mpl/src/mplstr.c
Log:
add MPL_strsep for portability
Reviwed by balaji at .
Modified: mpich2/trunk/src/mpl/include/mplstr.h
===================================================================
--- mpich2/trunk/src/mpl/include/mplstr.h 2011-02-22 14:24:05 UTC (rev 8005)
+++ mpich2/trunk/src/mpl/include/mplstr.h 2011-02-22 14:24:08 UTC (rev 8006)
@@ -36,6 +36,7 @@
#endif /* MPL_HAVE_STRDUP */
int MPL_strncpy(char *dest, const char *src, size_t n);
+char *MPL_strsep(char **stringp, const char *delim);
#if defined MPL_NEEDS_STRNCMP_DECL
extern int strncmp(const char *s1, const char *s2, size_t n);
Modified: mpich2/trunk/src/mpl/src/mplstr.c
===================================================================
--- mpich2/trunk/src/mpl/src/mplstr.c 2011-02-22 14:24:05 UTC (rev 8005)
+++ mpich2/trunk/src/mpl/src/mplstr.c 2011-02-22 14:24:08 UTC (rev 8006)
@@ -256,3 +256,45 @@
return 1;
}
}
+
+/* replacement for strsep. Conforms to the following description (from the OS X
+ * 10.6 man page):
+ *
+ * The strsep() function locates, in the string referenced by *stringp, the first occur-
+ * rence of any character in the string delim (or the terminating `\0' character) and
+ * replaces it with a `\0'. The location of the next character after the delimiter
+ * character (or NULL, if the end of the string was reached) is stored in *stringp. The
+ * original value of *stringp is returned.
+ *
+ * An ``empty'' field (i.e., a character in the string delim occurs as the first charac-
+ * ter of *stringp) can be detected by comparing the location referenced by the returned
+ * pointer to `\0'.
+ *
+ * If *stringp is initially NULL, strsep() returns NULL.
+ */
+char *MPL_strsep(char **stringp, const char *delim)
+{
+ int i, j;
+ char *ret;
+
+ if (!*stringp)
+ return NULL;
+
+ ret = *stringp;
+ i = 0;
+ while (1) {
+ if (!ret[i]) {
+ *stringp = NULL;
+ return ret;
+ }
+ for (j = 0; delim[j] != '\0'; ++j) {
+ if (ret[i] == delim[j]) {
+ ret[i] = '\0';
+ *stringp = &ret[i+1];
+ return ret;
+ }
+ }
+ ++i;
+ }
+}
+
More information about the mpich2-commits
mailing list