plibc.h

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

Generated on Sun Jul 26 17:20:56 2009 for GNU libmicrohttpd by  doxygen 1.5.9