00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __SYSDEPS_POSIX_H__
00033 #define __SYSDEPS_POSIX_H__
00034
00035 #include "SysDeps/host_type.h"
00036
00037 #include <stdio.h>
00038 #include <errno.h>
00039 #include <fcntl.h>
00040 #include <sys/stat.h>
00041
00042 #ifdef HOST_IS_WINDOWS
00043
00044 #include <io.h>
00045 #include <process.h>
00046 #include <direct.h>
00047
00048 #elif defined(HOST_IS_CYGWIN)
00049
00050 #include <io.h>
00051 #include <process.h>
00052 #include <dirent.h>
00053
00054 #elif defined(HOST_IS_LINUX)
00055
00056 #include <unistd.h>
00057 #include <fcntl.h>
00058 #include <stdarg.h>
00059 #include <utime.h>
00060 #include <sys/types.h>
00061 #include <sys/stat.h>
00062 #include <sys/time.h>
00063 #include <sys/times.h>
00064 #include <sys/resource.h>
00065 #include <sys/file.h>
00066 #include <sys/mman.h>
00067 #include <sys/wait.h>
00068 #include <sys/socket.h>
00069 #include <sys/times.h>
00070 #include <sys/ioctl.h>
00071 #include <sys/mount.h>
00072
00073 #else
00074 #error "unknown host type"
00075 #endif
00076
00077
00078 #ifdef HOST_IS_WINDOWS
00079 namespace Onikiri {
00080 namespace POSIX {
00081 typedef struct stat posix_struct_stat;
00082 const int POSIX_O_BINARY = _O_BINARY;
00083 const int POSIX_O_RDONLY = _O_RDONLY;
00084 const int POSIX_O_WRONLY = _O_WRONLY;
00085 const int POSIX_O_RDWR = _O_RDWR;
00086 const int POSIX_O_APPEND = _O_APPEND;
00087 const int POSIX_O_CREAT = _O_CREAT;
00088 const int POSIX_O_EXCL = _O_EXCL;
00089 const int POSIX_O_TRUNC = _O_TRUNC;
00090
00091 const int POSIX_S_IFDIR = _S_IFDIR;
00092 const int POSIX_S_IFCHR = _S_IFCHR;
00093 const int POSIX_S_IFREG = _S_IFREG;
00094 const int POSIX_S_IFIFO = _S_IFIFO;
00095
00096 const int POSIX_S_IWRITE = _S_IWRITE;
00097 const int POSIX_S_IREAD = _S_IREAD;
00098
00099 const int POSIX_F_OK = 0;
00100 const int POSIX_X_OK = 0;
00101 const int POSIX_W_OK = 2;
00102 const int POSIX_R_OK = 4;
00103
00104 const int POSIX_SEEK_SET = SEEK_SET;
00105 const int POSIX_SEEK_CUR = SEEK_CUR;
00106 const int POSIX_SEEK_END = SEEK_END;
00107
00108 int posix_geterrno();
00109
00110 int posix_getpid();
00111
00112
00113 inline int posix_getuid()
00114 { return 959; }
00115 inline int posix_geteuid()
00116 { return 959; }
00117 inline int posix_getgid()
00118 { return 10; }
00119 inline int posix_getegid()
00120 { return 10; }
00121
00122 char *posix_getcwd(char* buf, int maxlen);
00123 int posix_chdir(const char* path);
00124
00125 int posix_open(const char* name, int flags);
00126 int posix_open(const char* name, int flags, int pmode);
00127 int posix_read(int fd, void* buf, unsigned int count);
00128 int posix_write(int fd, void* buf, unsigned int count);
00129 int posix_close(int fd);
00130 s64 posix_lseek(int fd, s64 offset, int whence);
00131 int posix_dup(int fd);
00132
00133 int posix_stat(const char* path, posix_struct_stat* s);
00134 int posix_fstat(int fd, posix_struct_stat* s);
00135 int posix_lstat(const char* path, posix_struct_stat* s);
00136
00137 int posix_fileno(FILE *file);
00138 int posix_access(const char* path, int mode);
00139 int posix_unlink(const char* path);
00140 int posix_rename(const char* oldpath, const char* newpath);
00141
00142 int posix_truncate(const char* path, s64 length);
00143 int posix_ftruncate(int fd, s64 length);
00144 }
00145 }
00146 #elif defined(HOST_IS_CYGWIN) || defined(HOST_IS_LINUX)
00147 namespace Onikiri {
00148 namespace POSIX {
00149 typedef struct stat posix_struct_stat;
00150 const int POSIX_O_BINARY = 0;
00151 const int POSIX_O_RDONLY = O_RDONLY;
00152 const int POSIX_O_WRONLY = O_WRONLY;
00153 const int POSIX_O_RDWR = O_RDWR;
00154 const int POSIX_O_APPEND = O_APPEND;
00155 const int POSIX_O_CREAT = O_CREAT;
00156 const int POSIX_O_EXCL = O_EXCL;
00157 const int POSIX_O_TRUNC = O_TRUNC;
00158
00159 const int POSIX_S_IFDIR = S_IFDIR;
00160 const int POSIX_S_IFCHR = S_IFCHR;
00161 const int POSIX_S_IFREG = S_IFREG;
00162 const int POSIX_S_IFIFO = S_IFIFO;
00163
00164 const int POSIX_S_IWRITE = S_IWRITE;
00165 const int POSIX_S_IREAD = S_IREAD;
00166
00167 const int POSIX_F_OK = F_OK;
00168 const int POSIX_X_OK = X_OK;
00169 const int POSIX_W_OK = W_OK;
00170 const int POSIX_R_OK = R_OK;
00171
00172 const int POSIX_SEEK_SET = SEEK_SET;
00173 const int POSIX_SEEK_CUR = SEEK_CUR;
00174 const int POSIX_SEEK_END = SEEK_END;
00175
00176 inline int posix_geterrno()
00177 { return errno; }
00178
00179 inline int posix_getpid()
00180 { return getpid(); }
00181
00182 inline int posix_getuid()
00183 { return getuid(); }
00184 inline int posix_geteuid()
00185 { return geteuid(); }
00186 inline int posix_getgid()
00187 { return getgid(); }
00188 inline int posix_getegid()
00189 { return getegid(); }
00190
00191 inline char *posix_getcwd(char* buf, int maxlen)
00192 { return getcwd(buf, maxlen); }
00193 inline int posix_chdir(const char* path)
00194 { return chdir(path); }
00195
00196 inline int posix_open(const char* name, int flags)
00197 { return open(name, flags); }
00198 inline int posix_open(const char* name, int flags, int pmode)
00199 { return open(name, flags, pmode); }
00200 inline int posix_read(int fd, void* buf, unsigned int count)
00201 { return read(fd, buf, count); }
00202 inline int posix_write(int fd, void* buf, unsigned int count)
00203 { return write(fd, buf, count); }
00204 inline int posix_close(int fd)
00205 { return close(fd); }
00206 inline int posix_dup(int fd)
00207 { return dup(fd); }
00208
00209
00210 #if defined(HOST_IS_CYGWIN)
00211
00212 inline s64 posix_lseek(int fd, s64 offset, int whence)
00213 { return lseek(fd, offset, whence); }
00214 #elif defined(HOST_IS_LINUX)
00215 inline s64 posix_lseek(int fd, s64 offset, int whence)
00216 { return lseek64(fd, offset, whence); }
00217 #endif
00218
00219 inline int posix_stat(const char* path, posix_struct_stat* s)
00220 { return stat(path, s); }
00221 inline int posix_fstat(int fd, posix_struct_stat* s)
00222 { return fstat(fd, s); }
00223 inline int posix_lstat(const char* path, posix_struct_stat* s)
00224 { return lstat(path, s); }
00225
00226 inline int posix_fileno(FILE *file)
00227 { return fileno(file); }
00228 inline int posix_access(const char* path, int mode)
00229 { return access(path, mode); }
00230 inline int posix_unlink(const char* path)
00231 { return unlink(path); }
00232 inline int posix_rename(const char* oldpath, const char* newpath)
00233 { return rename(oldpath, newpath); }
00234
00235 inline int posix_truncate(const char* path, s64 length)
00236 { return truncate(path, length); }
00237 inline int posix_ftruncate(int fd, s64 length)
00238 { return ftruncate(fd, length); }
00239 }
00240 }
00241 #endif
00242
00243 #endif