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
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))
73 #ifndef HAVE_DECL__STATI64
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
118 #if !defined(EACCESS)
119 # define EACCESS EACCES
122 /* Thanks to the Cygwin project */
124 # define ENOCSI 43 /* No CSI structure available */
127 # define EL2HLT 44 /* Level 2 halted */
129 #if !defined(EDEADLK)
130 # define EDEADLK 45 /* Deadlock condition */
133 # define ENOLCK 46 /* No record locks available */
136 # define EBADE 50 /* Invalid exchange */
139 # define EBADR 51 /* Invalid request descriptor */
142 # define EXFULL 52 /* Exchange full */
145 # define ENOANO 53 /* No anode */
147 #if !defined(EBADRQC)
148 # define EBADRQC 54 /* Invalid request code */
150 #if !defined(EBADSLT)
151 # define EBADSLT 55 /* Invalid slot */
153 #if !defined(EDEADLOCK)
154 # define EDEADLOCK EDEADLK /* File locking deadlock error */
157 # define EBFONT 57 /* Bad font file fmt */
160 # define ENOSTR 60 /* Device not a stream */
162 #if !defined(ENODATA)
163 # define ENODATA 61 /* No data (for no delay io) */
166 # define ETIME 62 /* Timer expired */
169 # define ENOSR 63 /* Out of streams resources */
172 # define ENONET 64 /* Machine is not on the network */
175 # define ENOPKG 65 /* Package not installed */
177 #if !defined(EREMOTE)
178 # define EREMOTE 66 /* The object is remote */
180 #if !defined(ENOLINK)
181 # define ENOLINK 67 /* The link has been severed */
184 # define EADV 68 /* Advertise error */
187 # define ESRMNT 69 /* Srmount error */
190 # define ECOMM 70 /* Communication error on send */
192 #if !defined(EMULTIHOP)
193 # define EMULTIHOP 74 /* Multihop attempted */
196 # define ELBIN 75 /* Inode is remote (not really error) */
198 #if !defined(EDOTDOT)
199 # define EDOTDOT 76 /* Cross mount point (not really error) */
201 #if !defined(EBADMSG)
202 # define EBADMSG 77 /* Trying to read unreadable message */
204 #if !defined(ENOTUNIQ)
205 # define ENOTUNIQ 80 /* Given log. name not unique */
208 # define EBADFD 81 /* f.d. invalid for this operation */
210 #if !defined(EREMCHG)
211 # define EREMCHG 82 /* Remote address changed */
213 #if !defined(ELIBACC)
214 # define ELIBACC 83 /* Can't access a needed shared lib */
216 #if !defined(ELIBBAD)
217 # define ELIBBAD 84 /* Accessing a corrupted shared lib */
219 #if !defined(ELIBSCN)
220 # define ELIBSCN 85 /* .lib section in a.out corrupted */
222 #if !defined(ELIBMAX)
223 # define ELIBMAX 86 /* Attempting to link in too many libs */
225 #if !defined(ELIBEXEC)
226 # define ELIBEXEC 87 /* Attempting to exec a shared library */
229 # define ENOSYS 88 /* Function not implemented */
231 #if !defined(ENMFILE)
232 # define ENMFILE 89 /* No more files */
234 #if !defined(ENOTEMPTY)
235 # define ENOTEMPTY 90 /* Directory not empty */
237 #if !defined(ENAMETOOLONG)
238 # define ENAMETOOLONG 91 /* File or path name too long */
240 #if !defined(EPFNOSUPPORT)
241 # define EPFNOSUPPORT 96 /* Protocol family not supported */
243 #if !defined(ENOSHARE)
244 # define ENOSHARE 97 /* No such host or network path */
246 #if !defined(ENOMEDIUM)
247 # define ENOMEDIUM 98 /* No medium (in tape drive) */
249 #if !defined(ESHUTDOWN)
250 # define ESHUTDOWN 99 /* Can't send after socket shutdown */
252 #if !defined(EADDRINUSE)
253 # define EADDRINUSE 100 /* Address already in use */
255 #if !defined(EADDRNOTAVAIL)
256 # define EADDRNOTAVAIL 101 /* Address not available */
258 #if !defined(EAFNOSUPPORT)
259 # define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
261 #if !defined(EALREADY)
262 # define EALREADY 103 /* Socket already connected */
264 #if !defined(ECANCELED)
265 # define ECANCELED 105 /* Connection cancelled */
267 #if !defined(ECONNABORTED)
268 # define ECONNABORTED 106 /* Connection aborted */
270 #if !defined(ECONNREFUSED)
271 # define ECONNREFUSED 107 /* Connection refused */
273 #if !defined(ECONNRESET)
274 # define ECONNRESET 108 /* Connection reset by peer */
276 #if !defined(EDESTADDRREQ)
277 # define EDESTADDRREQ 109 /* Destination address required */
279 #if !defined(EHOSTUNREACH)
280 # define EHOSTUNREACH 110 /* Host is unreachable */
282 #if !defined(ECONNABORTED)
283 # define ECONNABORTED 111 /* Connection aborted */
285 #if !defined(EINPROGRESS)
286 # define EINPROGRESS 112 /* Connection already in progress */
288 #if !defined(EISCONN)
289 # define EISCONN 113 /* Socket is already connected */
292 # define ELOOP 114 /* Too many symbolic links */
294 #if !defined(EMSGSIZE)
295 # define EMSGSIZE 115 /* Message too long */
297 #if !defined(ENETDOWN)
298 # define ENETDOWN 116 /* Network interface is not configured */
300 #if !defined(ENETRESET)
301 # define ENETRESET 117 /* Connection aborted by network */
303 #if !defined(ENETUNREACH)
304 # define ENETUNREACH 118 /* Network is unreachable */
306 #if !defined(ENOBUFS)
307 # define ENOBUFS 119 /* No buffer space available */
309 #if !defined(EHOSTDOWN)
310 # define EHOSTDOWN 120 /* Host is down */
312 #if !defined(EPROCLIM)
313 # define EPROCLIM 121 /* Too many processes */
316 # define EDQUOT 122 /* Disk quota exceeded */
318 #if !defined(ENOPROTOOPT)
319 # define ENOPROTOOPT 123 /* Protocol not available */
321 #if !defined(ESOCKTNOSUPPORT)
322 # define ESOCKTNOSUPPORT 124 /* Socket type not supported */
325 # define ESTALE 125 /* Unknown error */
327 #if !defined(ENOTCONN)
328 # define ENOTCONN 126 /* Socket is not connected */
330 #if !defined(ETOOMANYREFS)
331 # define ETOOMANYREFS 127 /* Too many references: cannot splice */
333 #if !defined(ENOTSOCK)
334 # define ENOTSOCK 128 /* Socket operation on non-socket */
336 #if !defined(ENOTSUP)
337 # define ENOTSUP 129 /* Not supported */
339 #if !defined(EOPNOTSUPP)
340 # define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
343 # define EUSERS 131 /* Too many users */
345 #if !defined(EOVERFLOW)
346 # define EOVERFLOW 132 /* Value too large for defined data type */
348 #if !defined(EOWNERDEAD)
349 # define EOWNERDEAD 133 /* Unknown error */
352 # define EPROTO 134 /* Protocol error */
354 #if !defined(EPROTONOSUPPORT)
355 # define EPROTONOSUPPORT 135 /* Unknown protocol */
357 #if !defined(EPROTOTYPE)
358 # define EPROTOTYPE 136 /* Protocol wrong type for socket */
360 #if !defined(ECASECLASH)
361 # define ECASECLASH 137 /* Filename exists with different case */
363 #if !defined(ETIMEDOUT)
364 /* Make sure it's the same as WSATIMEDOUT */
365 # define ETIMEDOUT 138 /* Connection timed out */
367 #if !defined(EWOULDBLOCK) || EWOULDBLOCK == 140
368 # undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
369 # define EWOULDBLOCK EAGAIN /* Operation would block */
372 #undef HOST_NOT_FOUND
373 #define HOST_NOT_FOUND 1
377 #define NO_RECOVERY 3
381 #define PROT_READ 0x1
382 #define PROT_WRITE 0x2
383 #define MAP_SHARED 0x1
384 #define MAP_PRIVATE 0x2 /* unsupported */
385 #define MAP_FIXED 0x10
386 #define MAP_ANONYMOUS 0x20 /* unsupported */
387 #define MAP_FAILED ((void *)-1)
389 #define MS_ASYNC 1 /* sync memory asynchronously */
390 #define MS_INVALIDATE 2 /* invalidate the caches */
391 #define MS_SYNC 4 /* synchronous memory sync */
395 long f_type; /* type of filesystem (see below) */
396 long f_bsize; /* optimal transfer block size */
397 long f_blocks; /* total data blocks in file system */
398 long f_bfree; /* free blocks in fs */
399 long f_bavail; /* free blocks avail to non-superuser */
400 long f_files; /* total file nodes in file system */
401 long f_ffree; /* free file nodes in fs */
402 long f_fsid; /* file system id */
403 long f_namelen; /* maximum length of filenames */
404 long f_spare[6]; /* spare for later */
406 #define sleep(secs) (Sleep(secs * 1000))
408 /*********************** statfs *****************************/
409 /* fake block size */
410 #define FAKED_BLOCK_SIZE 512
412 /* linux-compatible values for fs type */
413 #define MSDOS_SUPER_MAGIC 0x4d44
414 #define NTFS_SUPER_MAGIC 0x5346544E
416 /*********************** End of statfs ***********************/
418 #define SHUT_RDWR SD_BOTH
420 /* Operations for flock() */
421 #define LOCK_SH 1 /* shared lock */
422 #define LOCK_EX 2 /* exclusive lock */
423 #define LOCK_NB 4 /* or'd with one of the above to prevent
425 #define LOCK_UN 8 /* remove lock */
427 /* Not supported under MinGW */
440 #define SHUT_WR SD_SEND
441 #define SHUT_RD SD_RECEIVE
442 #define SHUT_RDWR SD_BOTH
447 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
449 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
450 BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
451 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
452 BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
453 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
454 wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
455 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
456 wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
458 long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
459 char *pszBuffer, long *pdLength);
460 long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
461 wchar_t *pszBuffer, long *pdLength);
463 BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
464 void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
465 void __win_DiscardHandleBlockingMode(int s);
466 int _win_isSocketValid(int s);
467 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
468 int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
470 int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
471 int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
473 unsigned plibc_get_handle_count();
475 typedef void (*TPanicProc) (int, char *);
476 void plibc_set_panic_proc(TPanicProc proc);
477 void plibc_set_stat_size_size(int iLength);
478 void plibc_set_stat_time_size(int iLength);
480 int flock(int fd, int operation);
481 int fsync(int fildes);
482 int inet_pton(int af, const char *src, void *dst);
483 int inet_pton4(const char *src, u_char *dst, int pton);
485 int inet_pton6(const char *src, u_char *dst);
487 int statfs(const char *path, struct statfs *buf);
488 const char *hstrerror(int err);
489 int mkstemp(char *tmplate);
490 char *strptime (const char *buf, const char *format, struct tm *tm);
491 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
493 struct tm *gmtime_r(const time_t *clock, struct tm *result);
496 int plibc_init(char *pszOrg, char *pszApp);
497 int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
498 void plibc_shutdown();
499 int plibc_initialized();
501 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
502 void SetErrnoFromWinsockError(long lWinError);
503 void SetHErrnoFromWinError(long lWinError);
504 void SetErrnoFromHRESULT(HRESULT hRes);
505 int GetErrnoFromWinsockError(long lWinError);
506 FILE *_win_fopen(const char *filename, const char *mode);
507 int _win_fclose(FILE *);
508 DIR *_win_opendir(const char *dirname);
509 struct dirent *_win_readdir(DIR *dirp);
510 int _win_closedir(DIR *dirp);
511 int _win_open(const char *filename, int oflag, ...);
513 char *_win_bindtextdomain(const char *domainname, const char *dirname);
515 int _win_chdir(const char *path);
516 int _win_close(int fd);
517 int _win_creat(const char *path, mode_t mode);
518 char *_win_ctime(const time_t *clock);
519 char *_win_ctime_r(const time_t *clock, char *buf);
520 int _win_fstat(int handle, struct stat *buffer);
521 int _win_ftruncate(int fildes, off_t length);
522 int _win_truncate(const char *fname, int distance);
523 int _win_kill(pid_t pid, int sig);
524 int _win_pipe(int *phandles);
525 intptr_t _win_mkfifo(const char *path, mode_t mode);
526 int _win_rmdir(const char *path);
527 int _win_access( const char *path, int mode );
528 int _win_chmod(const char *filename, int pmode);
529 char *realpath(const char *file_name, char *resolved_name);
530 long _win_random(void);
531 void _win_srandom(unsigned int seed);
532 int _win_remove(const char *path);
533 int _win_rename(const char *oldname, const char *newname);
534 int _win_stat(const char *path, struct stat *buffer);
535 int _win_stati64(const char *path, struct _stati64 *buffer);
536 long _win_sysconf(int name);
537 int _win_unlink(const char *filename);
538 int _win_write(int fildes, const void *buf, size_t nbyte);
539 int _win_read(int fildes, void *buf, size_t nbyte);
540 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
541 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
542 int _win_symlink(const char *path1, const char *path2);
543 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
544 unsigned long long offset);
545 int _win_msync(void *start, size_t length, int flags);
546 int _win_munmap(void *start, size_t length);
547 int _win_lstat(const char *path, struct stat *buf);
548 int _win_lstati64(const char *path, struct _stati64 *buf);
549 int _win_readlink(const char *path, char *buf, size_t bufsize);
550 int _win_accept(int s, struct sockaddr *addr, int *addrlen);
552 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
553 int _win_bind(int s, const struct sockaddr *name, int namelen);
554 int _win_connect(int s,const struct sockaddr *name, int namelen);
555 int _win_getpeername(int s, struct sockaddr *name,
557 int _win_getsockname(int s, struct sockaddr *name,
559 int _win_getsockopt(int s, int level, int optname, char *optval,
561 int _win_listen(int s, int backlog);
562 int _win_recv(int s, char *buf, int len, int flags);
563 int _win_recvfrom(int s, void *buf, int len, int flags,
564 struct sockaddr *from, int *fromlen);
565 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
566 const struct timeval *tv);
567 int _win_send(int s, const char *buf, int len, int flags);
568 int _win_sendto(int s, const char *buf, int len, int flags,
569 const struct sockaddr *to, int tolen);
570 int _win_setsockopt(int s, int level, int optname, const void *optval,
572 int _win_shutdown(int s, int how);
573 int _win_socket(int af, int type, int protocol);
574 int _win_socketpair(int af, int type, int protocol, int socket_vector[2]);
575 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
576 struct hostent *_win_gethostbyname(const char *name);
577 struct hostent *gethostbyname2(const char *name, int af);
578 char *_win_strerror(int errnum);
580 char *index(const char *s, int c);
581 char *_win_strtok_r (char *ptr, const char *sep, char **end);
584 char *strndup (const char *s, size_t n);
586 #if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
587 size_t strnlen (const char *str, size_t maxlen);
589 char *stpcpy(char *dest, const char *src);
590 char *strcasestr(const char *haystack_start, const char *needle_start);
591 #ifndef __MINGW64_VERSION_MAJOR
592 #define strcasecmp(a, b) stricmp(a, b)
593 #define strncasecmp(a, b, c) strnicmp(a, b, c)
596 #define wcscasecmp(a, b) wcsicmp(a, b)
599 #define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
601 #ifndef strtok_r /* winpthreads defines it in pthread.h */
602 #define strtok_r _win_strtok_r
607 #define DIR_SEPARATOR '/'
608 #define DIR_SEPARATOR_STR "/"
609 #define PATH_SEPARATOR ':'
610 #define PATH_SEPARATOR_STR ":"
614 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
616 #define CREAT(p, m) creat(p, m)
617 #define PLIBC_CTIME(c) ctime(c)
618 #define CTIME_R(c, b) ctime_r(c, b)
620 #define FOPEN(f, m) fopen(f, m)
621 #define FCLOSE(f) fclose(f)
622 #define FTRUNCATE(f, l) ftruncate(f, l)
623 #define TRUNCATE(f, l) truncate(f, l)
624 #define OPENDIR(d) opendir(d)
625 #define CLOSEDIR(d) closedir(d)
626 #define READDIR(d) readdir(d)
628 #define CHDIR(d) chdir(d)
629 #define CLOSE(f) close(f)
630 #define LSEEK(f, o, w) lseek(f, o, w)
631 #define RMDIR(f) rmdir(f)
632 #define ACCESS(p, m) access(p, m)
633 #define CHMOD(f, p) chmod(f, p)
634 #define FSTAT(h, b) fstat(h, b)
635 #define PLIBC_KILL(p, s) kill(p, s)
636 #define PIPE(h) pipe(h)
637 #define REMOVE(p) remove(p)
638 #define RENAME(o, n) rename(o, n)
639 #define STAT(p, b) stat(p, b)
640 #define STAT64(p, b) stat64(p, b)
641 #define SYSCONF(n) sysconf(n)
642 #define UNLINK(f) unlink(f)
643 #define WRITE(f, b, n) write(f, b, n)
644 #define READ(f, b, n) read(f, b, n)
645 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
646 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
647 #define SYMLINK(a, b) symlink(a, b)
648 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
649 #define MKFIFO(p, m) mkfifo(p, m)
650 #define MSYNC(s, l, f) msync(s, l, f)
651 #define MUNMAP(s, l) munmap(s, l)
652 #define STRERROR(i) strerror(i)
653 #define RANDOM() random()
654 #define SRANDOM(s) srandom(s)
655 #define READLINK(p, b, s) readlink(p, b, s)
656 #define LSTAT(p, b) lstat(p, b)
657 #define LSTAT64(p, b) lstat64(p, b)
658 #define PRINTF printf
659 #define FPRINTF fprintf
660 #define VPRINTF(f, a) vprintf(f, a)
661 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
662 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
663 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
664 #define _REAL_SNPRINTF snprintf
665 #define SPRINTF sprintf
666 #define VSSCANF(s, f, a) vsscanf(s, f, a)
667 #define SSCANF sscanf
668 #define VFSCANF(s, f, a) vfscanf(s, f, a)
669 #define VSCANF(f, a) vscanf(f, a)
671 #define FSCANF fscanf
672 #define WAITPID(p, s, o) waitpid(p, s, o)
673 #define ACCEPT(s, a, l) accept(s, a, l)
674 #define BIND(s, n, l) bind(s, n, l)
675 #define CONNECT(s, n, l) connect(s, n, l)
676 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
677 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
678 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
679 #define LISTEN(s, b) listen(s, b)
680 #define RECV(s, b, l, f) recv(s, b, l, f)
681 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
682 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
683 #define SEND(s, b, l, f) send(s, b, l, f)
684 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
685 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
686 #define SHUTDOWN(s, h) shutdown(s, h)
687 #define SOCKET(a, t, p) socket(a, t, p)
688 #define SOCKETPAIR(a, t, p, v) socketpair(a, t, p, v)
689 #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t)
690 #define GETHOSTBYNAME(n) gethostbyname(n)
691 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
692 #define INSQUE(e, p) insque(e, p)
693 #define REMQUE(e) remque(e)
694 #define HSEARCH(i, a) hsearch(i, a)
695 #define HCREATE(n) hcreate(n)
696 #define HDESTROY() hdestroy()
697 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
698 #define HCREATE_R(n, h) hcreate_r(n, h)
699 #define HDESTROY_R(h) hdestroy_r(h)
700 #define TSEARCH(k, r, c) tsearch(k, r, c)
701 #define TFIND(k, r, c) tfind(k, r, c)
702 #define TDELETE(k, r, c) tdelete(k, r, c)
703 #define TWALK(r, a) twalk(r, a)
704 #define TDESTROY(r, f) tdestroy(r, f)
705 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
706 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
707 #define STRUCT_STAT64 struct stat64
709 #define DIR_SEPARATOR '\\'
710 #define DIR_SEPARATOR_STR "\\"
711 #define PATH_SEPARATOR ';'
712 #define PATH_SEPARATOR_STR ";"
713 #define NEWLINE "\r\n"
716 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
718 #define CREAT(p, m) _win_creat(p, m)
719 #define PLIBC_CTIME(c) _win_ctime(c)
720 #define CTIME_R(c, b) _win_ctime_r(c, b)
721 #define FOPEN(f, m) _win_fopen(f, m)
722 #define FCLOSE(f) _win_fclose(f)
723 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
724 #define TRUNCATE(f, l) _win_truncate(f, l)
725 #define OPENDIR(d) _win_opendir(d)
726 #define CLOSEDIR(d) _win_closedir(d)
727 #define READDIR(d) _win_readdir(d)
728 #define OPEN _win_open
729 #define CHDIR(d) _win_chdir(d)
730 #define CLOSE(f) _win_close(f)
731 #define PLIBC_KILL(p, s) _win_kill(p, s)
732 #define LSEEK(f, o, w) lseek(f, o, w)
733 #define FSTAT(h, b) _win_fstat(h, b)
734 #define RMDIR(f) _win_rmdir(f)
735 #define ACCESS(p, m) _win_access(p, m)
736 #define CHMOD(f, p) _win_chmod(f, p)
737 #define PIPE(h) _win_pipe(h)
738 #define RANDOM() _win_random()
739 #define SRANDOM(s) _win_srandom(s)
740 #define REMOVE(p) _win_remove(p)
741 #define RENAME(o, n) _win_rename(o, n)
742 #define STAT(p, b) _win_stat(p, b)
743 #define STAT64(p, b) _win_stati64(p, b)
744 #define SYSCONF(n) _win_sysconf(n)
745 #define UNLINK(f) _win_unlink(f)
746 #define WRITE(f, b, n) _win_write(f, b, n)
747 #define READ(f, b, n) _win_read(f, b, n)
748 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
749 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
750 #define SYMLINK(a, b) _win_symlink(a, b)
751 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
752 #define MKFIFO(p, m) _win_mkfifo(p, m)
753 #define MSYNC(s, l, f) _win_msync(s, l, f)
754 #define MUNMAP(s, l) _win_munmap(s, l)
755 #define STRERROR(i) _win_strerror(i)
756 #define READLINK(p, b, s) _win_readlink(p, b, s)
757 #define LSTAT(p, b) _win_lstat(p, b)
758 #define LSTAT64(p, b) _win_lstati64(p, b)
759 #define PRINTF printf
760 #define FPRINTF fprintf
761 #define VPRINTF(f, a) vprintf(f, a)
762 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
763 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
764 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
765 #define _REAL_SNPRINTF snprintf
766 #define SPRINTF sprintf
767 #define VSSCANF(s, f, a) vsscanf(s, f, a)
768 #define SSCANF sscanf
769 #define VFSCANF(s, f, a) vfscanf(s, f, a)
770 #define VSCANF(f, a) vscanf(f, a)
772 #define FSCANF fscanf
773 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
774 #define ACCEPT(s, a, l) _win_accept(s, a, l)
775 #define BIND(s, n, l) _win_bind(s, n, l)
776 #define CONNECT(s, n, l) _win_connect(s, n, l)
777 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
778 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
779 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
780 #define LISTEN(s, b) _win_listen(s, b)
781 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
782 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
783 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
784 #define SEND(s, b, l, f) _win_send(s, b, l, f)
785 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
786 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
787 #define SHUTDOWN(s, h) _win_shutdown(s, h)
788 #define SOCKET(a, t, p) _win_socket(a, t, p)
789 #define SOCKETPAIR(a, t, p, v) _win_socketpair(a, t, p, v)
790 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t)
791 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
792 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
793 #define INSQUE(e, p) _win_insque(e, p)
794 #define REMQUE(e) _win_remque(e)
795 #define HSEARCH(i, a) _win_hsearch(i, a)
796 #define HCREATE(n) _win_hcreate(n)
797 #define HDESTROY() _win_hdestroy()
798 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
799 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
800 #define HDESTROY_R(h) _win_hdestroy_r(h)
801 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
802 #define TFIND(k, r, c) _win_tfind(k, r, c)
803 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
804 #define TWALK(r, a) _win_twalk(r, a)
805 #define TDESTROY(r, f) _win_tdestroy(r, f)
806 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
807 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
808 #define STRUCT_STAT64 struct _stati64
813 /* Prototype structure for a linked-list data structure.
814 This is the type used by the `insque' and `remque' functions. */
816 struct PLIBC_SEARCH_QELEM
818 struct qelem *q_forw;
819 struct qelem *q_back;
824 /* Insert ELEM into a doubly-linked list, after PREV. */
825 void _win_insque (void *__elem, void *__prev);
827 /* Unlink ELEM from the doubly-linked list that it is in. */
828 void _win_remque (void *__elem);
831 /* For use with hsearch(3). */
832 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
834 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
836 /* Action which shall be performed in the call the hsearch. */
844 typedef struct PLIBC_SEARCH_entry
851 /* The reentrant version has no static variables to maintain the state.
852 Instead the interface of all functions is extended to take an argument
853 which describes the current status. */
854 typedef struct _PLIBC_SEARCH_ENTRY
857 PLIBC_SEARCH_ENTRY entry;
862 /* Family of hash table handling functions. The functions also
863 have reentrant counterparts ending with _r. The non-reentrant
864 functions all work on a signle internal hashing table. */
866 /* Search for entry matching ITEM.key in internal hash table. If
867 ACTION is `FIND' return found entry or signal error by returning
868 NULL. If ACTION is `ENTER' replace existing data (if any) with
870 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
872 /* Create a new hashing table which will at most contain NEL elements. */
873 int _win_hcreate (size_t __nel);
875 /* Destroy current internal hashing table. */
876 void _win_hdestroy (void);
878 /* Data type for reentrant functions. */
879 struct PLIBC_SEARCH_hsearch_data
881 struct _PLIBC_SEARCH_ENTRY *table;
886 /* Reentrant versions which can handle multiple hashing tables at the
888 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
889 struct PLIBC_SEARCH_hsearch_data *__htab);
890 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
891 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
894 /* The tsearch routines are very interesting. They make many
895 assumptions about the compiler. It assumes that the first field
896 in node must be the "key" field, which points to the datum.
897 Everything depends on that. */
901 PLIBC_SEARCH_preorder,
902 PLIBC_SEARCH_postorder,
903 PLIBC_SEARCH_endorder,
908 /* Search for an entry matching the given KEY in the tree pointed to
909 by *ROOTP and insert a new element if not found. */
910 void *_win_tsearch (__const void *__key, void **__rootp,
911 PLIBC_SEARCH__compar_fn_t __compar);
913 /* Search for an entry matching the given KEY in the tree pointed to
914 by *ROOTP. If no matching entry is available return NULL. */
915 void *_win_tfind (__const void *__key, void *__const *__rootp,
916 PLIBC_SEARCH__compar_fn_t __compar);
918 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
919 void *_win_tdelete (__const void *__restrict __key,
920 void **__restrict __rootp,
921 PLIBC_SEARCH__compar_fn_t __compar);
923 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
926 /* Walk through the whole tree and call the ACTION callback for every node
928 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
930 /* Callback type for function to free a tree node. If the keys are atomic
931 data this function should do nothing. */
932 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
934 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
935 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
938 /* Perform linear search for KEY by comparing by COMPAR in an array
939 [BASE,BASE+NMEMB*SIZE). */
940 void *_win_lfind (__const void *__key, __const void *__base,
941 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
943 /* Perform linear search for KEY by comparing by COMPAR function in
944 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
945 void *_win_lsearch (__const void *__key, void *__base,
946 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);