|
GNU libmicrohttpd
0.9.5
|
00001 /* 00002 This file is part of PlibC. 00003 (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors) 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 #include <stddef.h> 00040 00041 #ifdef Q_OS_WIN32 00042 #define WINDOWS 1 00043 #endif 00044 00045 #define HAVE_PLIBC_FD 0 00046 00047 #ifdef WINDOWS 00048 00049 #if ENABLE_NLS 00050 #include "langinfo.h" 00051 #endif 00052 00053 #include <ws2tcpip.h> 00054 #include <windows.h> 00055 #include <sys/types.h> 00056 #include <time.h> 00057 #include <stdio.h> 00058 #include <sys/types.h> 00059 #include <sys/stat.h> 00060 #include <dirent.h> 00061 #include <errno.h> 00062 #include <stdarg.h> 00063 00064 #define __BYTE_ORDER BYTE_ORDER 00065 #define __BIG_ENDIAN BIG_ENDIAN 00066 00067 /* Conflicts with our definitions */ 00068 #define __G_WIN32_H__ 00069 00070 /* Convert LARGE_INTEGER to double */ 00071 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ 00072 (double)((x).LowPart)) 00073 #ifndef __MINGW64__ 00074 struct stat64 00075 { 00076 _dev_t st_dev; 00077 _ino_t st_ino; 00078 _mode_t st_mode; 00079 short st_nlink; 00080 short st_uid; 00081 short st_gid; 00082 _dev_t st_rdev; 00083 __int64 st_size; 00084 __time64_t st_atime; 00085 __time64_t st_mtime; 00086 __time64_t st_ctime; 00087 }; 00088 #endif 00089 typedef unsigned int sa_family_t; 00090 00091 struct sockaddr_un { 00092 short sun_family; /*AF_UNIX*/ 00093 char sun_path[108]; /*path name */ 00094 }; 00095 00096 #ifndef pid_t 00097 #define pid_t DWORD 00098 #endif 00099 00100 #ifndef error_t 00101 #define error_t int 00102 #endif 00103 00104 #ifndef WEXITSTATUS 00105 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) 00106 #endif 00107 00108 #ifndef MSG_DONTWAIT 00109 #define MSG_DONTWAIT 0 00110 #endif 00111 00112 enum 00113 { 00114 _SC_PAGESIZE = 30, 00115 _SC_PAGE_SIZE = 30 00116 }; 00117 00118 /* Thanks to the Cygwin project */ 00119 #define ENOCSI 43 /* No CSI structure available */ 00120 #define EL2HLT 44 /* Level 2 halted */ 00121 #ifndef EDEADLK 00122 #define EDEADLK 45 /* Deadlock condition */ 00123 #endif 00124 #ifndef ENOLCK 00125 #define ENOLCK 46 /* No record locks available */ 00126 #endif 00127 #define EBADE 50 /* Invalid exchange */ 00128 #define EBADR 51 /* Invalid request descriptor */ 00129 #define EXFULL 52 /* Exchange full */ 00130 #define ENOANO 53 /* No anode */ 00131 #define EBADRQC 54 /* Invalid request code */ 00132 #define EBADSLT 55 /* Invalid slot */ 00133 #ifndef EDEADLOCK 00134 #define EDEADLOCK EDEADLK /* File locking deadlock error */ 00135 #endif 00136 #define EBFONT 57 /* Bad font file fmt */ 00137 #define ENOSTR 60 /* Device not a stream */ 00138 #define ENODATA 61 /* No data (for no delay io) */ 00139 #define ETIME 62 /* Timer expired */ 00140 #define ENOSR 63 /* Out of streams resources */ 00141 #define ENONET 64 /* Machine is not on the network */ 00142 #define ENOPKG 65 /* Package not installed */ 00143 #define EREMOTE 66 /* The object is remote */ 00144 #define ENOLINK 67 /* The link has been severed */ 00145 #define EADV 68 /* Advertise error */ 00146 #define ESRMNT 69 /* Srmount error */ 00147 #define ECOMM 70 /* Communication error on send */ 00148 #define EPROTO 71 /* Protocol error */ 00149 #define EMULTIHOP 74 /* Multihop attempted */ 00150 #define ELBIN 75 /* Inode is remote (not really error) */ 00151 #define EDOTDOT 76 /* Cross mount point (not really error) */ 00152 #define EBADMSG 77 /* Trying to read unreadable message */ 00153 #define ENOTUNIQ 80 /* Given log. name not unique */ 00154 #define EBADFD 81 /* f.d. invalid for this operation */ 00155 #define EREMCHG 82 /* Remote address changed */ 00156 #define ELIBACC 83 /* Can't access a needed shared lib */ 00157 #define ELIBBAD 84 /* Accessing a corrupted shared lib */ 00158 #define ELIBSCN 85 /* .lib section in a.out corrupted */ 00159 #define ELIBMAX 86 /* Attempting to link in too many libs */ 00160 #define ELIBEXEC 87 /* Attempting to exec a shared library */ 00161 #ifndef ENOSYS 00162 #define ENOSYS 88 /* Function not implemented */ 00163 #endif 00164 #define ENMFILE 89 /* No more files */ 00165 #ifndef ENOTEMPTY 00166 #define ENOTEMPTY 90 /* Directory not empty */ 00167 #endif 00168 #ifndef ENAMETOOLONG 00169 #define ENAMETOOLONG 91 /* File or path name too long */ 00170 #endif 00171 #define ELOOP 92 /* Too many symbolic links */ 00172 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 00173 #define EPFNOSUPPORT 96 /* Protocol family not supported */ 00174 #define ECONNRESET 104 /* Connection reset by peer */ 00175 #define ENOBUFS 105 /* No buffer space available */ 00176 #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ 00177 #define EPROTOTYPE 107 /* Protocol wrong type for socket */ 00178 #define ENOTSOCK 108 /* Socket operation on non-socket */ 00179 #define ENOPROTOOPT 109 /* Protocol not available */ 00180 #define ESHUTDOWN 110 /* Can't send after socket shutdown */ 00181 #define ECONNREFUSED 111 /* Connection refused */ 00182 #define EADDRINUSE 112 /* Address already in use */ 00183 #define ECONNABORTED 113 /* Connection aborted */ 00184 #define ENETUNREACH 114 /* Network is unreachable */ 00185 #define ENETDOWN 115 /* Network interface is not configured */ 00186 #ifndef ETIMEDOUT 00187 #define ETIMEDOUT 116 /* Connection timed out */ 00188 #endif 00189 #define EHOSTDOWN 117 /* Host is down */ 00190 #define EHOSTUNREACH 118 /* Host is unreachable */ 00191 #define EINPROGRESS 119 /* Connection already in progress */ 00192 #define EALREADY 120 /* Socket already connected */ 00193 #define EDESTADDRREQ 121 /* Destination address required */ 00194 #define EMSGSIZE 122 /* Message too long */ 00195 #define EPROTONOSUPPORT 123 /* Unknown protocol */ 00196 #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ 00197 #define EADDRNOTAVAIL 125 /* Address not available */ 00198 #define ENETRESET 126 /* Connection aborted by network */ 00199 #define EISCONN 127 /* Socket is already connected */ 00200 #define ENOTCONN 128 /* Socket is not connected */ 00201 #define ETOOMANYREFS 129 /* Too many references: cannot splice */ 00202 #define EPROCLIM 130 /* Too many processes */ 00203 #define EUSERS 131 /* Too many users */ 00204 #define EDQUOT 132 /* Disk quota exceeded */ 00205 #define ESTALE 133 /* Unknown error */ 00206 #ifndef ENOTSUP 00207 #define ENOTSUP 134 /* Not supported */ 00208 #endif 00209 #define ENOMEDIUM 135 /* No medium (in tape drive) */ 00210 #define ENOSHARE 136 /* No such host or network path */ 00211 #define ECASECLASH 137 /* Filename exists with different case */ 00212 #define EWOULDBLOCK EAGAIN /* Operation would block */ 00213 #define EOVERFLOW 139 /* Value too large for defined data type */ 00214 00215 #undef HOST_NOT_FOUND 00216 #define HOST_NOT_FOUND 1 00217 #undef TRY_AGAIN 00218 #define TRY_AGAIN 2 00219 #undef NO_RECOVERY 00220 #define NO_RECOVERY 3 00221 #undef NO_ADDRESS 00222 #define NO_ADDRESS 4 00223 00224 #define PROT_READ 0x1 00225 #define PROT_WRITE 0x2 00226 #define MAP_SHARED 0x1 00227 #define MAP_PRIVATE 0x2 /* unsupported */ 00228 #define MAP_FIXED 0x10 00229 #define MAP_ANONYMOUS 0x20 /* unsupported */ 00230 #define MAP_FAILED ((void *)-1) 00231 00232 #define MS_ASYNC 1 /* sync memory asynchronously */ 00233 #define MS_INVALIDATE 2 /* invalidate the caches */ 00234 #define MS_SYNC 4 /* synchronous memory sync */ 00235 00236 struct statfs 00237 { 00238 long f_type; /* type of filesystem (see below) */ 00239 long f_bsize; /* optimal transfer block size */ 00240 long f_blocks; /* total data blocks in file system */ 00241 long f_bfree; /* free blocks in fs */ 00242 long f_bavail; /* free blocks avail to non-superuser */ 00243 long f_files; /* total file nodes in file system */ 00244 long f_ffree; /* free file nodes in fs */ 00245 long f_fsid; /* file system id */ 00246 long f_namelen; /* maximum length of filenames */ 00247 long f_spare[6]; /* spare for later */ 00248 }; 00249 00250 extern const struct in6_addr in6addr_any; /* :: */ 00251 extern const struct in6_addr in6addr_loopback; /* ::1 */ 00252 00253 /* Taken from the Wine project <http://www.winehq.org> 00254 /wine/include/winternl.h */ 00255 enum SYSTEM_INFORMATION_CLASS 00256 { 00257 SystemBasicInformation = 0, 00258 Unknown1, 00259 SystemPerformanceInformation = 2, 00260 SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ 00261 Unknown4, 00262 SystemProcessInformation = 5, 00263 Unknown6, 00264 Unknown7, 00265 SystemProcessorPerformanceInformation = 8, 00266 Unknown9, 00267 Unknown10, 00268 SystemDriverInformation, 00269 Unknown12, 00270 Unknown13, 00271 Unknown14, 00272 Unknown15, 00273 SystemHandleList, 00274 Unknown17, 00275 Unknown18, 00276 Unknown19, 00277 Unknown20, 00278 SystemCacheInformation, 00279 Unknown22, 00280 SystemInterruptInformation = 23, 00281 SystemExceptionInformation = 33, 00282 SystemRegistryQuotaInformation = 37, 00283 SystemLookasideInformation = 45 00284 }; 00285 00286 typedef struct 00287 { 00288 LARGE_INTEGER IdleTime; 00289 LARGE_INTEGER KernelTime; 00290 LARGE_INTEGER UserTime; 00291 LARGE_INTEGER Reserved1[2]; 00292 ULONG Reserved2; 00293 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; 00294 00295 #define sleep(secs) (Sleep(secs * 1000)) 00296 00297 /*********************** statfs *****************************/ 00298 /* fake block size */ 00299 #define FAKED_BLOCK_SIZE 512 00300 00301 /* linux-compatible values for fs type */ 00302 #define MSDOS_SUPER_MAGIC 0x4d44 00303 #define NTFS_SUPER_MAGIC 0x5346544E 00304 00305 /*********************** End of statfs ***********************/ 00306 00307 #define SHUT_RDWR SD_BOTH 00308 00309 /* Operations for flock() */ 00310 #define LOCK_SH 1 /* shared lock */ 00311 #define LOCK_EX 2 /* exclusive lock */ 00312 #define LOCK_NB 4 /* or'd with one of the above to prevent 00313 blocking */ 00314 #define LOCK_UN 8 /* remove lock */ 00315 00316 /* Not supported under MinGW */ 00317 #define S_IRGRP 0 00318 #define S_IWGRP 0 00319 #define S_IROTH 0 00320 #define S_IXGRP 0 00321 #define S_IWOTH 0 00322 #define S_IXOTH 0 00323 #define S_ISUID 0 00324 #define S_ISGID 0 00325 #define S_ISVTX 0 00326 #define S_IRWXG 0 00327 #define S_IRWXO 0 00328 00329 #define SHUT_WR SD_SEND 00330 #define SHUT_RD SD_RECEIVE 00331 #define SHUT_RDWR SD_BOTH 00332 00333 #define SIGKILL 9 00334 #define SIGTERM 15 00335 00336 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) 00337 00338 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); 00339 BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest); 00340 BOOL _plibc_DereferenceShortcut(char *pszShortcut); 00341 BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut); 00342 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags); 00343 wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags); 00344 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags); 00345 wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags); 00346 00347 long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, 00348 char *pszBuffer, long *pdLength); 00349 long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey, 00350 wchar_t *pszBuffer, long *pdLength); 00351 00352 BOOL __win_IsHandleMarkedAsBlocking(int hHandle); 00353 void __win_SetHandleBlockingMode(int s, BOOL bBlocking); 00354 void __win_DiscardHandleBlockingMode(int s); 00355 int _win_isSocketValid(int s); 00356 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows); 00357 int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows); 00358 00359 int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows); 00360 int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks); 00361 00362 unsigned plibc_get_handle_count(); 00363 00364 typedef void (*TPanicProc) (int, char *); 00365 void plibc_set_panic_proc(TPanicProc proc); 00366 00367 int flock(int fd, int operation); 00368 int fsync(int fildes); 00369 int inet_pton(int af, const char *src, void *dst); 00370 int inet_pton4(const char *src, u_char *dst, int pton); 00371 #if USE_IPV6 00372 int inet_pton6(const char *src, u_char *dst); 00373 #endif 00374 int truncate(const char *fname, int distance); 00375 int statfs(const char *path, struct statfs *buf); 00376 const char *hstrerror(int err); 00377 int mkstemp(char *tmplate); 00378 char *strptime (const char *buf, const char *format, struct tm *tm); 00379 const char *inet_ntop(int af, const void *src, char *dst, size_t size); 00380 #ifndef gmtime_r 00381 struct tm *gmtime_r(const time_t *clock, struct tm *result); 00382 #endif 00383 00384 int plibc_init(char *pszOrg, char *pszApp); 00385 int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode); 00386 void plibc_shutdown(); 00387 int plibc_initialized(); 00388 00389 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine); 00390 void SetErrnoFromWinsockError(long lWinError); 00391 void SetHErrnoFromWinError(long lWinError); 00392 void SetErrnoFromHRESULT(HRESULT hRes); 00393 int GetErrnoFromWinsockError(long lWinError); 00394 FILE *_win_fopen(const char *filename, const char *mode); 00395 int _win_fclose(FILE *); 00396 DIR *_win_opendir(const char *dirname); 00397 struct dirent *_win_readdir(DIR *dirp); 00398 int _win_closedir(DIR *dirp); 00399 int _win_open(const char *filename, int oflag, ...); 00400 #ifdef ENABLE_NLS 00401 char *_win_bindtextdomain(const char *domainname, const char *dirname); 00402 #endif 00403 int _win_chdir(const char *path); 00404 int _win_close(int fd); 00405 int _win_creat(const char *path, mode_t mode); 00406 char *_win_ctime(const time_t *clock); 00407 char *_win_ctime_r(const time_t *clock, char *buf); 00408 int _win_fstat(int handle, struct stat *buffer); 00409 int _win_ftruncate(int fildes, off_t length); 00410 void _win_gettimeofday(struct timeval *tp, void *tzp); 00411 int _win_kill(pid_t pid, int sig); 00412 int _win_pipe(int *phandles); 00413 int _win_rmdir(const char *path); 00414 int _win_access( const char *path, int mode ); 00415 int _win_chmod(const char *filename, int pmode); 00416 char *realpath(const char *file_name, char *resolved_name); 00417 long _win_random(void); 00418 void _win_srandom(unsigned int seed); 00419 int _win_remove(const char *path); 00420 int _win_rename(const char *oldname, const char *newname); 00421 int _win_stat(const char *path, struct stat *buffer); 00422 int _win_stat64(const char *path, struct stat64 *buffer); 00423 long _win_sysconf(int name); 00424 int _win_unlink(const char *filename); 00425 int _win_write(int fildes, const void *buf, size_t nbyte); 00426 int _win_read(int fildes, void *buf, size_t nbyte); 00427 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); 00428 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream ); 00429 int _win_symlink(const char *path1, const char *path2); 00430 void *_win_mmap(void *start, size_t len, int access, int flags, int fd, 00431 unsigned long long offset); 00432 int _win_msync(void *start, size_t length, int flags); 00433 int _win_munmap(void *start, size_t length); 00434 int _win_lstat(const char *path, struct stat *buf); 00435 int _win_lstat64(const char *path, struct stat64 *buf); 00436 int _win_readlink(const char *path, char *buf, size_t bufsize); 00437 int _win_accept(int s, struct sockaddr *addr, int *addrlen); 00438 00439 int _win_printf(const char *format,...); 00440 int _win_wprintf(const wchar_t *format, ...); 00441 00442 int _win_fprintf(FILE *f,const char *format,...); 00443 int _win_fwprintf(FILE *f,const wchar_t *format, ...); 00444 00445 int _win_vprintf(const char *format, va_list ap); 00446 int _win_vfwprintf(FILE *stream, const wchar_t *format, va_list arg_ptr); 00447 00448 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr); 00449 int _win_vwprintf(const wchar_t *format, va_list ap); 00450 00451 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr); 00452 int _win_vswprintf(wchar_t *dest, const wchar_t *format, va_list arg_ptr); 00453 00454 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr); 00455 int _win_vsnwprintf(wchar_t* wstr, size_t size, const wchar_t *format, va_list arg_ptr); 00456 00457 int _win_snprintf(char *str,size_t size,const char *format,...); 00458 int _win_snwprintf(wchar_t *str, size_t size, const wchar_t *format, ...); 00459 00460 int _win_sprintf(char *dest,const char *format,...); 00461 int _win_swprintf(wchar_t *dest, const wchar_t *format, ...); 00462 00463 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr); 00464 int _win_vswscanf(const wchar_t* wstr, const wchar_t* format, va_list arg_ptr); 00465 00466 int _win_sscanf(const char *str, const char *format, ...); 00467 int _win_swscanf(const wchar_t *wstr, const wchar_t *format, ...); 00468 00469 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr); 00470 int _win_vfwscanf(FILE *stream, const wchar_t *format, va_list arg_ptr); 00471 00472 int _win_vscanf(const char *format, va_list arg_ptr); 00473 int _win_vwscanf(const wchar_t *format, va_list arg_ptr); 00474 00475 int _win_scanf(const char *format, ...); 00476 int _win_wscanf(const wchar_t *format, ...); 00477 00478 int _win_fscanf(FILE *stream, const char *format, ...); 00479 int _win_fwscanf(FILE *stream, const wchar_t *format, ...); 00480 00481 00482 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options); 00483 int _win_bind(int s, const struct sockaddr *name, int namelen); 00484 int _win_connect(int s,const struct sockaddr *name, int namelen); 00485 int _win_getpeername(int s, struct sockaddr *name, 00486 int *namelen); 00487 int _win_getsockname(int s, struct sockaddr *name, 00488 int *namelen); 00489 int _win_getsockopt(int s, int level, int optname, char *optval, 00490 int *optlen); 00491 int _win_listen(int s, int backlog); 00492 int _win_recv(int s, char *buf, int len, int flags); 00493 int _win_recvfrom(int s, void *buf, int len, int flags, 00494 struct sockaddr *from, int *fromlen); 00495 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, 00496 const struct timeval *tv); 00497 int _win_send(int s, const char *buf, int len, int flags); 00498 int _win_sendto(int s, const char *buf, int len, int flags, 00499 const struct sockaddr *to, int tolen); 00500 int _win_setsockopt(int s, int level, int optname, const void *optval, 00501 int optlen); 00502 int _win_shutdown(int s, int how); 00503 int _win_socket(int af, int type, int protocol); 00504 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type); 00505 struct hostent *_win_gethostbyname(const char *name); 00506 struct hostent *gethostbyname2(const char *name, int af); 00507 char *_win_strerror(int errnum); 00508 int IsWinNT(); 00509 char *index(const char *s, int c); 00510 00511 #if !HAVE_STRNDUP 00512 char *strndup (const char *s, size_t n); 00513 #endif 00514 #if !HAVE_STRNLEN 00515 size_t strnlen (const char *str, size_t maxlen); 00516 #endif 00517 char *stpcpy(char *dest, const char *src); 00518 char *strcasestr(const char *haystack_start, const char *needle_start); 00519 #ifndef __MINGW64__ 00520 #define strcasecmp(a, b) stricmp(a, b) 00521 #define wcscasecmp(a, b) wcsicmp(a, b) 00522 #define strncasecmp(a, b, c) strnicmp(a, b, c) 00523 #define wcsncasecmp(a, b, c) wcsnicmp(a, b, c) 00524 #endif 00525 #endif /* WINDOWS */ 00526 00527 #ifndef WINDOWS 00528 #define DIR_SEPARATOR '/' 00529 #define DIR_SEPARATOR_STR "/" 00530 #define PATH_SEPARATOR ':' 00531 #define PATH_SEPARATOR_STR ":" 00532 #define NEWLINE "\n" 00533 00534 #ifdef ENABLE_NLS 00535 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) 00536 #endif 00537 #define CREAT(p, m) creat(p, m) 00538 #define PLIBC_CTIME(c) ctime(c) 00539 #define CTIME_R(c, b) ctime_r(c, b) 00540 #undef FOPEN 00541 #define FOPEN(f, m) fopen(f, m) 00542 #define FCLOSE(f) fclose(f) 00543 #define FTRUNCATE(f, l) ftruncate(f, l) 00544 #define OPENDIR(d) opendir(d) 00545 #define CLOSEDIR(d) closedir(d) 00546 #define READDIR(d) readdir(d) 00547 #define OPEN open 00548 #define CHDIR(d) chdir(d) 00549 #define CLOSE(f) close(f) 00550 #define LSEEK(f, o, w) lseek(f, o, w) 00551 #define RMDIR(f) rmdir(f) 00552 #define ACCESS(p, m) access(p, m) 00553 #define CHMOD(f, p) chmod(f, p) 00554 #define FSTAT(h, b) fstat(h, b) 00555 #define PLIBC_KILL(p, s) kill(p, s) 00556 #define PIPE(h) pipe(h) 00557 #define REMOVE(p) remove(p) 00558 #define RENAME(o, n) rename(o, n) 00559 #define STAT(p, b) stat(p, b) 00560 #define STAT64(p, b) stat64(p, b) 00561 #define SYSCONF(n) sysconf(n) 00562 #define UNLINK(f) unlink(f) 00563 #define WRITE(f, b, n) write(f, b, n) 00564 #define READ(f, b, n) read(f, b, n) 00565 #define GN_FREAD(b, s, c, f) fread(b, s, c, f) 00566 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) 00567 #define SYMLINK(a, b) symlink(a, b) 00568 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) 00569 #define MKFIFO(p, m) mkfifo(p, m) 00570 #define MSYNC(s, l, f) msync(s, l, f) 00571 #define MUNMAP(s, l) munmap(s, l) 00572 #define STRERROR(i) strerror(i) 00573 #define RANDOM() random() 00574 #define SRANDOM(s) srandom(s) 00575 #define READLINK(p, b, s) readlink(p, b, s) 00576 #define LSTAT(p, b) lstat(p, b) 00577 #define LSTAT64(p, b) lstat64(p, b) 00578 #define PRINTF printf 00579 #define FPRINTF fprintf 00580 #define VPRINTF(f, a) vprintf(f, a) 00581 #define VFPRINTF(s, f, a) vfprintf(s, f, a) 00582 #define VSPRINTF(d, f, a) vsprintf(d, f, a) 00583 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) 00584 #define _REAL_SNPRINTF snprintf 00585 #define SPRINTF sprintf 00586 #define VSSCANF(s, f, a) vsscanf(s, f, a) 00587 #define SSCANF sscanf 00588 #define VFSCANF(s, f, a) vfscanf(s, f, a) 00589 #define VSCANF(f, a) vscanf(f, a) 00590 #define SCANF scanf 00591 #define FSCANF fscanf 00592 #define WAITPID(p, s, o) waitpid(p, s, o) 00593 #define ACCEPT(s, a, l) accept(s, a, l) 00594 #define BIND(s, n, l) bind(s, n, l) 00595 #define CONNECT(s, n, l) connect(s, n, l) 00596 #define GETPEERNAME(s, n, l) getpeername(s, n, l) 00597 #define GETSOCKNAME(s, n, l) getsockname(s, n, l) 00598 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) 00599 #define LISTEN(s, b) listen(s, b) 00600 #define RECV(s, b, l, f) recv(s, b, l, f) 00601 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) 00602 #define SELECT(n, r, w, e, t) select(n, r, w, e, t) 00603 #define SEND(s, b, l, f) send(s, b, l, f) 00604 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) 00605 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) 00606 #define SHUTDOWN(s, h) shutdown(s, h) 00607 #define SOCKET(a, t, p) socket(a, t, p) 00608 #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) 00609 #define GETHOSTBYNAME(n) gethostbyname(n) 00610 #define GETTIMEOFDAY(t, n) gettimeofday(t, n) 00611 #define INSQUE(e, p) insque(e, p) 00612 #define REMQUE(e) remque(e) 00613 #define HSEARCH(i, a) hsearch(i, a) 00614 #define HCREATE(n) hcreate(n) 00615 #define HDESTROY() hdestroy() 00616 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h) 00617 #define HCREATE_R(n, h) hcreate_r(n, h) 00618 #define HDESTROY_R(h) hdestroy_r(h) 00619 #define TSEARCH(k, r, c) tsearch(k, r, c) 00620 #define TFIND(k, r, c) tfind(k, r, c) 00621 #define TDELETE(k, r, c) tdelete(k, r, c) 00622 #define TWALK(r, a) twalk(r, a) 00623 #define TDESTROY(r, f) tdestroy(r, f) 00624 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) 00625 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) 00626 #else 00627 #define DIR_SEPARATOR '\\' 00628 #define DIR_SEPARATOR_STR "\\" 00629 #define PATH_SEPARATOR ';' 00630 #define PATH_SEPARATOR_STR ";" 00631 #define NEWLINE "\r\n" 00632 00633 #ifdef ENABLE_NLS 00634 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) 00635 #endif 00636 #define CREAT(p, m) _win_creat(p, m) 00637 #define PLIBC_CTIME(c) _win_ctime(c) 00638 #define CTIME_R(c, b) _win_ctime_r(c, b) 00639 #define FOPEN(f, m) _win_fopen(f, m) 00640 #define FCLOSE(f) _win_fclose(f) 00641 #define FTRUNCATE(f, l) _win_ftruncate(f, l) 00642 #define OPENDIR(d) _win_opendir(d) 00643 #define CLOSEDIR(d) _win_closedir(d) 00644 #define READDIR(d) _win_readdir(d) 00645 #define OPEN _win_open 00646 #define CHDIR(d) _win_chdir(d) 00647 #define CLOSE(f) _win_close(f) 00648 #define PLIBC_KILL(p, s) _win_kill(p, s) 00649 #define LSEEK(f, o, w) _win_lseek(f, o, w) 00650 #define FSTAT(h, b) _win_fstat(h, b) 00651 #define RMDIR(f) _win_rmdir(f) 00652 #define ACCESS(p, m) _win_access(p, m) 00653 #define CHMOD(f, p) _win_chmod(f, p) 00654 #define PIPE(h) _win_pipe(h) 00655 #define RANDOM() _win_random() 00656 #define SRANDOM(s) _win_srandom(s) 00657 #define REMOVE(p) _win_remove(p) 00658 #define RENAME(o, n) _win_rename(o, n) 00659 #define STAT(p, b) _win_stat(p, b) 00660 #define STAT64(p, b) _win_stat64(p, b) 00661 #define SYSCONF(n) _win_sysconf(n) 00662 #define UNLINK(f) _win_unlink(f) 00663 #define WRITE(f, b, n) _win_write(f, b, n) 00664 #define READ(f, b, n) _win_read(f, b, n) 00665 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) 00666 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) 00667 #define SYMLINK(a, b) _win_symlink(a, b) 00668 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) 00669 #define MKFIFO(p, m) _win_mkfifo(p, m) 00670 #define MSYNC(s, l, f) _win_msync(s, l, f) 00671 #define MUNMAP(s, l) _win_munmap(s, l) 00672 #define STRERROR(i) _win_strerror(i) 00673 #define READLINK(p, b, s) _win_readlink(p, b, s) 00674 #define LSTAT(p, b) _win_lstat(p, b) 00675 #define LSTAT64(p, b) _win_lstat64(p, b) 00676 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) 00677 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) 00678 #define VPRINTF(f, a) _win_vprintf(f, a) 00679 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) 00680 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) 00681 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) 00682 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) 00683 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) 00684 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) 00685 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) 00686 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) 00687 #define VSCANF(f, a) _win_vscanf(f, a) 00688 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) 00689 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) 00690 #define WAITPID(p, s, o) _win_waitpid(p, s, o) 00691 #define ACCEPT(s, a, l) _win_accept(s, a, l) 00692 #define BIND(s, n, l) _win_bind(s, n, l) 00693 #define CONNECT(s, n, l) _win_connect(s, n, l) 00694 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) 00695 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) 00696 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) 00697 #define LISTEN(s, b) _win_listen(s, b) 00698 #define RECV(s, b, l, f) _win_recv(s, b, l, f) 00699 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) 00700 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) 00701 #define SEND(s, b, l, f) _win_send(s, b, l, f) 00702 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) 00703 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) 00704 #define SHUTDOWN(s, h) _win_shutdown(s, h) 00705 #define SOCKET(a, t, p) _win_socket(a, t, p) 00706 #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) 00707 #define GETHOSTBYNAME(n) _win_gethostbyname(n) 00708 #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n) 00709 #define INSQUE(e, p) _win_insque(e, p) 00710 #define REMQUE(e) _win_remque(e) 00711 #define HSEARCH(i, a) _win_hsearch(i, a) 00712 #define HCREATE(n) _win_hcreate(n) 00713 #define HDESTROY() _win_hdestroy() 00714 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h) 00715 #define HCREATE_R(n, h) _win_hcreate_r(n, h) 00716 #define HDESTROY_R(h) _win_hdestroy_r(h) 00717 #define TSEARCH(k, r, c) _win_tsearch(k, r, c) 00718 #define TFIND(k, r, c) _win_tfind(k, r, c) 00719 #define TDELETE(k, r, c) _win_tdelete(k, r, c) 00720 #define TWALK(r, a) _win_twalk(r, a) 00721 #define TDESTROY(r, f) _win_tdestroy(r, f) 00722 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) 00723 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) 00724 #endif 00725 00726 /* search.h */ 00727 00728 /* Prototype structure for a linked-list data structure. 00729 This is the type used by the `insque' and `remque' functions. */ 00730 00731 struct PLIBC_SEARCH_QELEM 00732 { 00733 struct qelem *q_forw; 00734 struct qelem *q_back; 00735 char q_data[1]; 00736 }; 00737 00738 00739 /* Insert ELEM into a doubly-linked list, after PREV. */ 00740 void _win_insque (void *__elem, void *__prev); 00741 00742 /* Unlink ELEM from the doubly-linked list that it is in. */ 00743 void _win_remque (void *__elem); 00744 00745 00746 /* For use with hsearch(3). */ 00747 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *); 00748 00749 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t; 00750 00751 /* Action which shall be performed in the call the hsearch. */ 00752 typedef enum 00753 { 00754 PLIBC_SEARCH_FIND, 00755 PLIBC_SEARCH_ENTER 00756 } 00757 PLIBC_SEARCH_ACTION; 00758 00759 typedef struct PLIBC_SEARCH_entry 00760 { 00761 char *key; 00762 void *data; 00763 } 00764 PLIBC_SEARCH_ENTRY; 00765 00766 /* The reentrant version has no static variables to maintain the state. 00767 Instead the interface of all functions is extended to take an argument 00768 which describes the current status. */ 00769 typedef struct _PLIBC_SEARCH_ENTRY 00770 { 00771 unsigned int used; 00772 PLIBC_SEARCH_ENTRY entry; 00773 } 00774 _PLIBC_SEARCH_ENTRY; 00775 00776 00777 /* Family of hash table handling functions. The functions also 00778 have reentrant counterparts ending with _r. The non-reentrant 00779 functions all work on a signle internal hashing table. */ 00780 00781 /* Search for entry matching ITEM.key in internal hash table. If 00782 ACTION is `FIND' return found entry or signal error by returning 00783 NULL. If ACTION is `ENTER' replace existing data (if any) with 00784 ITEM.data. */ 00785 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action); 00786 00787 /* Create a new hashing table which will at most contain NEL elements. */ 00788 int _win_hcreate (size_t __nel); 00789 00790 /* Destroy current internal hashing table. */ 00791 void _win_hdestroy (void); 00792 00793 /* Data type for reentrant functions. */ 00794 struct PLIBC_SEARCH_hsearch_data 00795 { 00796 struct _PLIBC_SEARCH_ENTRY *table; 00797 unsigned int size; 00798 unsigned int filled; 00799 }; 00800 00801 /* Reentrant versions which can handle multiple hashing tables at the 00802 same time. */ 00803 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval, 00804 struct PLIBC_SEARCH_hsearch_data *__htab); 00805 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab); 00806 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab); 00807 00808 00809 /* The tsearch routines are very interesting. They make many 00810 assumptions about the compiler. It assumes that the first field 00811 in node must be the "key" field, which points to the datum. 00812 Everything depends on that. */ 00813 /* For tsearch */ 00814 typedef enum 00815 { 00816 PLIBC_SEARCH_preorder, 00817 PLIBC_SEARCH_postorder, 00818 PLIBC_SEARCH_endorder, 00819 PLIBC_SEARCH_leaf 00820 } 00821 PLIBC_SEARCH_VISIT; 00822 00823 /* Search for an entry matching the given KEY in the tree pointed to 00824 by *ROOTP and insert a new element if not found. */ 00825 void *_win_tsearch (__const void *__key, void **__rootp, 00826 PLIBC_SEARCH__compar_fn_t __compar); 00827 00828 /* Search for an entry matching the given KEY in the tree pointed to 00829 by *ROOTP. If no matching entry is available return NULL. */ 00830 void *_win_tfind (__const void *__key, void *__const *__rootp, 00831 PLIBC_SEARCH__compar_fn_t __compar); 00832 00833 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */ 00834 void *_win_tdelete (__const void *__restrict __key, 00835 void **__restrict __rootp, 00836 PLIBC_SEARCH__compar_fn_t __compar); 00837 00838 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value, 00839 int __level); 00840 00841 /* Walk through the whole tree and call the ACTION callback for every node 00842 or leaf. */ 00843 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action); 00844 00845 /* Callback type for function to free a tree node. If the keys are atomic 00846 data this function should do nothing. */ 00847 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep); 00848 00849 /* Destroy the whole tree, call FREEFCT for each node or leaf. */ 00850 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct); 00851 00852 00853 /* Perform linear search for KEY by comparing by COMPAR in an array 00854 [BASE,BASE+NMEMB*SIZE). */ 00855 void *_win_lfind (__const void *__key, __const void *__base, 00856 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); 00857 00858 /* Perform linear search for KEY by comparing by COMPAR function in 00859 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */ 00860 void *_win_lsearch (__const void *__key, void *__base, 00861 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); 00862 00863 00864 #ifdef __cplusplus 00865 } 00866 #endif 00867 00868 00869 #endif //_PLIBC_H_ 00870 00871 /* end of plibc.h */