diff --git a/Makefile b/Makefile index f34af02..3464338 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ LFLAGS = -lm DEPS = include/multiaddr/base58.h include/multiaddr/endian.h include/multiaddr/multiaddr.h \ include/multiaddr/protocols.h include/multiaddr/protoutils.h include/multiaddr/varhexutils.h \ include/multiaddr/varint.h -OBJS = base58.o varint.o varhexutils.o protoutils.o protocols.o multiaddr.o +OBJS = base58.o varint.o varhexutils.o protoutils.o protocols.o multiaddr.o string_tokenizer.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/include/multiaddr/string_tokenizer.h b/include/multiaddr/string_tokenizer.h new file mode 100644 index 0000000..893a32e --- /dev/null +++ b/include/multiaddr/string_tokenizer.h @@ -0,0 +1,10 @@ +#pragma once + +/** + * A replacement strtok_r so we can compile with c99 + * @param str the original string + * @param delim the delimiters + * @param nextp used internally to save state + * @returns a pointer to the next element + */ +char* ma_utils_strtok_r(char *str, const char *delim, char **nextp); diff --git a/protocols.c b/protocols.c index 627a7a8..e38c1e7 100644 --- a/protocols.c +++ b/protocols.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/protoutils.c b/protoutils.c index 52f1751..6dc8b38 100644 --- a/protoutils.c +++ b/protoutils.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -8,6 +9,7 @@ #include "multiaddr/varhexutils.h" #include "multiaddr/protocols.h" #include "multiaddr/protoutils.h" +#include "multiaddr/string_tokenizer.h" ////////////////////////////////////////////////////////// char ASCII2bits(char ch) { @@ -681,7 +683,7 @@ int string_to_bytes(uint8_t** finalbytes, size_t* realbbsize, const char* strx, //Starting to extract words and process them: char * wp; char * end; - wp=strtok_r(pstring,"/",&end); + wp=ma_utils_strtok_r(pstring,"/",&end); struct Protocol * protx; while(wp) { @@ -717,7 +719,7 @@ int string_to_bytes(uint8_t** finalbytes, size_t* realbbsize, const char* strx, protx=NULL;//Since right now it doesn't need that assignment anymore. firstorsecond=1;//Since the next word will be an protocol } - wp=strtok_r(NULL,"/",&end); + wp=ma_utils_strtok_r(NULL,"/",&end); } protx=NULL; unload_protocols(head); diff --git a/string_tokenizer.c b/string_tokenizer.c new file mode 100644 index 0000000..9129bdb --- /dev/null +++ b/string_tokenizer.c @@ -0,0 +1,39 @@ +#include +#include + +/** + * A replacement strtok_r so we can compile with c99 + * @param str the original string + * @param delim the delimiters + * @param nextp used internally to save state + * @returns a pointer to the next element + */ +char* ma_utils_strtok_r(char *str, const char *delim, char **nextp) +{ + char *ret; + + if (str == NULL) + { + str = *nextp; + } + + str += strspn(str, delim); + + if (*str == '\0') + { + return NULL; + } + + ret = str; + + str += strcspn(str, delim); + + if (*str) + { + *str++ = '\0'; + } + + *nextp = str; + + return ret; +} diff --git a/varhexutils.c b/varhexutils.c index b6c247a..2365658 100644 --- a/varhexutils.c +++ b/varhexutils.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "multiaddr/varint.h"