[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libcdio-devel] [PATCH 1/2] MinGW: detect if strndup is supported and ad
From: |
Pete Batard |
Subject: |
[Libcdio-devel] [PATCH 1/2] MinGW: detect if strndup is supported and add workaround if not |
Date: |
Tue, 17 Jan 2012 01:02:03 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
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 <address@hidden>
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
- [Libcdio-devel] [PATCH 1/2] MinGW: detect if strndup is supported and add workaround if not,
Pete Batard <=