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 #ifndef _PLIBC_H_
00029 #define _PLIBC_H_
00030
00031 #ifndef SIGALRM
00032 #define SIGALRM 14
00033 #endif
00034
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038
00039 #ifdef WINDOWS
00040
00041 #if ENABLE_NLS
00042 #include "langinfo.h"
00043 #endif
00044
00045 #include <windows.h>
00046 #include <Ws2tcpip.h>
00047 #include <time.h>
00048 #include <stdio.h>
00049 #include <sys/types.h>
00050 #include <sys/stat.h>
00051 #include <dirent.h>
00052 #include <errno.h>
00053
00054 #define __BYTE_ORDER BYTE_ORDER
00055 #define __BIG_ENDIAN BIG_ENDIAN
00056
00057
00058 #define __G_WIN32_H__
00059
00060
00061 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
00062 (double)((x).LowPart))
00063
00064 #define socklen_t int
00065 #define ssize_t int
00066 #ifndef HAVE_FTRUNCATE
00067 #define ftruncate chsize
00068 #endif
00069 #define off_t int
00070 #define int64_t long long
00071 #define int32_t long
00072
00073 #ifndef pid_t
00074 #define pid_t int
00075 #endif
00076
00077 #ifndef WEXITSTATUS
00078 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
00079 #endif
00080
00081
00082 #define ENOCSI 43
00083 #define EL2HLT 44
00084 #ifndef EDEADLK
00085 #define EDEADLK 45
00086 #endif
00087 #ifndef ENOLCK
00088 #define ENOLCK 46
00089 #endif
00090 #define EBADE 50
00091 #define EBADR 51
00092 #define EXFULL 52
00093 #define ENOANO 53
00094 #define EBADRQC 54
00095 #define EBADSLT 55
00096 #ifndef EDEADLOCK
00097 #define EDEADLOCK EDEADLK
00098 #endif
00099 #define EBFONT 57
00100 #define ENOSTR 60
00101 #define ENODATA 61
00102 #define ETIME 62
00103 #define ENOSR 63
00104 #define ENONET 64
00105 #define ENOPKG 65
00106 #define EREMOTE 66
00107 #define ENOLINK 67
00108 #define EADV 68
00109 #define ESRMNT 69
00110 #define ECOMM 70
00111 #define EPROTO 71
00112 #define EMULTIHOP 74
00113 #define ELBIN 75
00114 #define EDOTDOT 76
00115 #define EBADMSG 77
00116 #define ENOTUNIQ 80
00117 #define EBADFD 81
00118 #define EREMCHG 82
00119 #define ELIBACC 83
00120 #define ELIBBAD 84
00121 #define ELIBSCN 85
00122 #define ELIBMAX 86
00123 #define ELIBEXEC 87
00124 #ifndef ENOSYS
00125 #define ENOSYS 88
00126 #endif
00127 #define ENMFILE 89
00128 #ifndef ENOTEMPTY
00129 #define ENOTEMPTY 90
00130 #endif
00131 #ifndef ENAMETOOLONG
00132 #define ENAMETOOLONG 91
00133 #endif
00134 #define ELOOP 92
00135 #define EOPNOTSUPP 95
00136 #define EPFNOSUPPORT 96
00137 #define ECONNRESET 104
00138 #define ENOBUFS 105
00139 #define EAFNOSUPPORT 106
00140 #define EPROTOTYPE 107
00141 #define ENOTSOCK 108
00142 #define ENOPROTOOPT 109
00143 #define ESHUTDOWN 110
00144 #define ECONNREFUSED 111
00145 #define EADDRINUSE 112
00146 #define ECONNABORTED 113
00147 #define ENETUNREACH 114
00148 #define ENETDOWN 115
00149 #ifndef ETIMEDOUT
00150 #define ETIMEDOUT 116
00151 #endif
00152 #define EHOSTDOWN 117
00153 #define EHOSTUNREACH 118
00154 #define EINPROGRESS 119
00155 #define EALREADY 120
00156 #define EDESTADDRREQ 121
00157 #define EMSGSIZE 122
00158 #define EPROTONOSUPPORT 123
00159 #define ESOCKTNOSUPPORT 124
00160 #define EADDRNOTAVAIL 125
00161 #define ENETRESET 126
00162 #define EISCONN 127
00163 #define ENOTCONN 128
00164 #define ETOOMANYREFS 129
00165 #define EPROCLIM 130
00166 #define EUSERS 131
00167 #define EDQUOT 132
00168 #define ESTALE 133
00169 #ifndef ENOTSUP
00170 #define ENOTSUP 134
00171 #endif
00172 #define ENOMEDIUM 135
00173 #define ENOSHARE 136
00174 #define ECASECLASH 137
00175 #define EWOULDBLOCK EAGAIN
00176 #define EOVERFLOW 139
00177
00178 #undef HOST_NOT_FOUND
00179 #define HOST_NOT_FOUND 1
00180 #undef TRY_AGAIN
00181 #define TRY_AGAIN 2
00182 #undef NO_RECOVERY
00183 #define NO_RECOVERY 3
00184 #undef NO_ADDRESS
00185 #define NO_ADDRESS 4
00186
00187 #define PROT_READ 0x1
00188 #define PROT_WRITE 0x2
00189 #define MAP_SHARED 0x1
00190 #define MAP_PRIVATE 0x2
00191 #define MAP_FIXED 0x10
00192 #define MAP_FAILED ((void *)-1)
00193
00194 struct statfs
00195 {
00196 long f_type;
00197 long f_bsize;
00198 long f_blocks;
00199 long f_bfree;
00200 long f_bavail;
00201 long f_files;
00202 long f_ffree;
00203 long f_fsid;
00204 long f_namelen;
00205 long f_spare[6];
00206 };
00207
00208
00209
00210 enum SYSTEM_INFORMATION_CLASS
00211 {
00212 SystemBasicInformation = 0,
00213 Unknown1,
00214 SystemPerformanceInformation = 2,
00215 SystemTimeOfDayInformation = 3,
00216 Unknown4,
00217 SystemProcessInformation = 5,
00218 Unknown6,
00219 Unknown7,
00220 SystemProcessorPerformanceInformation = 8,
00221 Unknown9,
00222 Unknown10,
00223 SystemDriverInformation,
00224 Unknown12,
00225 Unknown13,
00226 Unknown14,
00227 Unknown15,
00228 SystemHandleList,
00229 Unknown17,
00230 Unknown18,
00231 Unknown19,
00232 Unknown20,
00233 SystemCacheInformation,
00234 Unknown22,
00235 SystemInterruptInformation = 23,
00236 SystemExceptionInformation = 33,
00237 SystemRegistryQuotaInformation = 37,
00238 SystemLookasideInformation = 45
00239 };
00240
00241 typedef struct
00242 {
00243 LARGE_INTEGER IdleTime;
00244 LARGE_INTEGER KernelTime;
00245 LARGE_INTEGER UserTime;
00246 LARGE_INTEGER Reserved1[2];
00247 ULONG Reserved2;
00248 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
00249
00250 #define sleep(secs) (Sleep(secs * 1000))
00251
00252
00253
00254 #define FAKED_BLOCK_SIZE 512
00255
00256
00257 #define MSDOS_SUPER_MAGIC 0x4d44
00258 #define NTFS_SUPER_MAGIC 0x5346544E
00259
00260
00261
00262 #define SHUT_RDWR SD_BOTH
00263
00264
00265 #define LOCK_SH 1
00266 #define LOCK_EX 2
00267 #define LOCK_NB 4
00268
00269 #define LOCK_UN 8
00270
00271
00272 #define S_IRGRP 0
00273 #define S_IWGRP 0
00274 #define S_IROTH 0
00275 #define S_IXGRP 0
00276 #define S_IWOTH 0
00277 #define S_IXOTH 0
00278 #define S_ISUID 0
00279 #define S_ISGID 0
00280 #define S_ISVTX 0
00281 #define S_IRWXG 0
00282 #define S_IRWXO 0
00283
00284 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
00285
00286
00287
00288
00289 #define index(s, c) strchr(s, c)
00290
00291 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
00292 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
00293 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
00294 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
00295 long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
00296 char *pszBuffer, long *pdLength);
00297
00298 BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle);
00299 void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking);
00300 void __win_DiscardHandleBlockingMode(SOCKET s);
00301 int _win_isSocketValid(int s);
00302 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
00303
00304 typedef void (*TPanicProc) (int, char *);
00305 void plibc_set_panic_proc(TPanicProc proc);
00306
00307 int flock(int fd, int operation);
00308 int fsync(int fildes);
00309 int inet_pton(int af, const char *src, void *dst);
00310 int inet_pton4(const char *src, u_char *dst, int pton);
00311 #if USE_IPV6
00312 int inet_pton6(const char *src, u_char *dst);
00313 #endif
00314 int truncate(const char *fname, int distance);
00315 int statfs(const char *path, struct statfs *buf);
00316 const char *hstrerror(int err);
00317 void gettimeofday(struct timeval *tp, void *tzp);
00318 int mkstemp(char *tmplate);
00319 char *strptime (const char *buf, const char *format, struct tm *tm);
00320 char *ctime(const time_t *clock);
00321 char *ctime_r(const time_t *clock, char *buf);
00322 int plibc_init(char *pszOrg, char *pszApp);
00323 void plibc_shutdown();
00324 int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks);
00325 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
00326 void SetErrnoFromWinsockError(long lWinError);
00327 void SetHErrnoFromWinError(long lWinError);
00328 void SetErrnoFromHRESULT(HRESULT hRes);
00329 FILE *_win_fopen(const char *filename, const char *mode);
00330 DIR *_win_opendir(const char *dirname);
00331 int _win_open(const char *filename, int oflag, ...);
00332 #ifdef ENABLE_NLS
00333 char *_win_bindtextdomain(const char *domainname, const char *dirname);
00334 #endif
00335 int _win_chdir(const char *path);
00336 int _win_close(int fd);
00337 int _win_creat(const char *path, mode_t mode);
00338 int _win_fstat(int handle, struct stat *buffer);
00339 int _win_pipe(int *phandles);
00340 int _win_rmdir(const char *path);
00341 int _win_access( const char *path, int mode );
00342 int _win_chmod(const char *filename, int pmode);
00343 char *realpath(const char *file_name, char *resolved_name);
00344 long _win_random(void);
00345 int _win_remove(const char *path);
00346 int _win_rename(const char *oldname, const char *newname);
00347 int _win_stat(const char *path, struct stat *buffer);
00348 int _win_unlink(const char *filename);
00349 int _win_write(int fildes, const void *buf, size_t nbyte);
00350 int _win_read(int fildes, void *buf, size_t nbyte);
00351 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
00352 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
00353 int _win_symlink(const char *path1, const char *path2);
00354 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
00355 unsigned long long offset);
00356 int _win_munmap(void *start, size_t length);
00357 int _win_lstat(const char *path, struct stat *buf);
00358 int _win_readlink(const char *path, char *buf, size_t bufsize);
00359 int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen);
00360 int _win_printf(const char *format,...);
00361 int _win_fprintf(FILE *f,const char *format,...);
00362 int _win_vprintf(const char *format, va_list ap);
00363 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
00364 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
00365 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr);
00366 int _win_snprintf(char *str,size_t size,const char *format,...);
00367 int _win_sprintf(char *dest,const char *format,...);
00368 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
00369 int _win_sscanf(const char *str, const char *format, ...);
00370 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
00371 int _win_vscanf(const char *format, va_list arg_ptr);
00372 int _win_scanf(const char *format, ...);
00373 int _win_fscanf(FILE *stream, const char *format, ...);
00374 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
00375 int _win_bind(SOCKET s, const struct sockaddr *name, int namelen);
00376 int _win_connect(SOCKET s,const struct sockaddr *name, int namelen);
00377 int _win_getpeername(SOCKET s, struct sockaddr *name,
00378 int *namelen);
00379 int _win_getsockname(SOCKET s, struct sockaddr *name,
00380 int *namelen);
00381 int _win_getsockopt(SOCKET s, int level, int optname, char *optval,
00382 int *optlen);
00383 int _win_listen(SOCKET s, int backlog);
00384 int _win_recv(SOCKET s, char *buf, int len, int flags);
00385 int _win_recvfrom(SOCKET s, void *buf, int len, int flags,
00386 struct sockaddr *from, int *fromlen);
00387 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
00388 const struct timeval *tv);
00389 int _win_send(SOCKET s, const char *buf, int len, int flags);
00390 int _win_sendto(SOCKET s, const char *buf, int len, int flags,
00391 const struct sockaddr *to, int tolen);
00392 int _win_setsockopt(SOCKET s, int level, int optname, const void *optval,
00393 int optlen);
00394 int _win_shutdown(SOCKET s, int how);
00395 SOCKET _win_socket(int af, int type, int protocol);
00396 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
00397 struct hostent *_win_gethostbyname(const char *name);
00398 char *_win_strerror(int errnum);
00399 int IsWinNT();
00400
00401 #if !HAVE_STRNDUP
00402 char *strndup (const char *s, size_t n);
00403 #endif
00404 #if !HAVE_STRNLEN
00405 size_t strnlen (const char *str, size_t maxlen);
00406 #endif
00407
00408 #endif
00409
00410 #ifndef WINDOWS
00411 #define DIR_SEPARATOR '/'
00412 #define DIR_SEPARATOR_STR "/"
00413 #define NEWLINE "\n"
00414
00415 #ifdef ENABLE_NLS
00416 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
00417 #endif
00418 #define CREAT(p, m) creat(p, m)
00419 #undef FOPEN
00420 #define FOPEN(f, m) fopen(f, m)
00421 #define OPENDIR(d) opendir(d)
00422 #define OPEN(f) open(f)
00423 #define CHDIR(d) chdir(d)
00424 #define CLOSE(f) close(f)
00425 #define RMDIR(f) rmdir(f)
00426 #define ACCESS(p, m) access(p, m)
00427 #define CHMOD(f, p) chmod(f, p)
00428 #define FSTAT(h, b) fstat(h, b)
00429 #define PIPE(h) pipe(h)
00430 #define REMOVE(p) remove(p)
00431 #define RENAME(o, n) rename(o, n)
00432 #define STAT(p, b) stat(p, b)
00433 #define UNLINK(f) unlink(f)
00434 #define WRITE(f, b, n) write(f, b, n)
00435 #define READ(f, b, n) read(f, b, n)
00436 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
00437 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
00438 #define SYMLINK(a, b) symlink(a, b)
00439 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
00440 #define MUNMAP(s, l) munmap(s, l)
00441 #define STRERROR(i) strerror(i)
00442 #define RANDOM() random()
00443 #define READLINK(p, b, s) readlink(p, b, s)
00444 #define LSTAT(p, b) lstat(p, b)
00445 #define PRINTF printf
00446 #define FPRINTF fprintf
00447 #define VPRINTF(f, a) vprintf(f, a)
00448 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
00449 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
00450 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
00451 #define _REAL_SNPRINTF snprintf
00452 #define SPRINTF sprintf
00453 #define VSSCANF(s, f, a) vsscanf(s, f, a)
00454 #define SSCANF sscanf
00455 #define VFSCANF(s, f, a) vfscanf(s, f, a)
00456 #define VSCANF(f, a) vscanf(f, a)
00457 #define SCANF scanf
00458 #define FSCANF fscanf
00459 #define WAITPID(p, s, o) waitpid(p, s, o)
00460 #define ACCEPT(s, a, l) accept(s, a, l)
00461 #define BIND(s, n, l) bind(s, n, l)
00462 #define CONNECT(s, n, l) connect(s, n, l)
00463 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
00464 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
00465 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
00466 #define LISTEN(s, b) listen(s, b)
00467 #define RECV(s, b, l, f) recv(s, b, l, f)
00468 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
00469 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
00470 #define SEND(s, b, l, f) send(s, b, l, f)
00471 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
00472 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
00473 #define SHUTDOWN(s, h) shutdown(s, h)
00474 #define SOCKET(a, t, p) socket(a, t, p)
00475 #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
00476 #define GETHOSTBYNAME(n) gethostbyname(n)
00477 #else
00478 #define DIR_SEPARATOR '\\'
00479 #define DIR_SEPARATOR_STR "\\"
00480 #define NEWLINE "\r\n"
00481
00482 #ifdef ENABLE_NLS
00483 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
00484 #endif
00485 #define CREAT(p, m) _win_creat(p, m)
00486 #define FOPEN(f, m) _win_fopen(f, m)
00487 #define OPENDIR(d) _win_opendir(d)
00488 #define OPEN(f) _win_open(f)
00489 #define CHDIR(d) _win_chdir(d)
00490 #define CLOSE(f) _win_close(f)
00491 #define FSTAT(h, b) _win_fstat(h, b)
00492 #define RMDIR(f) _win_rmdir(f)
00493 #define ACCESS(p, m) _win_access(p, m)
00494 #define CHMOD(f, p) _win_chmod(f, p)
00495 #define PIPE(h) _win_pipe(h)
00496 #define RANDOM() _win_random()
00497 #define REMOVE(p) _win_remove(p)
00498 #define RENAME(o, n) _win_rename(o, n)
00499 #define STAT(p, b) _win_stat(p, b)
00500 #define UNLINK(f) _win_unlink(f)
00501 #define WRITE(f, b, n) _win_write(f, b, n)
00502 #define READ(f, b, n) _win_read(f, b, n)
00503 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
00504 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
00505 #define SYMLINK(a, b) _win_symlink(a, b)
00506 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
00507 #define MUNMAP(s, l) _win_munmap(s, l)
00508 #define STRERROR(i) _win_strerror(i)
00509 #define READLINK(p, b, s) _win_readlink(p, b, s)
00510 #define LSTAT(p, b) _win_lstat(p, b)
00511 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
00512 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
00513 #define VPRINTF(f, a) _win_vprintf(f, a)
00514 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
00515 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
00516 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
00517 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
00518 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
00519 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
00520 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
00521 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
00522 #define VSCANF(f, a) _win_vscanf(f, a)
00523 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
00524 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
00525 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
00526 #define ACCEPT(s, a, l) _win_accept(s, a, l)
00527 #define BIND(s, n, l) _win_bind(s, n, l)
00528 #define CONNECT(s, n, l) _win_connect(s, n, l)
00529 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
00530 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
00531 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
00532 #define LISTEN(s, b) _win_listen(s, b)
00533 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
00534 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
00535 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
00536 #define SEND(s, b, l, f) _win_send(s, b, l, f)
00537 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
00538 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
00539 #define SHUTDOWN(s, h) _win_shutdown(s, h)
00540 #define SOCKET(a, t, p) _win_socket(a, t, p)
00541 #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
00542 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
00543 #endif
00544
00545
00546 #ifdef __cplusplus
00547 }
00548 #endif
00549
00550
00551 #endif //_PLIBC_H_
00552
00553