Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't use strndup for portability

Mac OS X does not include strndup on versions earlier than 10.7.
  • Loading branch information...
commit 8dc9419e7bce5d425514563809d645f10ce3ebb5 1 parent 893588f
@b4winckler authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/lxbread.c
View
14 src/lxbread.c
@@ -120,14 +120,24 @@ bool parse_header(const char *data, long size, fcs_header *hdr)
return ok;
}
+char *dup2str(const void *buf, long size)
+{
+ char *str = (char *)malloc(size + 1);
+ if (!str)
+ return NULL;
+
+ str[size] = 0;
+ return memcpy(str, buf, size);
+}
+
map_t parse_text(const char *text, long size)
{
if (size < 2)
return NULL;
map_t m = map_create();
- char *sep = strndup(text, 1);
- char *data = strndup(text+1, size-1);
+ char *sep = dup2str(text, 1);
+ char *data = dup2str(text+1, size-1);
char *p = data;
for (;;) {
Please sign in to comment.
Something went wrong with that request. Please try again.