Explorar o código

* Added openBSD's strsep() for future use

svn: 1710
Bryan Drewery %!s(int64=21) %!d(string=hai) anos
pai
achega
2cadc5a7bf
Modificáronse 6 ficheiros con 61 adicións e 1 borrados
  1. 2 1
      src/compat/Makefile.in
  2. 1 0
      src/compat/compat.h
  3. 1 0
      src/compat/strlcpy.c
  4. 1 0
      src/compat/strlcpy.h
  5. 47 0
      src/compat/strsep.c
  6. 9 0
      src/compat/strsep.h

+ 2 - 1
src/compat/Makefile.in

@@ -24,7 +24,8 @@ OBJS = dirname.o \
 	memutil.o \
 	strcasecmp.o \
 	strftime.o \
-	strlcpy.o 
+	strlcpy.o \
+	strsep.o
 
 doofus:
 	@echo ""

+ 1 - 0
src/compat/compat.h

@@ -19,6 +19,7 @@
 #include "strftime.h"
 #include "makepath.h"
 #include "strlcpy.h"
+#include "strsep.h"
 
 /* These apparently are unsafe without recasting. */
 #define egg_isdigit(x)  isdigit((int)  (unsigned char) (x))

+ 1 - 0
src/compat/strlcpy.c

@@ -4,6 +4,7 @@
 #include <string.h>
 #include <sys/types.h>
 
+#include "strlcpy.h"
 
 /*
  * Copy src to string dst of size siz.  At most siz-1 characters

+ 1 - 0
src/compat/strlcpy.h

@@ -4,6 +4,7 @@
 #include <sys/types.h>
 
 #undef strlcpy
+#undef strlcat
 
 size_t strlcpy(char *, const char *, size_t);
 size_t strlcat(char *, const char *, size_t);

+ 47 - 0
src/compat/strsep.c

@@ -0,0 +1,47 @@
+/* 
+ */
+#include <string.h>
+#include <stdio.h>
+#include "strsep.h"
+
+/*
+ * Get next token from string *stringp, where tokens are possibly-empty
+ * strings separated by characters from delim.
+ *
+ * Writes NULs into the string at *stringp to end tokens.
+ * delim need not remain constant from call to call.
+ * On return, *stringp points past the last NUL written (if there might
+ * be further tokens), or is NULL (if there are definitely no more tokens).
+ *
+ * If *stringp is NULL, strsep returns NULL.
+ */
+char *
+strsep (char **stringp, const char *delim)
+{
+  char *s;
+  const char *spanp;
+  int c, sc;
+  char *tok;
+
+  if ((s = *stringp) == NULL)
+    return (NULL);
+  for (tok = s;;)
+    {
+      c = *s++;
+      spanp = delim;
+      do
+	{
+	  if ((sc = *spanp++) == c)
+	    {
+	      if (c == 0)
+		s = NULL;
+	      else
+		s[-1] = 0;
+	      *stringp = s;
+	      return (tok);
+	    }
+	}
+      while (sc != 0);
+    }
+  /* NOTREACHED */
+}

+ 9 - 0
src/compat/strsep.h

@@ -0,0 +1,9 @@
+#ifndef _STRSEP_H
+#define _STRSEP_H
+
+#undef strsep
+
+char *strsep(char **, const char *);
+
+#endif /* !_STRSEP_H */
+