fix for strtok_r

yamux
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 \
../../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)

View File

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

View File

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

View File

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

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;
}