WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

 « Return to Thread: [PATCH 1/2] MinGW: detect if strndup is supported and add workaround if not

[PATCH 1/2] MinGW: detect if strndup is supported and add workaround if not

by Pete Batard :: Rate this Message:

| View in Thread

Couple more patches, since I'm using MinGW.

For what is worth, not much is needed to get MinGW compiling and running
the samples, at least if all you are interested in is ISO/UDF image
handling.

Currently, abs_path.c fails to compile because MinGW lacks strndup().
abs_path.c seems to be the only place that uses it as far as I could
see, but rather than override strndup always, I added some detection of
it to configure.ac, so as not to impact other platforms.

With this, MinGW compilation completes successfully.

Regards,

/Pete


From d20dcbe4637c4bd8de0feba5564d2e2612963a20 Mon Sep 17 00:00:00 2001
From: Pete Batard <pete@...>
Date: Mon, 16 Jan 2012 19:46:06 +0000
Subject: [PATCH 1/2] MinGW: detect if strndup is supported and add workaround
 if not

---
 configure.ac          |    4 ++--
 lib/driver/abs_path.c |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index fbf6e65..47e540c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -499,8 +499,8 @@ AC_DEFINE_UNQUOTED(LIBCDIO_SOURCE_PATH, "$LIBCDIO_SOURCE_PATH",
 AC_SUBST(LIBCDIO_SOURCE_PATH)
 
 AC_CHECK_FUNCS( [bzero chdir drand48 ftruncate geteuid getgid \
- getuid getpwuid gettimeofday lstat memcpy memset \
- rand seteuid setegid snprintf setenv unsetenv tzset \
+ getuid getpwuid gettimeofday lstat memcpy memset rand \
+ seteuid setegid snprintf setenv strndup unsetenv tzset \
  sleep usleep vsnprintf readlink realpath gmtime_r localtime_r] )
 
 # check for timegm() support
diff --git a/lib/driver/abs_path.c b/lib/driver/abs_path.c
index 4588e93..9b01489 100644
--- a/lib/driver/abs_path.c
+++ b/lib/driver/abs_path.c
@@ -59,6 +59,21 @@
 # define CharNext(p) ((p) + 1)
 #endif
 
+#ifndef HAVE_STRNDUP
+static inline char *strndup(const char *s, size_t n)
+{
+    char *result;
+    size_t len = strlen (s);
+    if (n < len)
+        len = n;
+    result = (char *) malloc (len + 1);
+    if (!result)
+        return 0;
+    result[len] = '\0';
+    return (char *) strncpy (result, s, len);
+}
+#endif /*HAVE_STRNDUP*/
+
 static char *
 strrdirsep(const char *path)
 {
--
1.7.8.msysgit.0

 « Return to Thread: [PATCH 1/2] MinGW: detect if strndup is supported and add workaround if not