diff options
author | Dave Beckett <dave@dajobe.org> | 2017-01-08 19:57:53 -0800 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2017-01-08 19:57:53 -0800 |
commit | 1f37c50e7f145d902ed13b35205fc57aec1f1541 (patch) | |
tree | 86a408a352aef71f6cb5975b9d016a9f4d18bdd8 | |
parent | d27769828520c941cd9d9d91a48bbf1fbe682bb0 (diff) | |
download | raptor-1f37c50e7f145d902ed13b35205fc57aec1f1541.tar.gz |
Get rid of strdup configure code; move to librdfa
Easier to replace strdup() calls in librdfa/ with it's own version
and just alway use it.
Remove strdup checks from configure.ac
(rdfa_strdup): Added.
Updated all callers.
-rw-r--r-- | configure.ac | 13 | ||||
-rw-r--r-- | librdfa/curie.c | 8 | ||||
-rw-r--r-- | librdfa/iri.c | 3 | ||||
-rw-r--r-- | librdfa/lists.c | 4 | ||||
-rw-r--r-- | librdfa/rdfa_utils.c | 23 | ||||
-rw-r--r-- | librdfa/rdfa_utils.h | 1 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/raptor_internal.h | 5 | ||||
-rw-r--r-- | src/strdup.c | 37 |
9 files changed, 28 insertions, 69 deletions
diff --git a/configure.ac b/configure.ac index 5d664b86..95a8bdac 100644 --- a/configure.ac +++ b/configure.ac @@ -424,18 +424,6 @@ AC_SUBST(RAPTOR_LIBTOOL_VERSION) dnl Checks for library functions. AC_CHECK_FUNCS(gettimeofday getopt getopt_long vsnprintf isascii setjmp qsort_r qsort_s stricmp strcasecmp) -AC_MSG_CHECKING(strdup) -have_strdup=no -AC_COMPILE_IFELSE([AC_LANG_SOURCE([ -#ifdef HAVE_STRING_H -#include <string.h> -#endif -int main() { return strdup(); } -])], - [AC_MSG_RESULT(yes) - have_strdup=yes - AC_DEFINE([HAVE_STRDUP], [1], [have the strdup function])], - [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(strtok_r) have_strtok_r=no AC_COMPILE_IFELSE([AC_LANG_SOURCE([ @@ -460,7 +448,6 @@ CPPFLAGS="$oCPPFLAGS" AM_CONDITIONAL(STRCASECMP, test $ac_cv_func_strcasecmp = no -a $ac_cv_func_stricmp = no) -AM_CONDITIONAL(STRDUP, test $have_strdup = no) AM_CONDITIONAL(GETOPT, test $ac_cv_func_getopt = no -a $ac_cv_func_getopt_long = no) diff --git a/librdfa/curie.c b/librdfa/curie.c index cef39d05..704f6b5a 100644 --- a/librdfa/curie.c +++ b/librdfa/curie.c @@ -378,7 +378,7 @@ char* rdfa_resolve_curie( term_iri = (const char*)rdfa_get_mapping(context->term_mappings, uri); if(term_iri != NULL) { - rval = strdup(term_iri); + rval = rdfa_strdup(term_iri); } else if(context->default_vocabulary == NULL && strstr(uri, ":") == NULL) { @@ -605,7 +605,7 @@ char* rdfa_resolve_relrev_curie(rdfacontext* context, const char* uri) { /* search all of the XHTML @rel/@rev reserved words for a * case-insensitive match against the given URI */ - char* term = strdup(resource); + char* term = rdfa_strdup(resource); char* ptr = NULL; for(ptr = term; *ptr; ptr++) @@ -616,7 +616,7 @@ char* rdfa_resolve_relrev_curie(rdfacontext* context, const char* uri) rval = (char*)rdfa_get_mapping(context->term_mappings, term); if(rval != NULL) { - rval = strdup(rval); + rval = rdfa_strdup(rval); } free(term); } @@ -626,7 +626,7 @@ char* rdfa_resolve_relrev_curie(rdfacontext* context, const char* uri) rval = (char*)rdfa_get_mapping(context->term_mappings, resource); if(rval != NULL) { - rval = strdup(rval); + rval = rdfa_strdup(rval); } } diff --git a/librdfa/iri.c b/librdfa/iri.c index 16a919ab..8f72d78a 100644 --- a/librdfa/iri.c +++ b/librdfa/iri.c @@ -28,6 +28,7 @@ #include <string.h> #include "rdfa.h" +#include "rdfa_utils.h" /** * Strips the iquery and ifragment part from an IRI. This leaves just the @@ -57,7 +58,7 @@ char* rdfa_iri_get_base(const char* iri) { /* there was no iquery or ifragment in the input string, so there is * no need to reformat the string */ - rval = strdup(iri); + rval = rdfa_strdup(iri); } else { diff --git a/librdfa/lists.c b/librdfa/lists.c index 4e3205e2..d3999795 100644 --- a/librdfa/lists.c +++ b/librdfa/lists.c @@ -190,7 +190,7 @@ void rdfa_complete_list_triples(rdfacontext* context) } else { - next = strdup((char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"); + next = rdfa_strdup((char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"); } triple = rdfa_create_triple(bnode, @@ -211,7 +211,7 @@ void rdfa_complete_list_triples(rdfacontext* context) * full IRI of the local list mapping associated with this list * object * first item of the 'bnode' array */ - subject = strdup(key); + subject = rdfa_strdup(key); if(subject) tmp = strstr(subject, " "); diff --git a/librdfa/rdfa_utils.c b/librdfa/rdfa_utils.c index a10d7840..cbae71c2 100644 --- a/librdfa/rdfa_utils.c +++ b/librdfa/rdfa_utils.c @@ -67,7 +67,7 @@ char* rdfa_replace_string(char* old_string, const char* new_string) free(old_string); /* copy the new string */ - rval = strdup(new_string); + rval = rdfa_strdup(new_string); } return rval; @@ -161,7 +161,7 @@ rdfalist* rdfa_copy_list(rdfalist* list) /* copy specific data type */ if(list->items[i]->flags & RDFALIST_FLAG_TEXT) { - rval->items[i]->data = strdup((char*)list->items[i]->data); + rval->items[i]->data = rdfa_strdup((char*)list->items[i]->data); } else if(list->items[i]->flags & RDFALIST_FLAG_TRIPLE) { @@ -344,7 +344,7 @@ void rdfa_create_list_mapping( /* build the real key to use when updating the mapping */ str_size = strlen(subject); - realkey = strdup(subject); + realkey = rdfa_strdup(subject); realkey = rdfa_n_append_string(realkey, &str_size, " ", 1); realkey = rdfa_n_append_string(realkey, &str_size, key, strlen(key)); rdfa_update_mapping(mapping, realkey, value, @@ -455,7 +455,7 @@ const void* rdfa_get_list_mapping( size_t str_size = strlen(subject); /* generate the real list mapping key and retrieve it from the mapping */ - realkey = strdup(subject); + realkey = rdfa_strdup(subject); realkey = rdfa_n_append_string(realkey, &str_size, " ", 1); realkey = rdfa_n_append_string(realkey, &str_size, key, strlen(key)); rval = (void*)rdfa_get_mapping(mapping, realkey); @@ -526,3 +526,18 @@ void rdfa_free_mapping(void** mapping, free_mapping_value_fp free_value) } } +char* +rdfa_strdup(const char* s) +{ + size_t len; + char *buf; + + if(!s) + return NULL; + + len = strlen(s) + 1; + buf = malloc(len); + if(buf) + memcpy(buf, s, len); + return buf; +} diff --git a/librdfa/rdfa_utils.h b/librdfa/rdfa_utils.h index df96265d..a21ddfef 100644 --- a/librdfa/rdfa_utils.h +++ b/librdfa/rdfa_utils.h @@ -477,6 +477,7 @@ void rdfa_establish_new_inlist_triples( void rdfa_complete_list_triples(rdfacontext* context); rdfacontext* rdfa_create_new_element_context(rdfalist* context_stack); void rdfa_free_context_stack(rdfacontext* context); +char* rdfa_strdup(const char* s); #ifdef __cplusplus } diff --git a/src/Makefile.am b/src/Makefile.am index 966a64da..3378d104 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,9 +166,6 @@ endif if STRCASECMP libraptor2_la_SOURCES += strcasecmp.c endif -if STRDUP -libraptor2_la_SOURCES += strdup.c -endif if PARSEDATE libraptor2_la_SOURCES += parsedate.c BUILT_SOURCES += parsedate.c diff --git a/src/raptor_internal.h b/src/raptor_internal.h index 4f360763..8a9010b2 100644 --- a/src/raptor_internal.h +++ b/src/raptor_internal.h @@ -768,11 +768,6 @@ int raptor_check_ordinal(const unsigned char *name); #endif #endif -#ifndef HAVE_STRDUP -#define strdup raptor_strdup -char* raptor_strdup(const char* s); -#endif - /* raptor_nfc_icu.c */ int raptor_nfc_icu_check (const unsigned char* string, size_t len, int *error); diff --git a/src/strdup.c b/src/strdup.c deleted file mode 100644 index 22aa451b..00000000 --- a/src/strdup.c +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: c; c-basic-offset: 2 -*- - * - * strdup.c - strdup compatibility - * - * This file is in the public domain. - * - */ - -#ifdef HAVE_CONFIG_H -#include <raptor_config.h> -#endif - -#include <string.h> -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -/* for RAPTOR_MALLOC() */ -#include "raptor2.h" -#include "raptor_internal.h" - - -char* -raptor_strdup(const char* s) -{ - size_t len; - char *buf; - - if(!s) - return NULL; - - len = strlen(s) + 1; - buf = RAPTOR_MALLOC(char*, len); - if(buf) - memcpy(buf, s, len); - return buf; -} |