Browse Source

* Disable file operations in kernel mode.

* Implement strchr() in kernel.c.
  * Check for snprintf() at configure time.
tags/v0.99.beta14
Sam Hocevar sam 17 years ago
parent
commit
e895e01ee6
6 changed files with 38 additions and 12 deletions
  1. +1
    -1
      configure.ac
  2. +2
    -0
      cucul/figfont.c
  3. +23
    -11
      cucul/file.c
  4. +10
    -0
      kernel/kernel.c
  5. +1
    -0
      kernel/kernel.h
  6. +1
    -0
      msvc/config.h

+ 1
- 1
configure.ac View File

@@ -88,7 +88,7 @@ AC_ARG_ENABLE(zzuf,
[ --enable-zzuf use zzuf for fuzzing tests (autodetected)]) [ --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_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(usleep gettimeofday)


AC_CHECK_FUNCS(getopt_long, AC_CHECK_FUNCS(getopt_long,


+ 2
- 0
cucul/figfont.c View File

@@ -303,6 +303,7 @@ cucul_figfont_t * open_figfont(char const *path)


/* Open font: if not found, try .tlf, then .flf */ /* Open font: if not found, try .tlf, then .flf */
f = _cucul_file_open(path, "r"); f = _cucul_file_open(path, "r");
#if !defined __KERNEL__ && defined HAVE_SNPRINTF
if(!f) if(!f)
{ {
snprintf(altpath, 2047, "%s.tlf", path); snprintf(altpath, 2047, "%s.tlf", path);
@@ -315,6 +316,7 @@ cucul_figfont_t * open_figfont(char const *path)
altpath[2047] = '\0'; altpath[2047] = '\0';
f = _cucul_file_open(altpath, "r"); f = _cucul_file_open(altpath, "r");
} }
#endif
if(!f) if(!f)
{ {
free(ff); free(ff);


+ 23
- 11
cucul/file.c View File

@@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "common.h" #include "common.h"


#if !defined(__KERNEL__)
#if !defined __KERNEL__
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <string.h> # include <string.h>
@@ -33,26 +33,31 @@
#include "cucul.h" #include "cucul.h"
#include "cucul_internals.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); static int zipread(cucul_file_t *, void *, unsigned int);
#endif #endif


#if !defined __KERNEL__
struct cucul_file struct cucul_file
{ {
#if defined HAVE_ZLIB_H
# if defined HAVE_ZLIB_H
unsigned char read_buffer[READSIZE]; unsigned char read_buffer[READSIZE];
z_stream stream; z_stream stream;
gzFile gz; gzFile gz;
int eof, zip; int eof, zip;
#endif
# endif
FILE *f; FILE *f;
}; };
#endif


cucul_file_t *_cucul_file_open(char const *path, const char *mode) 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)); cucul_file_t *fp = malloc(sizeof(*fp));


#if defined HAVE_ZLIB_H
# if defined HAVE_ZLIB_H
uint8_t buf[4]; uint8_t buf[4];
unsigned int skip_size = 0; unsigned int skip_size = 0;


@@ -99,7 +104,7 @@ cucul_file_t *_cucul_file_open(char const *path, const char *mode)
gzclose(fp->gz); gzclose(fp->gz);
return NULL; return NULL;
} }
#else
# else
fp->f = fopen(path, mode); fp->f = fopen(path, mode);


if(!fp->f) if(!fp->f)
@@ -107,14 +112,17 @@ cucul_file_t *_cucul_file_open(char const *path, const char *mode)
free(fp); free(fp);
return NULL; return NULL;
} }
#endif
# endif


return fp; return fp;
#endif
} }


int _cucul_file_close(cucul_file_t *fp) 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; gzFile gz = fp->gz;
if(fp->zip) if(fp->zip)
inflateEnd(&fp->stream); inflateEnd(&fp->stream);
@@ -129,7 +137,9 @@ int _cucul_file_close(cucul_file_t *fp)


int _cucul_file_eof(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); return fp->zip ? fp->eof : gzeof(fp->gz);
#else #else
return feof(fp->f); 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) 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) if(fp->zip)
{ {
int i; int i;
@@ -167,7 +179,7 @@ char *_cucul_file_gets(char *s, int size, cucul_file_t *fp)
#endif #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) static int zipread(cucul_file_t *fp, void *buf, unsigned int len)
{ {
unsigned int total_read = 0; unsigned int total_read = 0;


+ 10
- 0
kernel/kernel.c View File

@@ -212,6 +212,16 @@ char *strdup(const char *s)
return new; 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 */ /* stdarg.h functions */
int vsnprintf(char *str, size_t size, const char *format, va_list ap) int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ {


+ 1
- 0
kernel/kernel.h View File

@@ -87,6 +87,7 @@ int strcmp(const char *s1, const char *s2);
int strcasecmp(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); int memcmp(const void *s1, const void *s2, size_t n);
char *strdup(const char *s); char *strdup(const char *s);
char *strchr(const char *s, int c);


/* stdarg.h functions */ /* stdarg.h functions */
typedef void * va_list; typedef void * va_list;


+ 1
- 0
msvc/config.h View File

@@ -32,6 +32,7 @@
/* #undef HAVE_UNISTD_H */ /* #undef HAVE_UNISTD_H */
/* #undef HAVE_USLEEP */ /* #undef HAVE_USLEEP */
/* #undef HAVE_VSNPRINTF */ /* #undef HAVE_VSNPRINTF */
#define HAVE_SNPRINTF 1
#define HAVE_WINDOWS_H 1 #define HAVE_WINDOWS_H 1
/* #undef HAVE_X11_XKBLIB_H */ /* #undef HAVE_X11_XKBLIB_H */
/* #undef NO_MINUS_C_MINUS_O */ /* #undef NO_MINUS_C_MINUS_O */


Loading…
Cancel
Save