diff --git a/configure.ac b/configure.ac index 1900848..a5d90d8 100644 --- a/configure.ac +++ b/configure.ac @@ -88,7 +88,7 @@ AC_ARG_ENABLE(zzuf, [ --enable-zzuf use zzuf for fuzzing tests (autodetected)]) AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h dlfcn.h termios.h) -AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) +AC_CHECK_FUNCS(signal ioctl snprintf vsnprintf getenv putenv strcasecmp htons) AC_CHECK_FUNCS(usleep gettimeofday) AC_CHECK_FUNCS(getopt_long, diff --git a/cucul/figfont.c b/cucul/figfont.c index 80e5536..73b428f 100644 --- a/cucul/figfont.c +++ b/cucul/figfont.c @@ -303,6 +303,7 @@ cucul_figfont_t * open_figfont(char const *path) /* Open font: if not found, try .tlf, then .flf */ f = _cucul_file_open(path, "r"); +#if !defined __KERNEL__ && defined HAVE_SNPRINTF if(!f) { snprintf(altpath, 2047, "%s.tlf", path); @@ -315,6 +316,7 @@ cucul_figfont_t * open_figfont(char const *path) altpath[2047] = '\0'; f = _cucul_file_open(altpath, "r"); } +#endif if(!f) { free(ff); diff --git a/cucul/file.c b/cucul/file.c index ee2d0c5..c621342 100644 --- a/cucul/file.c +++ b/cucul/file.c @@ -19,7 +19,7 @@ #include "config.h" #include "common.h" -#if !defined(__KERNEL__) +#if !defined __KERNEL__ # include # include # include @@ -33,26 +33,31 @@ #include "cucul.h" #include "cucul_internals.h" -#if defined HAVE_ZLIB_H +#if !defined __KERNEL__ && defined HAVE_ZLIB_H static int zipread(cucul_file_t *, void *, unsigned int); #endif +#if !defined __KERNEL__ struct cucul_file { -#if defined HAVE_ZLIB_H +# if defined HAVE_ZLIB_H unsigned char read_buffer[READSIZE]; z_stream stream; gzFile gz; int eof, zip; -#endif +# endif FILE *f; }; +#endif cucul_file_t *_cucul_file_open(char const *path, const char *mode) { +#if defined __KERNEL__ + return NULL; +#else cucul_file_t *fp = malloc(sizeof(*fp)); -#if defined HAVE_ZLIB_H +# if defined HAVE_ZLIB_H uint8_t buf[4]; unsigned int skip_size = 0; @@ -99,7 +104,7 @@ cucul_file_t *_cucul_file_open(char const *path, const char *mode) gzclose(fp->gz); return NULL; } -#else +# else fp->f = fopen(path, mode); if(!fp->f) @@ -107,14 +112,17 @@ cucul_file_t *_cucul_file_open(char const *path, const char *mode) free(fp); return NULL; } -#endif +# endif return fp; +#endif } int _cucul_file_close(cucul_file_t *fp) { -#if defined HAVE_ZLIB_H +#if defined __KERNEL__ + return 0; +#elif defined HAVE_ZLIB_H gzFile gz = fp->gz; if(fp->zip) inflateEnd(&fp->stream); @@ -129,7 +137,9 @@ int _cucul_file_close(cucul_file_t *fp) int _cucul_file_eof(cucul_file_t *fp) { -#if defined HAVE_ZLIB_H +#if defined __KERNEL__ + return 1; +#elif defined HAVE_ZLIB_H return fp->zip ? fp->eof : gzeof(fp->gz); #else return feof(fp->f); @@ -138,7 +148,9 @@ int _cucul_file_eof(cucul_file_t *fp) char *_cucul_file_gets(char *s, int size, cucul_file_t *fp) { -#if defined HAVE_ZLIB_H +#if defined __KERNEL__ + return NULL; +#elif defined HAVE_ZLIB_H if(fp->zip) { int i; @@ -167,7 +179,7 @@ char *_cucul_file_gets(char *s, int size, cucul_file_t *fp) #endif } -#if defined HAVE_ZLIB_H +#if !defined __KERNEL__ && defined HAVE_ZLIB_H static int zipread(cucul_file_t *fp, void *buf, unsigned int len) { unsigned int total_read = 0; diff --git a/kernel/kernel.c b/kernel/kernel.c index 455b48f..e2cc8c6 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -212,6 +212,16 @@ char *strdup(const char *s) return new; } +char *strchr(const char *s, int c) +{ + do + if(*s == c) + return (char *)(intptr_t)s; + while(*s++); + + return NULL; +} + /* stdarg.h functions */ int vsnprintf(char *str, size_t size, const char *format, va_list ap) { diff --git a/kernel/kernel.h b/kernel/kernel.h index 15be8fe..f95a076 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -87,6 +87,7 @@ int strcmp(const char *s1, const char *s2); int strcasecmp(const char *s1, const char *s2); int memcmp(const void *s1, const void *s2, size_t n); char *strdup(const char *s); +char *strchr(const char *s, int c); /* stdarg.h functions */ typedef void * va_list; diff --git a/msvc/config.h b/msvc/config.h index f86060e..a7e2a49 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -32,6 +32,7 @@ /* #undef HAVE_UNISTD_H */ /* #undef HAVE_USLEEP */ /* #undef HAVE_VSNPRINTF */ +#define HAVE_SNPRINTF 1 #define HAVE_WINDOWS_H 1 /* #undef HAVE_X11_XKBLIB_H */ /* #undef NO_MINUS_C_MINUS_O */