summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2012-03-30 21:20:06 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2012-03-30 21:20:06 +0000
commit21db76e61c63f258332398ce4ca93ead4fcbbfc5 (patch)
tree59b33d895a6b4fecb7230a341f0c9eb8d8ad2c70 /bindings
parent18ccb09846de4137a94d7a0287aef0751bf51e65 (diff)
downloadlibdom-21db76e61c63f258332398ce4ca93ead4fcbbfc5.tar.gz
libdom-21db76e61c63f258332398ce4ca93ead4fcbbfc5.tar.bz2
Replace strndup with our own implementation
svn path=/trunk/libdom/; revision=13780
Diffstat (limited to 'bindings')
-rw-r--r--bindings/hubbub/parser.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 65c3449..2703247 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -334,6 +334,23 @@ static hubbub_error create_comment(void *parser, const hubbub_string *data,
return HUBBUB_OK;
}
+static char *parser_strndup(const char *s, size_t n)
+{
+ size_t len;
+ char *s2;
+
+ for (len = 0; len != n && s[len] != '\0'; len++)
+ continue;
+
+ s2 = malloc(len + 1);
+ if (s2 == NULL)
+ return NULL;
+
+ memcpy(s2, s, len);
+ s2[len] = '\0';
+ return s2;
+}
+
static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
void **result)
{
@@ -344,7 +361,7 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
*result = NULL;
- qname = strndup((const char *) doctype->name.ptr,
+ qname = parser_strndup((const char *) doctype->name.ptr,
(size_t) doctype->name.len);
if (qname == NULL) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
@@ -353,7 +370,8 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
}
if (doctype->public_missing == false) {
- public_id = strndup((const char *) doctype->public_id.ptr,
+ public_id = parser_strndup(
+ (const char *) doctype->public_id.ptr,
(size_t) doctype->public_id.len);
} else {
public_id = strdup("");
@@ -365,7 +383,8 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype,
}
if (doctype->system_missing == false) {
- system_id = strndup((const char *) doctype->system_id.ptr,
+ system_id = parser_strndup(
+ (const char *) doctype->system_id.ptr,
(size_t) doctype->system_id.len);
} else {
system_id = strdup("");