00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00177 #undef HOST_NOT_FOUND
00178 #define HOST_NOT_FOUND 1
00179 #undef TRY_AGAIN
00180 #define TRY_AGAIN 2
00181 #undef NO_RECOVERY
00182 #define NO_RECOVERY 3
00183 #undef NO_ADDRESS
00184 #define NO_ADDRESS 4
00185
00186 #define PROT_READ 0x1
00187 #define PROT_WRITE 0x2
00188 #define MAP_SHARED 0x1
00189 #define MAP_PRIVATE 0x2
00190 #define MAP_FIXED 0x10
00191
00192 struct statfs
00193 {
00194 long f_type;
00195 long f_bsize;
00196 long f_blocks;
00197 long f_bfree;
00198 long f_bavail;
00199 long f_files;
00200 long f_ffree;
00201 long f_fsid;
00202 long f_namelen;
00203 long f_spare[6];
00204 };
00205
00206
00207
00208 enum SYSTEM_INFORMATION_CLASS
00209 {
00210 SystemBasicInformation = 0,
00211 Unknown1,
00212 SystemPerformanceInformation = 2,
00213 SystemTimeOfDayInformation = 3,
00214 Unknown4,
00215 SystemProcessInformation = 5,
00216 Unknown6,
00217 Unknown7,
00218 SystemProcessorPerformanceInformation = 8,
00219 Unknown9,
00220 Unknown10,
00221 SystemDriverInformation,
00222 Unknown12,
00223 Unknown13,
00224 Unknown14,
00225 Unknown15,
00226 SystemHandleList,
00227 Unknown17,
00228 Unknown18,
00229 Unknown19,
00230 Unknown20,
00231 SystemCacheInformation,
00232 Unknown22,
00233 SystemInterruptInformation = 23,
00234 SystemExceptionInformation = 33,
00235 SystemRegistryQuotaInformation = 37,
00236 SystemLookasideInformation = 45
00237 };
00238
00239 typedef struct
00240 {
00241 LARGE_INTEGER IdleTime;
00242 LARGE_INTEGER KernelTime;
00243 LARGE_INTEGER UserTime;
00244 LARGE_INTEGER Reserved1[2];
00245 ULONG Reserved2;
00246 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
00247
00248 #define sleep(secs) (Sleep(secs * 1000))
00249
00250
00251
00252 #define FAKED_BLOCK_SIZE 512
00253
00254
00255 #define MSDOS_SUPER_MAGIC 0x4d44
00256 #define NTFS_SUPER_MAGIC 0x5346544E
00257
00258
00259
00260 #define SHUT_RDWR SD_BOTH
00261
00262
00263 #define LOCK_SH 1
00264 #define LOCK_EX 2
00265 #define LOCK_NB 4
00266
00267 #define LOCK_UN 8
00268
00269
00270 #define S_IRGRP 0
00271 #define S_IWGRP 0
00272 #define S_IROTH 0
00273 #define S_IXGRP 0
00274 #define S_IWOTH 0
00275 #define S_IXOTH 0
00276 #define S_ISUID 0
00277 #define S_ISGID 0
00278 #define S_ISVTX 0
00279 #define S_IRWXG 0
00280 #define S_IRWXO 0
00281
00282 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
00283
00287 #define index(s, c) strchr(s, c)
00288
00289 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
00290 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
00291 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
00292 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
00293 long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
00294 char *pszBuffer, long *pdLength);
00295
00296 BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle);
00297 void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking);
00298 void __win_DiscardHandleBlockingMode(SOCKET s);
00299 int _win_isSocketValid(int s);
00300 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
00301
00302 typedef void (*TPanicProc) (int, char *);
00303 void plibc_set_panic_proc(TPanicProc proc);
00304
00305 int flock(int fd, int operation);
00306 int fsync(int fildes);
00307 int inet_pton(int af, const char *src, void *dst);
00308 int inet_pton4(const char *src, u_char *dst, int pton);
00309 #if USE_IPV6
00310 int inet_pton6(const char *src, u_char *dst);
00311 #endif
00312 int truncate(const char *fname, int distance);
00313 int statfs(const char *path, struct statfs *buf);
00314 const char *hstrerror(int err);
00315 void gettimeofday(struct timeval *tp, void *tzp);
00316 int mkstemp(char *tmplate);
00317 char *strptime (const char *buf, const char *format, struct tm *tm);
00318 char *ctime(const time_t *clock);
00319 char *ctime_r(const time_t *clock, char *buf);
00320 int plibc_init(char *pszOrg, char *pszApp);
00321 void plibc_shutdown();
00322 int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks);
00323 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
00324 void SetErrnoFromWinsockError(long lWinError);
00325 void SetHErrnoFromWinError(long lWinError);
00326 void SetErrnoFromHRESULT(HRESULT hRes);
00327 FILE *_win_fopen(const char *filename, const char *mode);
00328 DIR *_win_opendir(const char *dirname);
00329 int _win_open(const char *filename, int oflag, ...);
00330 #ifdef ENABLE_NLS
00331 char *_win_bindtextdomain(const char *domainname, const char *dirname);
00332 #endif
00333 int _win_chdir(const char *path);
00334 int _win_close(int fd);
00335 int _win_creat(const char *path, mode_t mode);
00336 int _win_fstat(int handle, struct stat *buffer);
00337 int _win_pipe(int *phandles);
00338 int _win_rmdir(const char *path);
00339 int _win_access( const char *path, int mode );
00340 int _win_chmod(const char *filename, int pmode);
00341 char *realpath(const char *file_name, char *resolved_name);
00342 long _win_random(void);
00343 int _win_remove(const char *path);
00344 int _win_rename(const char *oldname, const char *newname);
00345 int _win_stat(const char *path, struct stat *buffer);
00346 int _win_unlink(const char *filename);
00347 int _win_write(int fildes, const void *buf, size_t nbyte);
00348 int _win_read(int fildes, void *buf, size_t nbyte);
00349 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
00350 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
00351 int _win_symlink(const char *path1, const char *path2);
00352 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
00353 unsigned long long offset);
00354 int _win_munmap(void *start, size_t length);
00355 int _win_lstat(const char *path, struct stat *buf);
00356 int _win_readlink(const char *path, char *buf, size_t bufsize);
00357 int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen);
00358 int _win_printf(const char *format,...);
00359 int _win_fprintf(FILE *f,const char *format,...);
00360 int _win_vprintf(const char *format, va_list ap);
00361 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
00362 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
00363 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr);
00364 int _win_snprintf(char *str,size_t size,const char *format,...);
00365 int _win_sprintf(char *dest,const char *format,...);
00366 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
00367 int _win_sscanf(const char *str, const char *format, ...);
00368 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
00369 int _win_vscanf(const char *format, va_list arg_ptr);
00370 int _win_scanf(const char *format, ...);
00371 int _win_fscanf(FILE *stream, const char *format, ...);
00372 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
00373 int _win_bind(SOCKET s, const struct sockaddr *name, int namelen);
00374 int _win_connect(SOCKET s,const struct sockaddr *name, int namelen);
00375 int _win_getpeername(SOCKET s, struct sockaddr *name,
00376 int *namelen);
00377 int _win_getsockname(SOCKET s, struct sockaddr *name,
00378 int *namelen);
00379 int _win_getsockopt(SOCKET s, int level, int optname, char *optval,
00380 int *optlen);
00381 int _win_listen(SOCKET s, int backlog);
00382 int _win_recv(SOCKET s, char *buf, int len, int flags);
00383 int _win_recvfrom(SOCKET s, void *buf, int len, int flags,
00384 struct sockaddr *from, int *fromlen);
00385 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
00386 const struct timeval *tv);
00387 int _win_send(SOCKET s, const char *buf, int len, int flags);
00388 int _win_sendto(SOCKET s, const char *buf, int len, int flags,
00389 const struct sockaddr *to, int tolen);
00390 int _win_setsockopt(SOCKET s, int level, int optname, const void *optval,
00391 int optlen);
00392 int _win_shutdown(SOCKET s, int how);
00393 SOCKET _win_socket(int af, int type, int protocol);
00394 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
00395 struct hostent *_win_gethostbyname(const char *name);
00396 char *_win_strerror(int errnum);
00397 int IsWinNT();
00398
00399 #if !HAVE_STRNDUP
00400 char *strndup (const char *s, size_t n);
00401 #endif
00402 #if !HAVE_STRNLEN
00403 size_t strnlen (const char *str, size_t maxlen);
00404 #endif
00405
00406 #endif
00407
00408 #ifndef WINDOWS
00409 #define DIR_SEPARATOR '/'
00410 #define DIR_SEPARATOR_STR "/"
00411 #define NEWLINE "\n"
00412
00413 #ifdef ENABLE_NLS
00414 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
00415 #endif
00416 #define CREAT(p, m) creat(p, m)
00417 #undef FOPEN
00418 #define FOPEN(f, m) fopen(f, m)
00419 #define OPENDIR(d) opendir(d)
00420 #define OPEN(f) open(f)
00421 #define CHDIR(d) chdir(d)
00422 #define CLOSE(f) close(f)
00423 #define RMDIR(f) rmdir(f)
00424 #define ACCESS(p, m) access(p, m)
00425 #define CHMOD(f, p) chmod(f, p)
00426 #define FSTAT(h, b) fstat(h, b)
00427 #define PIPE(h) pipe(h)
00428 #define REMOVE(p) remove(p)
00429 #define RENAME(o, n) rename(o, n)
00430 #define STAT(p, b) stat(p, b)
00431 #define UNLINK(f) unlink(f)
00432 #define WRITE(f, b, n) write(f, b, n)
00433 #define READ(f, b, n) read(f, b, n)
00434 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
00435 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
00436 #define SYMLINK(a, b) symlink(a, b)
00437 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
00438 #define MUNMAP(s, l) munmap(s, l)
00439 #define STRERROR(i) strerror(i)
00440 #define RANDOM() random()
00441 #define READLINK(p, b, s) readlink(p, b, s)
00442 #define LSTAT(p, b) lstat(p, b)
00443 #define PRINTF printf
00444 #define FPRINTF fprintf
00445 #define VPRINTF(f, a) vprintf(f, a)
00446 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
00447 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
00448 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
00449 #define _REAL_SNPRINTF snprintf
00450 #define SPRINTF sprintf
00451 #define VSSCANF(s, f, a) vsscanf(s, f, a)
00452 #define SSCANF sscanf
00453 #define VFSCANF(s, f, a) vfscanf(s, f, a)
00454 #define VSCANF(f, a) vscanf(f, a)
00455 #define SCANF scanf
00456 #define FSCANF fscanf
00457 #define WAITPID(p, s, o) waitpid(p, s, o)
00458 #define ACCEPT(s, a, l) accept(s, a, l)
00459 #define BIND(s, n, l) bind(s, n, l)
00460 #define CONNECT(s, n, l) connect(s, n, l)
00461 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
00462 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
00463 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
00464 #define LISTEN(s, b) listen(s, b)
00465 #define RECV(s, b, l, f) recv(s, b, l, f)
00466 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
00467 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
00468 #define SEND(s, b, l, f) send(s, b, l, f)
00469 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
00470 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
00471 #define SHUTDOWN(s, h) shutdown(s, h)
00472 #define SOCKET(a, t, p) socket(a, t, p)
00473 #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
00474 #define GETHOSTBYNAME(n) gethostbyname(n)
00475 #else
00476 #define DIR_SEPARATOR '\\'
00477 #define DIR_SEPARATOR_STR "\\"
00478 #define NEWLINE "\r\n"
00479
00480 #ifdef ENABLE_NLS
00481 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
00482 #endif
00483 #define CREAT(p, m) _win_creat(p, m)
00484 #define FOPEN(f, m) _win_fopen(f, m)
00485 #define OPENDIR(d) _win_opendir(d)
00486 #define OPEN(f) _win_open(f)
00487 #define CHDIR(d) _win_chdir(d)
00488 #define CLOSE(f) _win_close(f)
00489 #define FSTAT(h, b) _win_fstat(h, b)
00490 #define RMDIR(f) _win_rmdir(f)
00491 #define ACCESS(p, m) _win_access(p, m)
00492 #define CHMOD(f, p) _win_chmod(f, p)
00493 #define PIPE(h) _win_pipe(h)
00494 #define RANDOM() _win_random()
00495 #define REMOVE(p) _win_remove(p)
00496 #define RENAME(o, n) _win_rename(o, n)
00497 #define STAT(p, b) _win_stat(p, b)
00498 #define UNLINK(f) _win_unlink(f)
00499 #define WRITE(f, b, n) _win_write(f, b, n)
00500 #define READ(f, b, n) _win_read(f, b, n)
00501 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
00502 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
00503 #define SYMLINK(a, b) _win_symlink(a, b)
00504 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
00505 #define MUNMAP(s, l) _win_munmap(s, l)
00506 #define STRERROR(i) _win_strerror(i)
00507 #define READLINK(p, b, s) _win_readlink(p, b, s)
00508 #define LSTAT(p, b) _win_lstat(p, b)
00509 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
00510 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
00511 #define VPRINTF(f, a) _win_vprintf(f, a)
00512 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
00513 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
00514 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
00515 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
00516 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
00517 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
00518 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
00519 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
00520 #define VSCANF(f, a) _win_vscanf(f, a)
00521 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
00522 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
00523 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
00524 #define ACCEPT(s, a, l) _win_accept(s, a, l)
00525 #define BIND(s, n, l) _win_bind(s, n, l)
00526 #define CONNECT(s, n, l) _win_connect(s, n, l)
00527 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
00528 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
00529 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
00530 #define LISTEN(s, b) _win_listen(s, b)
00531 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
00532 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
00533 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
00534 #define SEND(s, b, l, f) _win_send(s, b, l, f)
00535 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
00536 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
00537 #define SHUTDOWN(s, h) _win_shutdown(s, h)
00538 #define SOCKET(a, t, p) _win_socket(a, t, p)
00539 #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
00540 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
00541 #endif
00542
00543
00544 #ifdef __cplusplus
00545 }
00546 #endif
00547
00548
00549 #endif //_PLIBC_H_
00550
00551