From 640e4be5be23bf7579cd613999d6bfc95e9ca366 Mon Sep 17 00:00:00 2001 From: John Jones Date: Tue, 21 Mar 2017 13:40:46 -0500 Subject: [PATCH] fix for strtok_r --- include/ipfs/util/string_tokenizer.h | 10 ------- main/Makefile | 3 +-- merkledag/node.c | 10 +++---- test/Makefile | 1 - util/Makefile | 2 +- util/string_tokenizer.c | 39 ---------------------------- 6 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 include/ipfs/util/string_tokenizer.h delete mode 100644 util/string_tokenizer.c diff --git a/include/ipfs/util/string_tokenizer.h b/include/ipfs/util/string_tokenizer.h deleted file mode 100644 index 95e490b..0000000 --- a/include/ipfs/util/string_tokenizer.h +++ /dev/null @@ -1,10 +0,0 @@ -#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* ipfs_utils_strtok_r(char *str, const char *delim, char **nextp); diff --git a/main/Makefile b/main/Makefile index f3ee38a..8bb9111 100644 --- a/main/Makefile +++ b/main/Makefile @@ -29,8 +29,7 @@ OBJS = main.o \ ../unixfs/unixfs.o \ ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o \ ../util/errs.o \ - ../util/time.o \ - ../util/string_tokenizer.o + ../util/time.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/merkledag/node.c b/merkledag/node.c index 6e7d1a2..b85c794 100644 --- a/merkledag/node.c +++ b/merkledag/node.c @@ -13,8 +13,8 @@ #include "ipfs/cid/cid.h" #include "ipfs/merkledag/node.h" #include "ipfs/unixfs/unixfs.h" -#include "ipfs/util/string_tokenizer.h" +extern char *strtok_r(char *, const char *, char **); // for protobuf Node (all fields optional) data (optional bytes) links (repeated node_link) enum WireType ipfs_node_message_fields[] = { WIRETYPE_LENGTH_DELIMITED, WIRETYPE_LENGTH_DELIMITED }; @@ -692,10 +692,10 @@ int Node_Resolve_Max_Size(char * input1) int num = 0; char * tr; char * end; - tr=ipfs_utils_strtok_r(input,"/",&end); + tr=strtok_r(input,"/",&end); for(int i = 0;tr;i++) { - tr=ipfs_utils_strtok_r(NULL,"/",&end); + tr=strtok_r(NULL,"/",&end); num++; } return num; @@ -719,12 +719,12 @@ int Node_Resolve(char ** result, char * input1) strcpy(input, input1); char * tr; char * end; - tr=ipfs_utils_strtok_r(input,"/",&end); + tr=strtok_r(input,"/",&end); for(int i = 0;tr;i++) { result[i] = (char *) malloc(strlen(tr)+1); strcpy(result[i], tr); - tr=ipfs_utils_strtok_r(NULL,"/",&end); + tr=strtok_r(NULL,"/",&end); } return 1; } diff --git a/test/Makefile b/test/Makefile index 5118ba3..776464a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,7 +28,6 @@ OBJS = testit.o test_helper.o \ ../routing/supernode.o \ ../thirdparty/ipfsaddr/ipfs_addr.o \ ../unixfs/unixfs.o \ - ../util/string_tokenizer.o \ ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o %.o: %.c $(DEPS) diff --git a/util/Makefile b/util/Makefile index a756ff9..559e417 100644 --- a/util/Makefile +++ b/util/Makefile @@ -7,7 +7,7 @@ endif LFLAGS = DEPS = -OBJS = errs.o time.o string_tokenizer.o +OBJS = errs.o time.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/util/string_tokenizer.c b/util/string_tokenizer.c deleted file mode 100644 index b8a6d0e..0000000 --- a/util/string_tokenizer.c +++ /dev/null @@ -1,39 +0,0 @@ -#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* ipfs_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; -}