Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows build #23

Open
ThomasPGH opened this issue Jan 18, 2018 · 1 comment
Open

Windows build #23

ThomasPGH opened this issue Jan 18, 2018 · 1 comment

Comments

@ThomasPGH
Copy link

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.

@ThomasPGH
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant