summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-01-07 12:34:29 -0700
committerJohn Stebbins <[email protected]>2019-01-14 13:36:08 -0800
commitef6777ea094ed5a2f830136e1ec7b4220d421f97 (patch)
treeff3a3d08b9379e8327bbb85b638009355e6feef6
parent5154729becab0465462027d93d9293fb3ddca49c (diff)
ssautil: fix strndup on mingw
-rw-r--r--libhb/ports.c30
-rw-r--r--libhb/ports.h5
-rw-r--r--libhb/ssautil.c6
3 files changed, 38 insertions, 3 deletions
diff --git a/libhb/ports.c b/libhb/ports.c
index da48d5d81..6773f2905 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -1475,3 +1475,33 @@ size_t hb_getline(char ** lineptr, size_t * n, FILE * fp)
return getline(lineptr, n, fp);
#endif
}
+
+char * hb_strndup(const char * src, size_t len)
+{
+#ifdef SYS_MINGW
+ char * result, * end;
+
+ if (src == NULL)
+ {
+ return NULL;
+ }
+
+ end = memchr(src, 0, len);
+ if (end != NULL)
+ {
+ len = end - src;
+ }
+
+ result = malloc(len + 1);
+ if (result == NULL)
+ {
+ return NULL;
+ }
+ memcpy(result, src, len);
+ result[len] = 0;
+
+ return result;
+#else
+ return strndup(src, len);
+#endif
+}
diff --git a/libhb/ports.h b/libhb/ports.h
index f6c89b37d..6a6c3c755 100644
--- a/libhb/ports.h
+++ b/libhb/ports.h
@@ -84,6 +84,11 @@ FILE * hb_fopen(const char *path, const char *mode);
char * hb_strr_dir_sep(const char *path);
/************************************************************************
+ * String utils
+ ***********************************************************************/
+char * hb_strndup(const char * src, size_t len);
+
+/************************************************************************
* File utils
***********************************************************************/
char * hb_get_temporary_directory(void);
diff --git a/libhb/ssautil.c b/libhb/ssautil.c
index 96ab11bb2..108b46f89 100644
--- a/libhb/ssautil.c
+++ b/libhb/ssautil.c
@@ -147,7 +147,7 @@ static int ssa_update_style(const char *ssa, hb_subtitle_style_context_t *ctx)
if (ssa[pos] == 'r')
{
// Style reset
- char * style = strndup(ssa + pos + 1, end - (pos + 1));
+ char * style = hb_strndup(ssa + pos + 1, end - (pos + 1));
ssa_style_set(ctx, style);
free(style);
}
@@ -284,7 +284,7 @@ static char * get_field(char ** pos)
char * end = strchr(start, ',');
if (end != NULL)
{
- result = strndup(start, end - start);
+ result = hb_strndup(start, end - start);
*pos = end + 1;
}
else
@@ -315,7 +315,7 @@ static char * sgetline(char * str)
}
if (eol != NULL)
{
- return strndup(str, eol - str);
+ return hb_strndup(str, eol - str);
}
else
{