]> granicus.if.org Git - graphviz/commitdiff
provide replacement for missing strtok_r()
authorJohn Ellson <ellson@research.att.com>
Thu, 16 Aug 2012 12:04:35 +0000 (08:04 -0400)
committerJohn Ellson <ellson@research.att.com>
Thu, 16 Aug 2012 12:04:35 +0000 (08:04 -0400)
configure.ac
lib/common/emit.c

index 3c8a916a87b18a462aee735c1b750dda8631c544..0888a323f0e6b3588839a6bea4e143af189300fc 100644 (file)
@@ -475,7 +475,7 @@ AC_FUNC_ALLOCA
 AC_CHECK_FUNCS([lrand48 drand48 srand48 setmode setenv getenv \
        __freadable _sysconf getrusage strerror cbrt lsqrt vsnprintf \
        strtoul strtoll strtoull uname memset nl_langinfo pow sqrt \
-       strchr strdup strerror strstr _NSGetEnviron])
+       strchr strdup strerror strstr strtok_r _NSGetEnviron])
 
 AC_REPLACE_FUNCS([strcasecmp strncasecmp strcasestr])
 
index 11e2de9f8b343257dea08ca42382e168fce86175..0f84d0182cdc0152bf7c312159b84b355ce14b00 100644 (file)
 #include "gvc.h"
 #include "xdot.h"
 
-#ifdef WIN32
-#define strtok_r strtok_s
-#endif
-
 #define P2RECT(p, pr, sx, sy) (pr[0].x = p.x - sx, pr[0].y = p.y - sy, pr[1].x = p.x + sx, pr[1].y = p.y + sy)
 #define FUZZ 3
 #define EPSILON .0001
 
+// #ifdef WIN32
+// #define strtok_r strtok_s
+// #endif
+
+#ifndef HAVE_STRTOK_R
+/*
+ * From:  http://sourceforge.net/tracker/?func=detail&aid=2673480&group_id=2435&atid=352435
+ *
+ * NB this implementation uses strok(), so will corrupt any existing strok() state.
+ */
+char *strtok_r(char *str, const char *delim, char **save)
+{
+    char *res, *last;
+
+    if( !save )
+        return strtok(str, delim);
+    if( !str && !(str = *save) )
+        return NULL;
+    last = str + strlen(str);
+    if( (*save = res = strtok(str, delim)) )
+    {
+        *save += strlen(res);
+        if( *save < last )
+            (*save)++;
+        else
+            *save = NULL;
+    }
+    return res;
+}
+#endif
+
 typedef struct {
     xdot_op op;
     boxf bb;