fix for strtok_r

This commit is contained in:
John Jones 2017-03-21 13:40:46 -05:00
parent 25a2fa0c65
commit 640e4be5be
6 changed files with 7 additions and 58 deletions

View file

@ -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);

View file

@ -29,8 +29,7 @@ OBJS = main.o \
../unixfs/unixfs.o \ ../unixfs/unixfs.o \
../../c-protobuf/protobuf.o ../../c-protobuf/varint.o \ ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o \
../util/errs.o \ ../util/errs.o \
../util/time.o \ ../util/time.o
../util/string_tokenizer.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View file

@ -13,8 +13,8 @@
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/merkledag/node.h" #include "ipfs/merkledag/node.h"
#include "ipfs/unixfs/unixfs.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) // 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 }; 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; int num = 0;
char * tr; char * tr;
char * end; char * end;
tr=ipfs_utils_strtok_r(input,"/",&end); tr=strtok_r(input,"/",&end);
for(int i = 0;tr;i++) for(int i = 0;tr;i++)
{ {
tr=ipfs_utils_strtok_r(NULL,"/",&end); tr=strtok_r(NULL,"/",&end);
num++; num++;
} }
return num; return num;
@ -719,12 +719,12 @@ int Node_Resolve(char ** result, char * input1)
strcpy(input, input1); strcpy(input, input1);
char * tr; char * tr;
char * end; char * end;
tr=ipfs_utils_strtok_r(input,"/",&end); tr=strtok_r(input,"/",&end);
for(int i = 0;tr;i++) for(int i = 0;tr;i++)
{ {
result[i] = (char *) malloc(strlen(tr)+1); result[i] = (char *) malloc(strlen(tr)+1);
strcpy(result[i], tr); strcpy(result[i], tr);
tr=ipfs_utils_strtok_r(NULL,"/",&end); tr=strtok_r(NULL,"/",&end);
} }
return 1; return 1;
} }

View file

@ -28,7 +28,6 @@ OBJS = testit.o test_helper.o \
../routing/supernode.o \ ../routing/supernode.o \
../thirdparty/ipfsaddr/ipfs_addr.o \ ../thirdparty/ipfsaddr/ipfs_addr.o \
../unixfs/unixfs.o \ ../unixfs/unixfs.o \
../util/string_tokenizer.o \
../../c-protobuf/protobuf.o ../../c-protobuf/varint.o ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)

View file

@ -7,7 +7,7 @@ endif
LFLAGS = LFLAGS =
DEPS = DEPS =
OBJS = errs.o time.o string_tokenizer.o OBJS = errs.o time.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View file

@ -1,39 +0,0 @@
#include <stdlib.h>
#include <string.h>
/**
* 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;
}