Apparently Windows doesn't have strndup or index.

This commit is contained in:
David Given 2022-07-17 00:47:49 +02:00
parent b40f4e33fb
commit 92b3dfb42c
4 changed files with 26 additions and 1 deletions

View file

@ -15,7 +15,7 @@ bool tracing(char k)
if (!tracechars)
return false;
return index(tracechars, k);
return strchr(tracechars, k);
}
void tracef(char k, const char* fmt, ...)

View file

@ -9,6 +9,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "system.h"
#include "em_arith.h"
#include "em_label.h"
#include "em.h"

View file

@ -0,0 +1,19 @@
#include <stdlib.h>
#include <string.h>
#include "system.h"
#if defined WIN32
/* Really? */
char* strndup(const char* s, size_t n)
{
size_t len = strnlen(s, n);
char* ns = malloc(len + 1);
if (!ns)
return NULL;
ns[len] = '\0';
memcpy(ns, s, len);
return ns;
}
#endif

View file

@ -84,4 +84,9 @@ void sys_basename(const char *str, register char *dst);
* the same semantics as ISO C90 tmpnam() */
char* sys_tmpnam(char *buffer);
#if defined WIN32
/* Really? */
extern char* strndup(const char* s, size_t n);
#endif
#endif /* __SYSTEM_INCLUDED__ */