picoc
picoc copied to clipboard
Windows build
The version in the repository won't build on Windows. When I built it a few days ago I had to add
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
I simply added this to platform.h.
Also, strdup () is not available in the Windows build by default. I added
#define strdup _strdup
for this. Then I changed the position of the #ifndef WIN32 within string.c.
Beginning of platform.h:
/* all platform-specific includes and defines go in this file */
#ifndef PLATFORM_H
#define PLATFORM_H
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <setjmp.h>
#include <math.h>
#include <stdbool.h>
/* host platform includes */
#ifdef UNIX_HOST
# include <stdint.h>
# include <unistd.h>
#elif defined(WIN32) /*(predefined on MSVC)*/
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define strdup _strdup
#else
# error ***** A platform must be explicitly defined! *****
#endif
Around line 170 within cstdlib/string.h:
void StringStrxfrm(struct ParseState *Parser, struct Value *ReturnValue,
struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = strxfrm(Param[0]->Val->Pointer,
Param[1]->Val->Pointer, Param[2]->Val->Integer);
}
void StringStrdup(struct ParseState *Parser, struct Value *ReturnValue,
struct Value **Param, int NumArgs)
{
ReturnValue->Val->Pointer = (void*)strdup(Param[0]->Val->Pointer);
}
#ifndef WIN32
void StringStrtok_r(struct ParseState *Parser, struct Value *ReturnValue,
struct Value **Param, int NumArgs)
{
ReturnValue->Val->Pointer = (void*)strtok_r(Param[0]->Val->Pointer,
Param[1]->Val->Pointer, Param[2]->Val->Pointer);
}
#endif
And a bit further down in string.c:
/* all string.h functions */
struct LibraryFunction StringFunctions[] =
{
#ifndef WIN32
{StringIndex, "char *index(char *,int);"},
{StringRindex, "char *rindex(char *,int);"},
#endif
{StringMemcpy, "void *memcpy(void *,void *,int);"},
{StringMemmove, "void *memmove(void *,void *,int);"},
{StringMemchr, "void *memchr(char *,int,int);"},
{StringMemcmp, "int memcmp(void *,void *,int);"},
{StringMemset, "void *memset(void *,int,int);"},
{StringStrcat, "char *strcat(char *,char *);"},
{StringStrncat, "char *strncat(char *,char *,int);"},
{StringStrchr, "char *strchr(char *,int);"},
{StringStrrchr, "char *strrchr(char *,int);"},
{StringStrcmp, "int strcmp(char *,char *);"},
{StringStrncmp, "int strncmp(char *,char *,int);"},
{StringStrcoll, "int strcoll(char *,char *);"},
{StringStrcpy, "char *strcpy(char *,char *);"},
{StringStrncpy, "char *strncpy(char *,char *,int);"},
{StringStrerror,"char *strerror(int);"},
{StringStrlen, "int strlen(char *);"},
{StringStrspn, "int strspn(char *,char *);"},
{StringStrcspn, "int strcspn(char *,char *);"},
{StringStrpbrk, "char *strpbrk(char *,char *);"},
{StringStrstr, "char *strstr(char *,char *);"},
{StringStrtok, "char *strtok(char *,char *);"},
{StringStrxfrm, "int strxfrm(char *,char *,int);"},
{StringStrdup, "char *strdup(char *);"},
#ifndef WIN32
{StringStrtok_r,"char *strtok_r(char *,char *,char **);"},
#endif
{NULL, NULL }
};
I thought it might be better if this went directly into the trunk.
I've never used strtok_r () or strtok_s () but from their documentations it seems both functions are identical. http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok_r.html https://msdn.microsoft.com/en-us/library/ftsafwz3.aspx#Return%20Value This would mean the same could (and probably should) be done with strtok_r (). #define strtok_r strtok_s