- created jitcache-arm-x86 branch
[cacao.git] / src / vmcore / system.h
index d632139bcd7ab54a13c79ba67c8bd8fd1e093dc3..8a052aedc9a06a06b041c28345eda1086299c7d1 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vmcore/system.h - system (OS) functions
 
-   Copyright (C) 2007
+   Copyright (C) 2007, 2008
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 /* NOTE: In this file we check for all system headers, because we wrap
    all system calls into inline functions for better portability. */
 
+#if defined(HAVE_DIRENT_H)
+# include <dirent.h>
+#endif
+
+#if defined(HAVE_DLFCN_H)
+# include <dlfcn.h>
+#endif
+
 #if defined(HAVE_FCNTL_H)
 # include <fcntl.h>
 #endif
 
+#if defined(ENABLE_JRE_LAYOUT)
+# if defined(HAVE_LIBGEN_H)
+#  include <libgen.h>
+# endif
+#endif
+
 #if defined(HAVE_STDINT_H)
 # include <stdint.h>
 #endif
 
+#if defined(HAVE_STDIO_H)
+# include <stdio.h>
+#endif
+
 #if defined(HAVE_STDLIB_H)
 # include <stdlib.h>
 #endif
 # include <sys/socket.h>
 #endif
 
+#if defined(HAVE_SYS_STAT_H)
+# include <sys/stat.h>
+#endif
+
 #if defined(HAVE_SYS_TYPES_H)
 # include <sys/types.h>
 #endif
 
 /* inline functions ***********************************************************/
 
+inline static void system_abort(void)
+{
+#if defined(HAVE_ABORT)
+       abort();
+#else
+# error abort not available
+#endif
+}
+
 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 {
 #if defined(HAVE_ACCEPT)
@@ -75,6 +106,24 @@ inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *ad
 #endif
 }
 
+inline static int system_access(const char *pathname, int mode)
+{
+#if defined(HAVE_ACCESS)
+       return access(pathname, mode);
+#else
+# error access not available
+#endif
+}
+
+inline static int system_atoi(const char *nptr)
+{
+#if defined(HAVE_ATOI)
+       return atoi(nptr);
+#else
+# error atoi not available
+#endif
+}
+
 inline static void *system_calloc(size_t nmemb, size_t size)
 {
 #if defined(HAVE_CALLOC)
@@ -102,6 +151,89 @@ inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, s
 #endif
 }
 
+#if defined(ENABLE_JRE_LAYOUT)
+inline static char *system_dirname(char *path)
+{
+#if defined(HAVE_DIRNAME)
+       return dirname(path);
+#else
+# error dirname not available
+#endif
+}
+#endif
+
+inline static int system_dlclose(void* handle)
+{
+#if defined(HAVE_DLCLOSE)
+       return dlclose(handle);
+#else
+# error dlclose not available
+#endif
+}
+
+inline static char* system_dlerror(void)
+{
+#if defined(HAVE_DLERROR)
+       return dlerror();
+#else
+# error dlerror not available
+#endif
+}
+
+inline static void* system_dlopen(const char* filename, int flag)
+{
+#if defined(HAVE_DLOPEN)
+       return dlopen(filename, flag);
+#else
+# error dlopen not available
+#endif
+}
+
+inline static void* system_dlsym(void* handle, const char* symbol)
+{
+#if defined(HAVE_DLSYM)
+       return dlsym(handle, symbol);
+#else
+# error dlsym not available
+#endif
+}
+
+inline static FILE *system_fopen(const char *path, const char *mode)
+{
+#if defined(HAVE_FOPEN)
+       return fopen(path, mode);
+#else
+# error fopen not available
+#endif
+}
+
+inline static int system_fclose(FILE *fp)
+{
+#if defined(HAVE_FCLOSE)
+       return fclose(fp);
+#else
+# error fclose not available
+#endif
+}
+
+inline static size_t system_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+#if defined(HAVE_FREAD)
+       return fread(ptr, size, nmemb, stream);
+#else
+# error fread not available
+#endif
+}
+
+inline static int system_fseek(FILE *stream, off_t offset, int whence)
+{
+#if defined(HAVE_FSEEK)
+       return fseek(stream, offset, whence);
+#else
+# error fseek not available
+#endif
+}
+
 inline static void system_free(void *ptr)
 {
 #if defined(HAVE_FREE)
@@ -246,6 +378,21 @@ inline static void *system_realloc(void *ptr, size_t size)
 #endif
 }
 
+#if defined(__LINUX__)
+inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
+#elif defined(__IRIX__)
+inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(dirent_t *), int(*compar)(dirent_t **, dirent_t **))
+#else
+inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(struct dirent *), int(*compar)(const void *, const void *))
+#endif
+{
+#if defined(HAVE_SCANDIR)
+       return scandir(dir, namelist, filter, compar);
+#else
+# error scandir not available
+#endif
+}
+
 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
 {
 #if defined(HAVE_SETSOCKOPT)
@@ -273,6 +420,60 @@ inline static int system_socket(int domain, int type, int protocol)
 #endif
 }
 
+inline static int system_stat(const char *path, struct stat *buf)
+{
+#if defined(HAVE_STAT)
+       return stat(path, buf);
+#else
+# error stat not available
+#endif
+}
+
+inline static char *system_strcat(char *dest, const char *src)
+{
+#if defined(HAVE_STRCAT)
+       return strcat(dest, src);
+#else
+# error strcat not available
+#endif
+}
+
+inline static char *system_strcpy(char *dest, const char *src)
+{
+#if defined(HAVE_STRCPY)
+       return strcpy(dest, src);
+#else
+# error strcpy not available
+#endif
+}
+
+inline static char *system_strdup(const char *s)
+{
+#if defined(HAVE_STRDUP)
+       return strdup(s);
+#else
+# error strdup not available
+#endif
+}
+
+inline static char *system_strerror(int errnum)
+{
+#if defined(HAVE_STRERROR)
+       return strerror(errnum);
+#else
+# error strerror not available
+#endif
+}
+
+inline static size_t system_strlen(const char *s)
+{
+#if defined(HAVE_STRLEN)
+       return strlen(s);
+#else
+# error strlen not available
+#endif
+}
+
 inline static ssize_t system_write(int fd, const void *buf, size_t count)
 {
 #if defined(HAVE_WRITE)