Re: [ccache] Suggested patch to add local strtok_r for systems lacking it

2012-05-13 Thread Joel Rosdahl
Hi,

On 12 April 2012 08:32, Jürgen Buchmüller pullm...@t-online.de wrote:
 here's a suggested patch for config.h.in and util.c to add a local
 implementation of strtok_r for systems that don't have it (e.g. mingw32
 plus libgw32c).

A lot of Windows build related work has already been done in the
development version (i.e., on the master branch), including a strtok_r
implementation. It would be great if you could try it out:
http://ccache.samba.org/repo.html

-- Joel
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


[ccache] Suggested patch to add local strtok_r for systems lacking it

2012-04-12 Thread Jürgen Buchmüller
Hi list,

here's a suggested patch for config.h.in and util.c to add a local
implementation of strtok_r for systems that don't have it (e.g. mingw32
plus libgw32c).

Cheers
Juergen

diff -rub ccache-3.1.7.orig/ccache.h ccache-3.1.7/ccache.h
--- ccache-3.1.7.orig/ccache.h	Sun Jan  8 14:40:55 2012
+++ ccache-3.1.7/ccache.h	Thu Apr 12 06:21:36 2012
@@ -97,7 +97,9 @@
 
 /* - */
 /* util.c */
-
+#ifndef	HAVE_STRTOK_R
+char* strtok_r(char *src, const char* delim, char** last);
+#endif
 void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 void cc_log_argv(const char *prefix, char **argv);
 void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
diff -rub ccache-3.1.7.orig/config.h.in ccache-3.1.7/config.h.in
--- ccache-3.1.7.orig/config.h.in	Sun Jan  8 14:40:55 2012
+++ ccache-3.1.7/config.h.in	Thu Apr 12 06:22:17 2012
@@ -64,6 +64,9 @@
 /* Define to 1 if you have a C99 compliant `snprintf' function. */
 #undef HAVE_SNPRINTF
 
+/* Define to 1 if you have a C99 compliant `strtok_r' function. */
+#undef HAVE_STRTOK_R
+
 /* Define to 1 if you have the stdarg.h header file. */
 #undef HAVE_STDARG_H
 
diff -rub ccache-3.1.7.orig/util.c ccache-3.1.7/util.c
--- ccache-3.1.7.orig/util.c	Sun Jan  8 14:40:55 2012
+++ ccache-3.1.7/util.c	Thu Apr 12 06:20:23 2012
@@ -33,6 +33,53 @@
 #include sys/locking.h
 #endif
 
+#ifdef _WIN32
+char * strtok_r(char *s, const char *delim, char **last)
+{
+	char *spanp, *tok;
+	int c, sc;
+
+	if (s == NULL  (s = *last) == NULL)
+		return (NULL);
+
+	/*
+	 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
+	 */
+cont:
+	c = *s++;
+	for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
+		if (c == sc)
+			goto cont;
+	}
+
+	if (c == 0) {		/* no non-delimiter characters */
+		*last = NULL;
+		return (NULL);
+	}
+	tok = s - 1;
+
+	/*
+	 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
+	 * Note that delim must have one NUL; we stop if we see that, too.
+	 */
+	for (;;) {
+		c = *s++;
+		spanp = (char *)delim;
+		do {
+			if ((sc = *spanp++) == c) {
+if (c == 0)
+	s = NULL;
+else
+	s[-1] = '\0';
+*last = s;
+return (tok);
+			}
+		} while (sc != 0);
+	}
+	/* NOTREACHED */
+}
+#endif
+
 static FILE *logfile;
 
 static bool
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] Suggested patch to add local strtok_r for systems lacking it

2012-04-12 Thread Martin Pool
Thanks for the patch.

I guess the definition ought to be guarded by HAVE_STRTOK_R, not _WIN32.

Perhaps you also need to update configure.in to check for it?

m
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] Suggested patch to add local strtok_r for systems lacking it

2012-04-12 Thread Jürgen Buchmüller
Am Donnerstag, den 12.04.2012, 18:54 +1000 schrieb Martin Pool:
 Thanks for the patch.
 
 I guess the definition ought to be guarded by HAVE_STRTOK_R, not _WIN32.

Of course! I should have looked through it once more before submission.

 Perhaps you also need to update configure.in to check for it?

I thought that config.h.in standard defines, i.e. defines for well known
function names, would be handled automagically by the autotools and it
would suffice to just add the #define. I'll take a closer look now.

In any case, I realized there actually _is_ a strtok_r implementation in
libgw32c - of course! It's just that it was hidden behind a __USE_GNU
ifdef, so I have to specify -D_GNU_SOURCE to enable its visibility.

What I'm trying to achieve is to build ccache-3.1.7 on mingw32 together
with the glibc substitute gw32c. The readily available ccache-win32,
which most people use, is based on ccache-2.4 and a little hackish for
my taste.

Currently I'm running into some brick walls because I must undefine
_WIN32 to avoid conflicts between win32 and glibc for various types and
macros. I will report should I succeed, since I suspect many people will
be interested in a more recent ccache for mingw32.

Regards
Juergen

___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] Suggested patch to add local strtok_r for systems lacking it

2012-04-12 Thread Mike Frysinger
On Thursday 12 April 2012 02:32:39 Jürgen Buchmüller wrote:
 here's a suggested patch for config.h.in and util.c to add a local
 implementation of strtok_r for systems that don't have it (e.g. mingw32
 plus libgw32c).

sounds like we should just integrate gnulib instead of open coding all of our 
own compatibility layers
-mike


signature.asc
Description: This is a digitally signed message part.
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache