* Merged executionstate branch.
[cacao.git] / src / vmcore / system.h
index d632139bcd7ab54a13c79ba67c8bd8fd1e093dc3..d98bd9010666a0befd553c3f44d0fc1fb3351a86 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_FCNTL_H)
 # include <fcntl.h>
 #endif
 
+#if defined(WITH_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 +102,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 +147,44 @@ inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, s
 #endif
 }
 
+#if defined(WITH_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 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 void system_free(void *ptr)
 {
 #if defined(HAVE_FREE)
@@ -246,6 +329,15 @@ inline static void *system_realloc(void *ptr, size_t size)
 #endif
 }
 
+inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
+{
+#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 +365,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)