summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorRodeo <[email protected]>2015-04-10 14:56:27 +0000
committerRodeo <[email protected]>2015-04-10 14:56:27 +0000
commit864ce5a4227d81f688f32e808245b2600f431ac3 (patch)
tree80fe0b03201bac220a3d2c291129381752b888db /libhb
parentf360714523e5f1f78ced2ae8691f3087b80eef65 (diff)
Move strtok_r fallback to dedicated "compat" files.
Also, check whether the toolchain already provides strtok_r instead of building it unconditionally. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7076 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/compat.c42
-rw-r--r--libhb/compat.h28
-rw-r--r--libhb/hb.h1
-rw-r--r--libhb/module.defs4
-rw-r--r--libhb/ports.c27
-rw-r--r--libhb/ports.h11
6 files changed, 75 insertions, 38 deletions
diff --git a/libhb/compat.c b/libhb/compat.c
new file mode 100644
index 000000000..440074bc2
--- /dev/null
+++ b/libhb/compat.c
@@ -0,0 +1,42 @@
+/* compat.c
+
+ Copyright (c) 2003-2015 HandBrake Team
+ This file is part of the HandBrake source code
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License v2.
+ For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
+ */
+
+#include "compat.h"
+
+#ifdef HB_NEED_STRTOK_R
+#include <string.h>
+
+char *strtok_r(char *s, const char *delim, char **save_ptr)
+{
+ char *token;
+
+ if (s == NULL) s = *save_ptr;
+
+ /* Scan leading delimiters. */
+ s += strspn(s, delim);
+ if (*s == '\0') return NULL;
+
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk(token, delim);
+ if (s == NULL)
+ {
+ /* This token finishes the string. */
+ *save_ptr = strchr(token, '\0');
+ }
+ else
+ {
+ /* Terminate the token and make *save_ptr point past it. */
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+
+ return token;
+}
+#endif // HB_NEED_STRTOK_R
diff --git a/libhb/compat.h b/libhb/compat.h
new file mode 100644
index 000000000..40283c907
--- /dev/null
+++ b/libhb/compat.h
@@ -0,0 +1,28 @@
+/* compat.h
+
+ Copyright (c) 2003-2015 HandBrake Team
+ This file is part of the HandBrake source code
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License v2.
+ For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
+ */
+
+#ifndef HB_COMPAT_H
+#define HB_COMPAT_H
+
+#ifdef HB_NEED_STRTOK_R
+/*
+ * Some MinGW-w64 distributions #define strtok_r in pthread.h,
+ * however their so-called "implementation" isn't thread-safe.
+ */
+#ifdef USE_PTHREAD
+#include <pthread.h>
+#ifdef strtok_r
+#undef strtok_r
+#endif // strtok_r
+#endif // USE_PTHREAD
+
+char *strtok_r(char *s, const char *delim, char **save_ptr);
+#endif // HB_NEED_STRTOK_R
+
+#endif // HB_COMPAT_H
diff --git a/libhb/hb.h b/libhb/hb.h
index 2da5e81c0..38418ac3b 100644
--- a/libhb/hb.h
+++ b/libhb/hb.h
@@ -16,6 +16,7 @@ extern "C" {
#include "project.h"
#include "common.h"
+#include "compat.h"
#include "hb_dict.h"
#include "hb_json.h"
#include "param.h"
diff --git a/libhb/module.defs b/libhb/module.defs
index 11b8a22c6..79222a2fa 100644
--- a/libhb/module.defs
+++ b/libhb/module.defs
@@ -72,6 +72,10 @@ ifeq (1,$(FEATURE.x265))
LIBHB.GCC.D += USE_X265
endif
+ifeq (1,$(COMPAT.strtok_r))
+ LIBHB.GCC.D += HB_NEED_STRTOK_R
+endif
+
## required for <libdvdread/*.h>
ifneq (,$(filter $(BUILD.arch),ppc ppc64))
LIBHB.GCC.D += WORDS_BIGENDIAN
diff --git a/libhb/ports.c b/libhb/ports.c
index 4e542b202..048f478cf 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -1147,33 +1147,6 @@ void hb_net_close( hb_net_t ** _n )
*_n = NULL;
}
-#ifdef SYS_MINGW
-char *strtok_r(char *s, const char *delim, char **save_ptr)
-{
- char *token;
-
- if (s == NULL) s = *save_ptr;
-
- /* Scan leading delimiters. */
- s += strspn(s, delim);
- if (*s == '\0') return NULL;
-
- /* Find the end of the token. */
- token = s;
- s = strpbrk(token, delim);
- if (s == NULL)
- /* This token finishes the string. */
- *save_ptr = strchr(token, '\0');
- else {
- /* Terminate the token and make *SAVE_PTR point past it. */
- *s = '\0';
- *save_ptr = s + 1;
- }
-
- return token;
-}
-#endif
-
/************************************************************************
* OS Sleep Allow / Prevent
***********************************************************************/
diff --git a/libhb/ports.h b/libhb/ports.h
index 7dde23028..649d3995f 100644
--- a/libhb/ports.h
+++ b/libhb/ports.h
@@ -57,17 +57,6 @@ void hb_snooze( int delay );
int hb_platform_init();
#ifdef SYS_MINGW
-/*
- * Some MinGW distributions #define strtok_r in pthread.h,
- * but their so-called "implementation" isn't thread-safe.
- */
-#ifdef strtok_r
-#undef strtok_r
-#endif
-char *strtok_r(char *s, const char *delim, char **save_ptr);
-#endif
-
-#ifdef SYS_MINGW
typedef struct
{
_WDIR *wdir;