]> arthur.barton.de Git - netatalk.git/commitdiff
Add utility function strtok_quote()
authorRalph Boehme <sloowfranklin@gmail.com>
Thu, 6 Dec 2012 09:56:33 +0000 (10:56 +0100)
committerRalph Boehme <sloowfranklin@gmail.com>
Thu, 6 Dec 2012 09:56:33 +0000 (10:56 +0100)
include/atalk/util.h
libatalk/util/unix.c

index ad2709a4613660c7553d899fe4e542f3f6e63e5a..30aba48149428d6254cd25e406850a574cde7c17 100644 (file)
@@ -184,6 +184,7 @@ extern int daemonize(int nochdir, int noclose);
 extern int run_cmd(const char *cmd, char **cmd_argv);
 extern char *realpath_safe(const char *path);
 extern const char *basename_safe(const char *path);
+extern char *strtok_quote (char *s, const char *delim);
 
 /******************************************************************
  * cnid.c
index 6dce0857744151ef4ba9189989712ae9ade92883..bde1a7ca28f35be34ac8a3aa09e90bdfafab9532 100644 (file)
@@ -386,3 +386,41 @@ const char *basename_safe(const char *path)
     strlcpy(buf, path, MAXPATHLEN);
     return basename(buf);
 }
+
+/**
+ * extended strtok allows the quoted strings
+ * modified strtok.c in glibc 2.0.6
+ **/
+char *strtok_quote(char *s, const char *delim)
+{
+    static char *olds = NULL;
+    char *token;
+
+    if (s == NULL)
+        s = olds;
+
+    /* Scan leading delimiters.  */
+    s += strspn (s, delim);
+    if (*s == '\0')
+        return NULL;
+
+    /* Find the end of the token.  */
+    token = s;
+
+    if (token[0] == '\"') {
+        token++;
+        s = strpbrk (token, "\"");
+    } else {
+        s = strpbrk (token, delim);
+    }
+
+    if (s == NULL) {
+        /* This token finishes the string.  */
+        olds = strchr (token, '\0');
+    } else {
+        /* Terminate the token and make OLDS point past it.  */
+        *s = '\0';
+        olds = s + 1;
+    }
+    return token;
+}