2 This file is part of PlibC.
3 (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * @file include/plibc.h
23 * @attention This file is usually not installed under Unix,
24 * so ship it with your application
25 * @version $Revision: 58 $
45 #define HAVE_PLIBC_FD 0
55 #include <sys/types.h>
58 #include <sys/types.h>
64 #define __BYTE_ORDER BYTE_ORDER
65 #define __BIG_ENDIAN BIG_ENDIAN
67 /* Conflicts with our definitions */
70 /* Convert LARGE_INTEGER to double */
71 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
72 (double)((x).LowPart))
89 typedef unsigned int sa_family_t;
92 short sun_family; /*AF_UNIX*/
93 char sun_path[108]; /*path name */
105 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
109 #define MSG_DONTWAIT 0
112 /* Thanks to the Cygwin project */
113 #define ENOCSI 43 /* No CSI structure available */
114 #define EL2HLT 44 /* Level 2 halted */
116 #define EDEADLK 45 /* Deadlock condition */
119 #define ENOLCK 46 /* No record locks available */
121 #define EBADE 50 /* Invalid exchange */
122 #define EBADR 51 /* Invalid request descriptor */
123 #define EXFULL 52 /* Exchange full */
124 #define ENOANO 53 /* No anode */
125 #define EBADRQC 54 /* Invalid request code */
126 #define EBADSLT 55 /* Invalid slot */
128 #define EDEADLOCK EDEADLK /* File locking deadlock error */
130 #define EBFONT 57 /* Bad font file fmt */
131 #define ENOSTR 60 /* Device not a stream */
132 #define ENODATA 61 /* No data (for no delay io) */
133 #define ETIME 62 /* Timer expired */
134 #define ENOSR 63 /* Out of streams resources */
135 #define ENONET 64 /* Machine is not on the network */
136 #define ENOPKG 65 /* Package not installed */
137 #define EREMOTE 66 /* The object is remote */
138 #define ENOLINK 67 /* The link has been severed */
139 #define EADV 68 /* Advertise error */
140 #define ESRMNT 69 /* Srmount error */
141 #define ECOMM 70 /* Communication error on send */
142 #define EPROTO 71 /* Protocol error */
143 #define EMULTIHOP 74 /* Multihop attempted */
144 #define ELBIN 75 /* Inode is remote (not really error) */
145 #define EDOTDOT 76 /* Cross mount point (not really error) */
146 #define EBADMSG 77 /* Trying to read unreadable message */
147 #define ENOTUNIQ 80 /* Given log. name not unique */
148 #define EBADFD 81 /* f.d. invalid for this operation */
149 #define EREMCHG 82 /* Remote address changed */
150 #define ELIBACC 83 /* Can't access a needed shared lib */
151 #define ELIBBAD 84 /* Accessing a corrupted shared lib */
152 #define ELIBSCN 85 /* .lib section in a.out corrupted */
153 #define ELIBMAX 86 /* Attempting to link in too many libs */
154 #define ELIBEXEC 87 /* Attempting to exec a shared library */
156 #define ENOSYS 88 /* Function not implemented */
158 #define ENMFILE 89 /* No more files */
160 #define ENOTEMPTY 90 /* Directory not empty */
163 #define ENAMETOOLONG 91 /* File or path name too long */
165 #define ELOOP 92 /* Too many symbolic links */
166 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
167 #define EPFNOSUPPORT 96 /* Protocol family not supported */
168 #define ECONNRESET 104 /* Connection reset by peer */
169 #define ENOBUFS 105 /* No buffer space available */
170 #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
171 #define EPROTOTYPE 107 /* Protocol wrong type for socket */
172 #define ENOTSOCK 108 /* Socket operation on non-socket */
173 #define ENOPROTOOPT 109 /* Protocol not available */
174 #define ESHUTDOWN 110 /* Can't send after socket shutdown */
175 #define ECONNREFUSED 111 /* Connection refused */
176 #define EADDRINUSE 112 /* Address already in use */
177 #define ECONNABORTED 113 /* Connection aborted */
178 #define ENETUNREACH 114 /* Network is unreachable */
179 #define ENETDOWN 115 /* Network interface is not configured */
181 #define ETIMEDOUT 116 /* Connection timed out */
183 #define EHOSTDOWN 117 /* Host is down */
184 #define EHOSTUNREACH 118 /* Host is unreachable */
185 #define EINPROGRESS 119 /* Connection already in progress */
186 #define EALREADY 120 /* Socket already connected */
187 #define EDESTADDRREQ 121 /* Destination address required */
188 #define EMSGSIZE 122 /* Message too long */
189 #define EPROTONOSUPPORT 123 /* Unknown protocol */
190 #define ESOCKTNOSUPPORT 124 /* Socket type not supported */
191 #define EADDRNOTAVAIL 125 /* Address not available */
192 #define ENETRESET 126 /* Connection aborted by network */
193 #define EISCONN 127 /* Socket is already connected */
194 #define ENOTCONN 128 /* Socket is not connected */
195 #define ETOOMANYREFS 129 /* Too many references: cannot splice */
196 #define EPROCLIM 130 /* Too many processes */
197 #define EUSERS 131 /* Too many users */
198 #define EDQUOT 132 /* Disk quota exceeded */
199 #define ESTALE 133 /* Unknown error */
201 #define ENOTSUP 134 /* Not supported */
203 #define ENOMEDIUM 135 /* No medium (in tape drive) */
204 #define ENOSHARE 136 /* No such host or network path */
205 #define ECASECLASH 137 /* Filename exists with different case */
206 #define EWOULDBLOCK EAGAIN /* Operation would block */
207 #define EOVERFLOW 139 /* Value too large for defined data type */
209 #undef HOST_NOT_FOUND
210 #define HOST_NOT_FOUND 1
214 #define NO_RECOVERY 3
218 #define PROT_READ 0x1
219 #define PROT_WRITE 0x2
220 #define MAP_SHARED 0x1
221 #define MAP_PRIVATE 0x2 /* unsupported */
222 #define MAP_FIXED 0x10
223 #define MAP_FAILED ((void *)-1)
227 long f_type; /* type of filesystem (see below) */
228 long f_bsize; /* optimal transfer block size */
229 long f_blocks; /* total data blocks in file system */
230 long f_bfree; /* free blocks in fs */
231 long f_bavail; /* free blocks avail to non-superuser */
232 long f_files; /* total file nodes in file system */
233 long f_ffree; /* free file nodes in fs */
234 long f_fsid; /* file system id */
235 long f_namelen; /* maximum length of filenames */
236 long f_spare[6]; /* spare for later */
239 extern const struct in6_addr in6addr_any; /* :: */
240 extern const struct in6_addr in6addr_loopback; /* ::1 */
242 /* Taken from the Wine project <http://www.winehq.org>
243 /wine/include/winternl.h */
244 enum SYSTEM_INFORMATION_CLASS
246 SystemBasicInformation = 0,
248 SystemPerformanceInformation = 2,
249 SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
251 SystemProcessInformation = 5,
254 SystemProcessorPerformanceInformation = 8,
257 SystemDriverInformation,
267 SystemCacheInformation,
269 SystemInterruptInformation = 23,
270 SystemExceptionInformation = 33,
271 SystemRegistryQuotaInformation = 37,
272 SystemLookasideInformation = 45
277 LARGE_INTEGER IdleTime;
278 LARGE_INTEGER KernelTime;
279 LARGE_INTEGER UserTime;
280 LARGE_INTEGER Reserved1[2];
282 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
284 #define sleep(secs) (Sleep(secs * 1000))
286 /*********************** statfs *****************************/
287 /* fake block size */
288 #define FAKED_BLOCK_SIZE 512
290 /* linux-compatible values for fs type */
291 #define MSDOS_SUPER_MAGIC 0x4d44
292 #define NTFS_SUPER_MAGIC 0x5346544E
294 /*********************** End of statfs ***********************/
296 #define SHUT_RDWR SD_BOTH
298 /* Operations for flock() */
299 #define LOCK_SH 1 /* shared lock */
300 #define LOCK_EX 2 /* exclusive lock */
301 #define LOCK_NB 4 /* or'd with one of the above to prevent
303 #define LOCK_UN 8 /* remove lock */
305 /* Not supported under MinGW */
318 #define SHUT_WR SD_SEND
319 #define SHUT_RD SD_RECEIVE
320 #define SHUT_RDWR SD_BOTH
325 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
327 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
328 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
329 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
330 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
331 long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
332 char *pszBuffer, long *pdLength);
334 BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
335 void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
336 void __win_DiscardHandleBlockingMode(int s);
337 int _win_isSocketValid(int s);
338 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
339 unsigned plibc_get_handle_count();
341 typedef void (*TPanicProc) (int, char *);
342 void plibc_set_panic_proc(TPanicProc proc);
344 int flock(int fd, int operation);
345 int fsync(int fildes);
346 int inet_pton(int af, const char *src, void *dst);
347 int inet_pton4(const char *src, u_char *dst, int pton);
349 int inet_pton6(const char *src, u_char *dst);
351 int truncate(const char *fname, int distance);
352 int statfs(const char *path, struct statfs *buf);
353 const char *hstrerror(int err);
354 int mkstemp(char *tmplate);
355 char *strptime (const char *buf, const char *format, struct tm *tm);
356 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
358 int plibc_init(char *pszOrg, char *pszApp);
359 void plibc_shutdown();
360 int plibc_initialized();
361 int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks);
362 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
363 void SetErrnoFromWinsockError(long lWinError);
364 void SetHErrnoFromWinError(long lWinError);
365 void SetErrnoFromHRESULT(HRESULT hRes);
366 int GetErrnoFromWinsockError(long lWinError);
367 FILE *_win_fopen(const char *filename, const char *mode);
368 DIR *_win_opendir(const char *dirname);
369 int _win_open(const char *filename, int oflag, ...);
371 char *_win_bindtextdomain(const char *domainname, const char *dirname);
373 int _win_chdir(const char *path);
374 int _win_close(int fd);
375 int _win_creat(const char *path, mode_t mode);
376 char *_win_ctime(const time_t *clock);
377 char *_win_ctime_r(const time_t *clock, char *buf);
378 int _win_fstat(int handle, struct stat *buffer);
379 int _win_ftruncate(int fildes, off_t length);
380 void _win_gettimeofday(struct timeval *tp, void *tzp);
381 int _win_kill(pid_t pid, int sig);
382 int _win_pipe(int *phandles);
383 int _win_rmdir(const char *path);
384 int _win_access( const char *path, int mode );
385 int _win_chmod(const char *filename, int pmode);
386 char *realpath(const char *file_name, char *resolved_name);
387 long _win_random(void);
388 void _win_srandom(unsigned int seed);
389 int _win_remove(const char *path);
390 int _win_rename(const char *oldname, const char *newname);
391 int _win_stat(const char *path, struct stat *buffer);
392 int _win_stat64(const char *path, struct stat64 *buffer);
393 int _win_unlink(const char *filename);
394 int _win_write(int fildes, const void *buf, size_t nbyte);
395 int _win_read(int fildes, void *buf, size_t nbyte);
396 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
397 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
398 int _win_symlink(const char *path1, const char *path2);
399 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
400 unsigned long long offset);
401 int _win_munmap(void *start, size_t length);
402 int _win_lstat(const char *path, struct stat *buf);
403 int _win_lstat64(const char *path, struct stat64 *buf);
404 int _win_readlink(const char *path, char *buf, size_t bufsize);
405 int _win_accept(int s, struct sockaddr *addr, int *addrlen);
406 int _win_printf(const char *format,...);
407 int _win_fprintf(FILE *f,const char *format,...);
408 int _win_vprintf(const char *format, va_list ap);
409 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
410 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
411 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr);
412 int _win_snprintf(char *str,size_t size,const char *format,...);
413 int _win_sprintf(char *dest,const char *format,...);
414 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
415 int _win_sscanf(const char *str, const char *format, ...);
416 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
417 int _win_vscanf(const char *format, va_list arg_ptr);
418 int _win_scanf(const char *format, ...);
419 int _win_fscanf(FILE *stream, const char *format, ...);
420 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
421 int _win_bind(int s, const struct sockaddr *name, int namelen);
422 int _win_connect(int s,const struct sockaddr *name, int namelen);
423 int _win_getpeername(int s, struct sockaddr *name,
425 int _win_getsockname(int s, struct sockaddr *name,
427 int _win_getsockopt(int s, int level, int optname, char *optval,
429 int _win_listen(int s, int backlog);
430 int _win_recv(int s, char *buf, int len, int flags);
431 int _win_recvfrom(int s, void *buf, int len, int flags,
432 struct sockaddr *from, int *fromlen);
433 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
434 const struct timeval *tv);
435 int _win_send(int s, const char *buf, int len, int flags);
436 int _win_sendto(int s, const char *buf, int len, int flags,
437 const struct sockaddr *to, int tolen);
438 int _win_setsockopt(int s, int level, int optname, const void *optval,
440 int _win_shutdown(int s, int how);
441 int _win_socket(int af, int type, int protocol);
442 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
443 struct hostent *_win_gethostbyname(const char *name);
444 struct hostent *gethostbyname2(const char *name, int af);
445 char *_win_strerror(int errnum);
447 char *index(const char *s, int c);
450 char *strndup (const char *s, size_t n);
453 size_t strnlen (const char *str, size_t maxlen);
455 char *stpcpy(char *dest, const char *src);
456 char *strcasestr(const char *haystack_start, const char *needle_start);
458 #define strcasecmp(a, b) stricmp(a, b)
459 #define strncasecmp(a, b, c) strnicmp(a, b, c)
464 #define DIR_SEPARATOR '/'
465 #define DIR_SEPARATOR_STR "/"
466 #define PATH_SEPARATOR ';'
467 #define PATH_SEPARATOR_STR ";"
471 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
473 #define CREAT(p, m) creat(p, m)
474 #define PLIBC_CTIME(c) ctime(c)
475 #define CTIME_R(c, b) ctime_r(c, b)
477 #define FOPEN(f, m) fopen(f, m)
478 #define FTRUNCATE(f, l) ftruncate(f, l)
479 #define OPENDIR(d) opendir(d)
481 #define CHDIR(d) chdir(d)
482 #define CLOSE(f) close(f)
483 #define LSEEK(f, o, w) lseek(f, o, w)
484 #define RMDIR(f) rmdir(f)
485 #define ACCESS(p, m) access(p, m)
486 #define CHMOD(f, p) chmod(f, p)
487 #define FSTAT(h, b) fstat(h, b)
488 #define PLIBC_KILL(p, s) kill(p, s)
489 #define PIPE(h) pipe(h)
490 #define REMOVE(p) remove(p)
491 #define RENAME(o, n) rename(o, n)
492 #define STAT(p, b) stat(p, b)
493 #define STAT64(p, b) stat64(p, b)
494 #define UNLINK(f) unlink(f)
495 #define WRITE(f, b, n) write(f, b, n)
496 #define READ(f, b, n) read(f, b, n)
497 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
498 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
499 #define SYMLINK(a, b) symlink(a, b)
500 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
501 #define MUNMAP(s, l) munmap(s, l)
502 #define STRERROR(i) strerror(i)
503 #define RANDOM() random()
504 #define SRANDOM(s) srandom(s)
505 #define READLINK(p, b, s) readlink(p, b, s)
506 #define LSTAT(p, b) lstat(p, b)
507 #define LSTAT64(p, b) lstat64(p, b)
508 #define PRINTF printf
509 #define FPRINTF fprintf
510 #define VPRINTF(f, a) vprintf(f, a)
511 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
512 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
513 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
514 #define _REAL_SNPRINTF snprintf
515 #define SPRINTF sprintf
516 #define VSSCANF(s, f, a) vsscanf(s, f, a)
517 #define SSCANF sscanf
518 #define VFSCANF(s, f, a) vfscanf(s, f, a)
519 #define VSCANF(f, a) vscanf(f, a)
521 #define FSCANF fscanf
522 #define WAITPID(p, s, o) waitpid(p, s, o)
523 #define ACCEPT(s, a, l) accept(s, a, l)
524 #define BIND(s, n, l) bind(s, n, l)
525 #define CONNECT(s, n, l) connect(s, n, l)
526 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
527 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
528 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
529 #define LISTEN(s, b) listen(s, b)
530 #define RECV(s, b, l, f) recv(s, b, l, f)
531 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
532 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
533 #define SEND(s, b, l, f) send(s, b, l, f)
534 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
535 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
536 #define SHUTDOWN(s, h) shutdown(s, h)
537 #define SOCKET(a, t, p) socket(a, t, p)
538 #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
539 #define GETHOSTBYNAME(n) gethostbyname(n)
540 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
541 #define INSQUE(e, p) insque(e, p)
542 #define REMQUE(e) remque(e)
543 #define HSEARCH(i, a) hsearch(i, a)
544 #define HCREATE(n) hcreate(n)
545 #define HDESTROY() hdestroy()
546 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
547 #define HCREATE_R(n, h) hcreate_r(n, h)
548 #define HDESTROY_R(h) hdestroy_r(h)
549 #define TSEARCH(k, r, c) tsearch(k, r, c)
550 #define TFIND(k, r, c) tfind(k, r, c)
551 #define TDELETE(k, r, c) tdelete(k, r, c)
552 #define TWALK(r, a) twalk(r, a)
553 #define TDESTROY(r, f) tdestroy(r, f)
554 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
555 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
557 #define DIR_SEPARATOR '\\'
558 #define DIR_SEPARATOR_STR "\\"
559 #define PATH_SEPARATOR ':'
560 #define PATH_SEPARATOR_STR ":"
561 #define NEWLINE "\r\n"
564 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
566 #define CREAT(p, m) _win_creat(p, m)
567 #define PLIBC_CTIME(c) _win_ctime(c)
568 #define CTIME_R(c, b) _win_ctime_r(c, b)
569 #define FOPEN(f, m) _win_fopen(f, m)
570 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
571 #define OPENDIR(d) _win_opendir(d)
572 #define OPEN _win_open
573 #define CHDIR(d) _win_chdir(d)
574 #define CLOSE(f) _win_close(f)
575 #define PLIBC_KILL(p, s) _win_kill(p, s)
576 #define LSEEK(f, o, w) _win_lseek(f, o, w)
577 #define FSTAT(h, b) _win_fstat(h, b)
578 #define RMDIR(f) _win_rmdir(f)
579 #define ACCESS(p, m) _win_access(p, m)
580 #define CHMOD(f, p) _win_chmod(f, p)
581 #define PIPE(h) _win_pipe(h)
582 #define RANDOM() _win_random()
583 #define SRANDOM(s) _win_srandom(s)
584 #define REMOVE(p) _win_remove(p)
585 #define RENAME(o, n) _win_rename(o, n)
586 #define STAT(p, b) _win_stat(p, b)
587 #define STAT64(p, b) _win_stat64(p, b)
588 #define UNLINK(f) _win_unlink(f)
589 #define WRITE(f, b, n) _win_write(f, b, n)
590 #define READ(f, b, n) _win_read(f, b, n)
591 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
592 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
593 #define SYMLINK(a, b) _win_symlink(a, b)
594 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
595 #define MUNMAP(s, l) _win_munmap(s, l)
596 #define STRERROR(i) _win_strerror(i)
597 #define READLINK(p, b, s) _win_readlink(p, b, s)
598 #define LSTAT(p, b) _win_lstat(p, b)
599 #define LSTAT64(p, b) _win_lstat64(p, b)
600 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
601 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
602 #define VPRINTF(f, a) _win_vprintf(f, a)
603 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
604 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
605 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
606 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
607 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
608 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
609 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
610 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
611 #define VSCANF(f, a) _win_vscanf(f, a)
612 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
613 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
614 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
615 #define ACCEPT(s, a, l) _win_accept(s, a, l)
616 #define BIND(s, n, l) _win_bind(s, n, l)
617 #define CONNECT(s, n, l) _win_connect(s, n, l)
618 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
619 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
620 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
621 #define LISTEN(s, b) _win_listen(s, b)
622 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
623 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
624 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
625 #define SEND(s, b, l, f) _win_send(s, b, l, f)
626 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
627 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
628 #define SHUTDOWN(s, h) _win_shutdown(s, h)
629 #define SOCKET(a, t, p) _win_socket(a, t, p)
630 #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
631 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
632 #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
633 #define INSQUE(e, p) _win_insque(e, p)
634 #define REMQUE(e) _win_remque(e)
635 #define HSEARCH(i, a) _win_hsearch(i, a)
636 #define HCREATE(n) _win_hcreate(n)
637 #define HDESTROY() _win_hdestroy()
638 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
639 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
640 #define HDESTROY_R(h) _win_hdestroy_r(h)
641 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
642 #define TFIND(k, r, c) _win_tfind(k, r, c)
643 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
644 #define TWALK(r, a) _win_twalk(r, a)
645 #define TDESTROY(r, f) _win_tdestroy(r, f)
646 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
647 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
652 /* Prototype structure for a linked-list data structure.
653 This is the type used by the `insque' and `remque' functions. */
655 struct PLIBC_SEARCH_QELEM
657 struct qelem *q_forw;
658 struct qelem *q_back;
663 /* Insert ELEM into a doubly-linked list, after PREV. */
664 void _win_insque (void *__elem, void *__prev);
666 /* Unlink ELEM from the doubly-linked list that it is in. */
667 void _win_remque (void *__elem);
670 /* For use with hsearch(3). */
671 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
673 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
675 /* Action which shall be performed in the call the hsearch. */
683 typedef struct PLIBC_SEARCH_entry
690 /* The reentrant version has no static variables to maintain the state.
691 Instead the interface of all functions is extended to take an argument
692 which describes the current status. */
693 typedef struct _PLIBC_SEARCH_ENTRY
696 PLIBC_SEARCH_ENTRY entry;
701 /* Family of hash table handling functions. The functions also
702 have reentrant counterparts ending with _r. The non-reentrant
703 functions all work on a signle internal hashing table. */
705 /* Search for entry matching ITEM.key in internal hash table. If
706 ACTION is `FIND' return found entry or signal error by returning
707 NULL. If ACTION is `ENTER' replace existing data (if any) with
709 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
711 /* Create a new hashing table which will at most contain NEL elements. */
712 int _win_hcreate (size_t __nel);
714 /* Destroy current internal hashing table. */
715 void _win_hdestroy (void);
717 /* Data type for reentrant functions. */
718 struct PLIBC_SEARCH_hsearch_data
720 struct _PLIBC_SEARCH_ENTRY *table;
725 /* Reentrant versions which can handle multiple hashing tables at the
727 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
728 struct PLIBC_SEARCH_hsearch_data *__htab);
729 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
730 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
733 /* The tsearch routines are very interesting. They make many
734 assumptions about the compiler. It assumes that the first field
735 in node must be the "key" field, which points to the datum.
736 Everything depends on that. */
740 PLIBC_SEARCH_preorder,
741 PLIBC_SEARCH_postorder,
742 PLIBC_SEARCH_endorder,
747 /* Search for an entry matching the given KEY in the tree pointed to
748 by *ROOTP and insert a new element if not found. */
749 void *_win_tsearch (__const void *__key, void **__rootp,
750 PLIBC_SEARCH__compar_fn_t __compar);
752 /* Search for an entry matching the given KEY in the tree pointed to
753 by *ROOTP. If no matching entry is available return NULL. */
754 void *_win_tfind (__const void *__key, void *__const *__rootp,
755 PLIBC_SEARCH__compar_fn_t __compar);
757 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
758 void *_win_tdelete (__const void *__restrict __key,
759 void **__restrict __rootp,
760 PLIBC_SEARCH__compar_fn_t __compar);
762 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
765 /* Walk through the whole tree and call the ACTION callback for every node
767 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
769 /* Callback type for function to free a tree node. If the keys are atomic
770 data this function should do nothing. */
771 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
773 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
774 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
777 /* Perform linear search for KEY by comparing by COMPAR in an array
778 [BASE,BASE+NMEMB*SIZE). */
779 void *_win_lfind (__const void *__key, __const void *__base,
780 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
782 /* Perform linear search for KEY by comparing by COMPAR function in
783 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
784 void *_win_lsearch (__const void *__key, void *__base,
785 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);