diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2013-05-20 19:30:04 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2013-05-20 19:30:04 +0200 |
commit | 3003c3ab6912570f3ee01a99971bd82f31180627 (patch) | |
tree | 50afca5b9c8dbd4e94acc645ba04b0599da1ed26 | |
parent | ed133b0000e8b8cdabf038bf40e457fac2cc428c (diff) |
add compat files to make compile with older compilers, mostly for mingw and dos, ugly
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
-rw-r--r-- | compat.c | 41 | ||||
-rw-r--r-- | compat.h | 17 |
2 files changed, 58 insertions, 0 deletions
diff --git a/compat.c b/compat.c new file mode 100644 index 0000000..1530bd5 --- /dev/null +++ b/compat.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <sys/stat.h> +#include <sys/types.h> + +int +xstrcasecmp(const char *_l, const char *_r) { + const unsigned char *l = (void *)_l, *r = (void *)_r; + for(; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++); + return tolower(*l) - tolower(*r); +} + +int +xstrncasecmp(const char *_l, const char *_r, size_t n) { + const unsigned char *l=(void *)_l, *r=(void *)_r; + if(!n--) + return 0; + for(; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--); + return tolower(*l) - tolower(*r); +} + +void * +xstrdup(const char *s) { + size_t len = strlen(s) + 1; + void *p = malloc(len); + if(p) + memcpy(p, s, len); + return p; +} + +int +xmkdir(const char *path, mode_t mode) { +/* TODO: fix for mingw */ +#if MINGW + return mkdir(path); +#else + return mkdir(path, mode); +#endif +} diff --git a/compat.h b/compat.h new file mode 100644 index 0000000..c17c8fb --- /dev/null +++ b/compat.h @@ -0,0 +1,17 @@ +#if 1 +#include <strings.h> +#include <string.h> +#define xstrcasecmp strcasecmp +#define xstrncasecmp strncasecmp +#else +int xstrcasecmp(const char *s1, const char *s2); +int xstrncasecmp(const char *s1, const char *s2, size_t len); +#endif + +/* non-ansi */ +void * xstrdup(const char *s); + +/* for mingw */ +#include <sys/stat.h> +#include <sys/types.h> +int xmkdir(const char *path, mode_t mode); |