2 This file is part of PlibC.
3 Copyright (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * @attention This file is usually not installed under Unix,
25 * so ship it with your application
27 * @version $Revision: 158 $
47 #define HAVE_PLIBC_FD 0
57 #include <sys/types.h>
60 #include <sys/types.h>
66 #define __BYTE_ORDER BYTE_ORDER
67 #define __BIG_ENDIAN BIG_ENDIAN
69 /* Conflicts with our definitions */
72 /* Convert LARGE_INTEGER to double */
73 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
74 (double)((x).LowPart))
75 #ifndef HAVE_DECL__STATI64
91 typedef unsigned int sa_family_t;
94 short sun_family; /*AF_UNIX*/
95 char sun_path[108]; /*path name */
107 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
111 #define MSG_DONTWAIT 0
120 #if !defined(EACCESS)
121 # define EACCESS EACCES
124 /* Thanks to the Cygwin project */
126 # define ENOCSI 43 /* No CSI structure available */
129 # define EL2HLT 44 /* Level 2 halted */
131 #if !defined(EDEADLK)
132 # define EDEADLK 45 /* Deadlock condition */
135 # define ENOLCK 46 /* No record locks available */
138 # define EBADE 50 /* Invalid exchange */
141 # define EBADR 51 /* Invalid request descriptor */
144 # define EXFULL 52 /* Exchange full */
147 # define ENOANO 53 /* No anode */
149 #if !defined(EBADRQC)
150 # define EBADRQC 54 /* Invalid request code */
152 #if !defined(EBADSLT)
153 # define EBADSLT 55 /* Invalid slot */
155 #if !defined(EDEADLOCK)
156 # define EDEADLOCK EDEADLK /* File locking deadlock error */
159 # define EBFONT 57 /* Bad font file fmt */
162 # define ENOSTR 60 /* Device not a stream */
164 #if !defined(ENODATA)
165 # define ENODATA 61 /* No data (for no delay io) */
168 # define ETIME 62 /* Timer expired */
171 # define ENOSR 63 /* Out of streams resources */
174 # define ENONET 64 /* Machine is not on the network */
177 # define ENOPKG 65 /* Package not installed */
179 #if !defined(EREMOTE)
180 # define EREMOTE 66 /* The object is remote */
182 #if !defined(ENOLINK)
183 # define ENOLINK 67 /* The link has been severed */
186 # define EADV 68 /* Advertise error */
189 # define ESRMNT 69 /* Srmount error */
192 # define ECOMM 70 /* Communication error on send */
194 #if !defined(EMULTIHOP)
195 # define EMULTIHOP 74 /* Multihop attempted */
198 # define ELBIN 75 /* Inode is remote (not really error) */
200 #if !defined(EDOTDOT)
201 # define EDOTDOT 76 /* Cross mount point (not really error) */
203 #if !defined(EBADMSG)
204 # define EBADMSG 77 /* Trying to read unreadable message */
206 #if !defined(ENOTUNIQ)
207 # define ENOTUNIQ 80 /* Given log. name not unique */
210 # define EBADFD 81 /* f.d. invalid for this operation */
212 #if !defined(EREMCHG)
213 # define EREMCHG 82 /* Remote address changed */
215 #if !defined(ELIBACC)
216 # define ELIBACC 83 /* Can't access a needed shared lib */
218 #if !defined(ELIBBAD)
219 # define ELIBBAD 84 /* Accessing a corrupted shared lib */
221 #if !defined(ELIBSCN)
222 # define ELIBSCN 85 /* .lib section in a.out corrupted */
224 #if !defined(ELIBMAX)
225 # define ELIBMAX 86 /* Attempting to link in too many libs */
227 #if !defined(ELIBEXEC)
228 # define ELIBEXEC 87 /* Attempting to exec a shared library */
231 # define ENOSYS 88 /* Function not implemented */
233 #if !defined(ENMFILE)
234 # define ENMFILE 89 /* No more files */
236 #if !defined(ENOTEMPTY)
237 # define ENOTEMPTY 90 /* Directory not empty */
239 #if !defined(ENAMETOOLONG)
240 # define ENAMETOOLONG 91 /* File or path name too long */
242 #if !defined(EPFNOSUPPORT)
243 # define EPFNOSUPPORT 96 /* Protocol family not supported */
245 #if !defined(ENOSHARE)
246 # define ENOSHARE 97 /* No such host or network path */
248 #if !defined(ENOMEDIUM)
249 # define ENOMEDIUM 98 /* No medium (in tape drive) */
251 #if !defined(ESHUTDOWN)
252 # define ESHUTDOWN 99 /* Can't send after socket shutdown */
254 #if !defined(EADDRINUSE)
255 # define EADDRINUSE 100 /* Address already in use */
257 #if !defined(EADDRNOTAVAIL)
258 # define EADDRNOTAVAIL 101 /* Address not available */
260 #if !defined(EAFNOSUPPORT)
261 # define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
263 #if !defined(EALREADY)
264 # define EALREADY 103 /* Socket already connected */
266 #if !defined(ECANCELED)
267 # define ECANCELED 105 /* Connection cancelled */
269 #if !defined(ECONNABORTED)
270 # define ECONNABORTED 106 /* Connection aborted */
272 #if !defined(ECONNREFUSED)
273 # define ECONNREFUSED 107 /* Connection refused */
275 #if !defined(ECONNRESET)
276 # define ECONNRESET 108 /* Connection reset by peer */
278 #if !defined(EDESTADDRREQ)
279 # define EDESTADDRREQ 109 /* Destination address required */
281 #if !defined(EHOSTUNREACH)
282 # define EHOSTUNREACH 110 /* Host is unreachable */
284 #if !defined(ECONNABORTED)
285 # define ECONNABORTED 111 /* Connection aborted */
287 #if !defined(EINPROGRESS)
288 # define EINPROGRESS 112 /* Connection already in progress */
290 #if !defined(EISCONN)
291 # define EISCONN 113 /* Socket is already connected */
294 # define ELOOP 114 /* Too many symbolic links */
296 #if !defined(EMSGSIZE)
297 # define EMSGSIZE 115 /* Message too long */
299 #if !defined(ENETDOWN)
300 # define ENETDOWN 116 /* Network interface is not configured */
302 #if !defined(ENETRESET)
303 # define ENETRESET 117 /* Connection aborted by network */
305 #if !defined(ENETUNREACH)
306 # define ENETUNREACH 118 /* Network is unreachable */
308 #if !defined(ENOBUFS)
309 # define ENOBUFS 119 /* No buffer space available */
311 #if !defined(EHOSTDOWN)
312 # define EHOSTDOWN 120 /* Host is down */
314 #if !defined(EPROCLIM)
315 # define EPROCLIM 121 /* Too many processes */
318 # define EDQUOT 122 /* Disk quota exceeded */
320 #if !defined(ENOPROTOOPT)
321 # define ENOPROTOOPT 123 /* Protocol not available */
323 #if !defined(ESOCKTNOSUPPORT)
324 # define ESOCKTNOSUPPORT 124 /* Socket type not supported */
327 # define ESTALE 125 /* Unknown error */
329 #if !defined(ENOTCONN)
330 # define ENOTCONN 126 /* Socket is not connected */
332 #if !defined(ETOOMANYREFS)
333 # define ETOOMANYREFS 127 /* Too many references: cannot splice */
335 #if !defined(ENOTSOCK)
336 # define ENOTSOCK 128 /* Socket operation on non-socket */
338 #if !defined(ENOTSUP)
339 # define ENOTSUP 129 /* Not supported */
341 #if !defined(EOPNOTSUPP)
342 # define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
345 # define EUSERS 131 /* Too many users */
347 #if !defined(EOVERFLOW)
348 # define EOVERFLOW 132 /* Value too large for defined data type */
350 #if !defined(EOWNERDEAD)
351 # define EOWNERDEAD 133 /* Unknown error */
354 # define EPROTO 134 /* Protocol error */
356 #if !defined(EPROTONOSUPPORT)
357 # define EPROTONOSUPPORT 135 /* Unknown protocol */
359 #if !defined(EPROTOTYPE)
360 # define EPROTOTYPE 136 /* Protocol wrong type for socket */
362 #if !defined(ECASECLASH)
363 # define ECASECLASH 137 /* Filename exists with different case */
365 #if !defined(ETIMEDOUT)
366 /* Make sure it's the same as WSATIMEDOUT */
367 # define ETIMEDOUT 138 /* Connection timed out */
369 #if !defined(EWOULDBLOCK) || EWOULDBLOCK == 140
370 # undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
371 # define EWOULDBLOCK EAGAIN /* Operation would block */
374 #undef HOST_NOT_FOUND
375 #define HOST_NOT_FOUND 1
379 #define NO_RECOVERY 3
383 #define PROT_READ 0x1
384 #define PROT_WRITE 0x2
385 #define MAP_SHARED 0x1
386 #define MAP_PRIVATE 0x2 /* unsupported */
387 #define MAP_FIXED 0x10
388 #define MAP_ANONYMOUS 0x20 /* unsupported */
389 #define MAP_FAILED ((void *)-1)
391 #define MS_ASYNC 1 /* sync memory asynchronously */
392 #define MS_INVALIDATE 2 /* invalidate the caches */
393 #define MS_SYNC 4 /* synchronous memory sync */
397 long f_type; /* type of filesystem (see below) */
398 long f_bsize; /* optimal transfer block size */
399 long f_blocks; /* total data blocks in file system */
400 long f_bfree; /* free blocks in fs */
401 long f_bavail; /* free blocks avail to non-superuser */
402 long f_files; /* total file nodes in file system */
403 long f_ffree; /* free file nodes in fs */
404 long f_fsid; /* file system id */
405 long f_namelen; /* maximum length of filenames */
406 long f_spare[6]; /* spare for later */
408 #define sleep(secs) (Sleep(secs * 1000))
410 /*********************** statfs *****************************/
411 /* fake block size */
412 #define FAKED_BLOCK_SIZE 512
414 /* linux-compatible values for fs type */
415 #define MSDOS_SUPER_MAGIC 0x4d44
416 #define NTFS_SUPER_MAGIC 0x5346544E
418 /*********************** End of statfs ***********************/
420 #define SHUT_RDWR SD_BOTH
422 /* Operations for flock() */
423 #define LOCK_SH 1 /* shared lock */
424 #define LOCK_EX 2 /* exclusive lock */
425 #define LOCK_NB 4 /* or'd with one of the above to prevent
427 #define LOCK_UN 8 /* remove lock */
429 /* Not supported under MinGW */
464 #define SHUT_WR SD_SEND
465 #define SHUT_RD SD_RECEIVE
466 #define SHUT_RDWR SD_BOTH
471 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
473 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
474 BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
475 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
476 BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
477 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
478 wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
479 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
480 wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
482 long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
483 char *pszBuffer, long *pdLength);
484 long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
485 wchar_t *pszBuffer, long *pdLength);
487 BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
488 void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
489 void __win_DiscardHandleBlockingMode(int s);
490 int _win_isSocketValid(int s);
491 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
492 int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
494 int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
495 int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
497 unsigned plibc_get_handle_count();
499 typedef void (*TPanicProc) (int, char *);
500 void plibc_set_panic_proc(TPanicProc proc);
501 void plibc_set_stat_size_size(int iLength);
502 void plibc_set_stat_time_size(int iLength);
504 int flock(int fd, int operation);
505 int fsync(int fildes);
506 int inet_pton(int af, const char *src, void *dst);
507 int inet_pton4(const char *src, u_char *dst, int pton);
509 int inet_pton6(const char *src, u_char *dst);
511 int statfs(const char *path, struct statfs *buf);
512 const char *hstrerror(int err);
513 int mkstemp(char *tmplate);
514 char *strptime (const char *buf, const char *format, struct tm *tm);
515 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
517 struct tm *gmtime_r(const time_t *clock, struct tm *result);
520 int plibc_init(char *pszOrg, char *pszApp);
521 int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
522 void plibc_shutdown();
523 int plibc_initialized();
525 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
526 void SetErrnoFromWinsockError(long lWinError);
527 void SetHErrnoFromWinError(long lWinError);
528 void SetErrnoFromHRESULT(HRESULT hRes);
529 int GetErrnoFromWinsockError(long lWinError);
530 FILE *_win_fopen(const char *filename, const char *mode);
531 int _win_fclose(FILE *);
532 DIR *_win_opendir(const char *dirname);
533 struct dirent *_win_readdir(DIR *dirp);
534 int _win_closedir(DIR *dirp);
535 int _win_open(const char *filename, int oflag, ...);
537 char *_win_bindtextdomain(const char *domainname, const char *dirname);
539 int _win_chdir(const char *path);
540 int _win_close(int fd);
541 int _win_creat(const char *path, mode_t mode);
542 char *_win_ctime(const time_t *clock);
543 char *_win_ctime_r(const time_t *clock, char *buf);
544 int _win_fstat(int handle, struct stat *buffer);
545 int _win_ftruncate(int fildes, off_t length);
546 int _win_truncate(const char *fname, int distance);
547 int _win_kill(pid_t pid, int sig);
548 int _win_pipe(int *phandles);
549 int _win_mkfifo(const char *path, mode_t mode);
550 int _win_rmdir(const char *path);
551 int _win_access( const char *path, int mode );
552 int _win_chmod(const char *filename, int pmode);
553 char *realpath(const char *file_name, char *resolved_name);
554 long _win_random(void);
555 void _win_srandom(unsigned int seed);
556 int _win_remove(const char *path);
557 int _win_rename(const char *oldname, const char *newname);
558 int _win_stat(const char *path, struct stat *buffer);
559 int _win_stati64(const char *path, struct _stati64 *buffer);
560 long _win_sysconf(int name);
561 int _win_unlink(const char *filename);
562 int _win_write(int fildes, const void *buf, size_t nbyte);
563 int _win_read(int fildes, void *buf, size_t nbyte);
564 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
565 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
566 int _win_symlink(const char *path1, const char *path2);
567 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
568 unsigned long long offset);
569 int _win_msync(void *start, size_t length, int flags);
570 int _win_munmap(void *start, size_t length);
571 int _win_lstat(const char *path, struct stat *buf);
572 int _win_lstati64(const char *path, struct _stati64 *buf);
573 int _win_readlink(const char *path, char *buf, size_t bufsize);
574 int _win_accept(int s, struct sockaddr *addr, int *addrlen);
576 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
577 int _win_bind(int s, const struct sockaddr *name, int namelen);
578 int _win_connect(int s,const struct sockaddr *name, int namelen);
579 int _win_getpeername(int s, struct sockaddr *name,
581 int _win_getsockname(int s, struct sockaddr *name,
583 int _win_getsockopt(int s, int level, int optname, char *optval,
585 int _win_listen(int s, int backlog);
586 int _win_recv(int s, char *buf, int len, int flags);
587 int _win_recvfrom(int s, void *buf, int len, int flags,
588 struct sockaddr *from, int *fromlen);
589 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
590 const struct timeval *tv);
591 int _win_send(int s, const char *buf, int len, int flags);
592 int _win_sendto(int s, const char *buf, int len, int flags,
593 const struct sockaddr *to, int tolen);
594 int _win_setsockopt(int s, int level, int optname, const void *optval,
596 int _win_shutdown(int s, int how);
597 int _win_socket(int af, int type, int protocol);
598 int _win_socketpair(int af, int type, int protocol, int socket_vector[2]);
599 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
600 struct hostent *_win_gethostbyname(const char *name);
601 struct hostent *gethostbyname2(const char *name, int af);
602 char *_win_strerror(int errnum);
604 char *index(const char *s, int c);
605 char *_win_strtok_r (char *ptr, const char *sep, char **end);
608 char *strndup (const char *s, size_t n);
610 #if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
611 size_t strnlen (const char *str, size_t maxlen);
613 char *stpcpy(char *dest, const char *src);
614 char *strcasestr(const char *haystack_start, const char *needle_start);
615 #ifndef __MINGW64_VERSION_MAJOR
616 #define strcasecmp(a, b) stricmp(a, b)
617 #define strncasecmp(a, b, c) strnicmp(a, b, c)
620 #define wcscasecmp(a, b) wcsicmp(a, b)
623 #define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
625 #ifndef strtok_r /* winpthreads defines it in pthread.h */
626 #define strtok_r _win_strtok_r
631 #define DIR_SEPARATOR '/'
632 #define DIR_SEPARATOR_STR "/"
633 #define PATH_SEPARATOR ':'
634 #define PATH_SEPARATOR_STR ":"
638 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
640 #define CREAT(p, m) creat(p, m)
641 #define PLIBC_CTIME(c) ctime(c)
642 #define CTIME_R(c, b) ctime_r(c, b)
644 #define FOPEN(f, m) fopen(f, m)
645 #define FCLOSE(f) fclose(f)
646 #define FTRUNCATE(f, l) ftruncate(f, l)
647 #define TRUNCATE(f, l) truncate(f, l)
648 #define OPENDIR(d) opendir(d)
649 #define CLOSEDIR(d) closedir(d)
650 #define READDIR(d) readdir(d)
652 #define CHDIR(d) chdir(d)
653 #define CLOSE(f) close(f)
654 #define LSEEK(f, o, w) lseek(f, o, w)
655 #define RMDIR(f) rmdir(f)
656 #define ACCESS(p, m) access(p, m)
657 #define CHMOD(f, p) chmod(f, p)
658 #define FSTAT(h, b) fstat(h, b)
659 #define PLIBC_KILL(p, s) kill(p, s)
660 #define PIPE(h) pipe(h)
661 #define REMOVE(p) remove(p)
662 #define RENAME(o, n) rename(o, n)
663 #define STAT(p, b) stat(p, b)
664 #define STAT64(p, b) stat64(p, b)
665 #define SYSCONF(n) sysconf(n)
666 #define UNLINK(f) unlink(f)
667 #define WRITE(f, b, n) write(f, b, n)
668 #define READ(f, b, n) read(f, b, n)
669 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
670 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
671 #define SYMLINK(a, b) symlink(a, b)
672 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
673 #define MKFIFO(p, m) mkfifo(p, m)
674 #define MSYNC(s, l, f) msync(s, l, f)
675 #define MUNMAP(s, l) munmap(s, l)
676 #define STRERROR(i) strerror(i)
677 #define RANDOM() random()
678 #define SRANDOM(s) srandom(s)
679 #define READLINK(p, b, s) readlink(p, b, s)
680 #define LSTAT(p, b) lstat(p, b)
681 #define LSTAT64(p, b) lstat64(p, b)
682 #define PRINTF printf
683 #define FPRINTF fprintf
684 #define VPRINTF(f, a) vprintf(f, a)
685 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
686 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
687 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
688 #define _REAL_SNPRINTF snprintf
689 #define SPRINTF sprintf
690 #define VSSCANF(s, f, a) vsscanf(s, f, a)
691 #define SSCANF sscanf
692 #define VFSCANF(s, f, a) vfscanf(s, f, a)
693 #define VSCANF(f, a) vscanf(f, a)
695 #define FSCANF fscanf
696 #define WAITPID(p, s, o) waitpid(p, s, o)
697 #define ACCEPT(s, a, l) accept(s, a, l)
698 #define BIND(s, n, l) bind(s, n, l)
699 #define CONNECT(s, n, l) connect(s, n, l)
700 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
701 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
702 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
703 #define LISTEN(s, b) listen(s, b)
704 #define RECV(s, b, l, f) recv(s, b, l, f)
705 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
706 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
707 #define SEND(s, b, l, f) send(s, b, l, f)
708 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
709 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
710 #define SHUTDOWN(s, h) shutdown(s, h)
711 #define SOCKET(a, t, p) socket(a, t, p)
712 #define SOCKETPAIR(a, t, p, v) socketpair(a, t, p, v)
713 #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t)
714 #define GETHOSTBYNAME(n) gethostbyname(n)
715 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
716 #define INSQUE(e, p) insque(e, p)
717 #define REMQUE(e) remque(e)
718 #define HSEARCH(i, a) hsearch(i, a)
719 #define HCREATE(n) hcreate(n)
720 #define HDESTROY() hdestroy()
721 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
722 #define HCREATE_R(n, h) hcreate_r(n, h)
723 #define HDESTROY_R(h) hdestroy_r(h)
724 #define TSEARCH(k, r, c) tsearch(k, r, c)
725 #define TFIND(k, r, c) tfind(k, r, c)
726 #define TDELETE(k, r, c) tdelete(k, r, c)
727 #define TWALK(r, a) twalk(r, a)
728 #define TDESTROY(r, f) tdestroy(r, f)
729 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
730 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
731 #define STRUCT_STAT64 struct stat64
733 #define DIR_SEPARATOR '\\'
734 #define DIR_SEPARATOR_STR "\\"
735 #define PATH_SEPARATOR ';'
736 #define PATH_SEPARATOR_STR ";"
737 #define NEWLINE "\r\n"
740 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
742 #define CREAT(p, m) _win_creat(p, m)
743 #define PLIBC_CTIME(c) _win_ctime(c)
744 #define CTIME_R(c, b) _win_ctime_r(c, b)
745 #define FOPEN(f, m) _win_fopen(f, m)
746 #define FCLOSE(f) _win_fclose(f)
747 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
748 #define TRUNCATE(f, l) _win_truncate(f, l)
749 #define OPENDIR(d) _win_opendir(d)
750 #define CLOSEDIR(d) _win_closedir(d)
751 #define READDIR(d) _win_readdir(d)
752 #define OPEN _win_open
753 #define CHDIR(d) _win_chdir(d)
754 #define CLOSE(f) _win_close(f)
755 #define PLIBC_KILL(p, s) _win_kill(p, s)
756 #define LSEEK(f, o, w) lseek(f, o, w)
757 #define FSTAT(h, b) _win_fstat(h, b)
758 #define RMDIR(f) _win_rmdir(f)
759 #define ACCESS(p, m) _win_access(p, m)
760 #define CHMOD(f, p) _win_chmod(f, p)
761 #define PIPE(h) _win_pipe(h)
762 #define RANDOM() _win_random()
763 #define SRANDOM(s) _win_srandom(s)
764 #define REMOVE(p) _win_remove(p)
765 #define RENAME(o, n) _win_rename(o, n)
766 #define STAT(p, b) _win_stat(p, b)
767 #define STAT64(p, b) _win_stati64(p, b)
768 #define SYSCONF(n) _win_sysconf(n)
769 #define UNLINK(f) _win_unlink(f)
770 #define WRITE(f, b, n) _win_write(f, b, n)
771 #define READ(f, b, n) _win_read(f, b, n)
772 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
773 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
774 #define SYMLINK(a, b) _win_symlink(a, b)
775 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
776 #define MKFIFO(p, m) _win_mkfifo(p, m)
777 #define MSYNC(s, l, f) _win_msync(s, l, f)
778 #define MUNMAP(s, l) _win_munmap(s, l)
779 #define STRERROR(i) _win_strerror(i)
780 #define READLINK(p, b, s) _win_readlink(p, b, s)
781 #define LSTAT(p, b) _win_lstat(p, b)
782 #define LSTAT64(p, b) _win_lstati64(p, b)
783 #define PRINTF printf
784 #define FPRINTF fprintf
785 #define VPRINTF(f, a) vprintf(f, a)
786 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
787 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
788 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
789 #define _REAL_SNPRINTF snprintf
790 #define SPRINTF sprintf
791 #define VSSCANF(s, f, a) vsscanf(s, f, a)
792 #define SSCANF sscanf
793 #define VFSCANF(s, f, a) vfscanf(s, f, a)
794 #define VSCANF(f, a) vscanf(f, a)
796 #define FSCANF fscanf
797 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
798 #define ACCEPT(s, a, l) _win_accept(s, a, l)
799 #define BIND(s, n, l) _win_bind(s, n, l)
800 #define CONNECT(s, n, l) _win_connect(s, n, l)
801 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
802 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
803 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
804 #define LISTEN(s, b) _win_listen(s, b)
805 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
806 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
807 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
808 #define SEND(s, b, l, f) _win_send(s, b, l, f)
809 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
810 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
811 #define SHUTDOWN(s, h) _win_shutdown(s, h)
812 #define SOCKET(a, t, p) _win_socket(a, t, p)
813 #define SOCKETPAIR(a, t, p, v) _win_socketpair(a, t, p, v)
814 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t)
815 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
816 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
817 #define INSQUE(e, p) _win_insque(e, p)
818 #define REMQUE(e) _win_remque(e)
819 #define HSEARCH(i, a) _win_hsearch(i, a)
820 #define HCREATE(n) _win_hcreate(n)
821 #define HDESTROY() _win_hdestroy()
822 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
823 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
824 #define HDESTROY_R(h) _win_hdestroy_r(h)
825 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
826 #define TFIND(k, r, c) _win_tfind(k, r, c)
827 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
828 #define TWALK(r, a) _win_twalk(r, a)
829 #define TDESTROY(r, f) _win_tdestroy(r, f)
830 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
831 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
832 #define STRUCT_STAT64 struct _stati64
837 /* Prototype structure for a linked-list data structure.
838 This is the type used by the `insque' and `remque' functions. */
840 struct PLIBC_SEARCH_QELEM
842 struct qelem *q_forw;
843 struct qelem *q_back;
848 /* Insert ELEM into a doubly-linked list, after PREV. */
849 void _win_insque (void *__elem, void *__prev);
851 /* Unlink ELEM from the doubly-linked list that it is in. */
852 void _win_remque (void *__elem);
855 /* For use with hsearch(3). */
856 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
858 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
860 /* Action which shall be performed in the call the hsearch. */
868 typedef struct PLIBC_SEARCH_entry
875 /* The reentrant version has no static variables to maintain the state.
876 Instead the interface of all functions is extended to take an argument
877 which describes the current status. */
878 typedef struct _PLIBC_SEARCH_ENTRY
881 PLIBC_SEARCH_ENTRY entry;
886 /* Family of hash table handling functions. The functions also
887 have reentrant counterparts ending with _r. The non-reentrant
888 functions all work on a signle internal hashing table. */
890 /* Search for entry matching ITEM.key in internal hash table. If
891 ACTION is `FIND' return found entry or signal error by returning
892 NULL. If ACTION is `ENTER' replace existing data (if any) with
894 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
896 /* Create a new hashing table which will at most contain NEL elements. */
897 int _win_hcreate (size_t __nel);
899 /* Destroy current internal hashing table. */
900 void _win_hdestroy (void);
902 /* Data type for reentrant functions. */
903 struct PLIBC_SEARCH_hsearch_data
905 struct _PLIBC_SEARCH_ENTRY *table;
910 /* Reentrant versions which can handle multiple hashing tables at the
912 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
913 struct PLIBC_SEARCH_hsearch_data *__htab);
914 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
915 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
918 /* The tsearch routines are very interesting. They make many
919 assumptions about the compiler. It assumes that the first field
920 in node must be the "key" field, which points to the datum.
921 Everything depends on that. */
925 PLIBC_SEARCH_preorder,
926 PLIBC_SEARCH_postorder,
927 PLIBC_SEARCH_endorder,
932 /* Search for an entry matching the given KEY in the tree pointed to
933 by *ROOTP and insert a new element if not found. */
934 void *_win_tsearch (__const void *__key, void **__rootp,
935 PLIBC_SEARCH__compar_fn_t __compar);
937 /* Search for an entry matching the given KEY in the tree pointed to
938 by *ROOTP. If no matching entry is available return NULL. */
939 void *_win_tfind (__const void *__key, void *__const *__rootp,
940 PLIBC_SEARCH__compar_fn_t __compar);
942 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
943 void *_win_tdelete (__const void *__restrict __key,
944 void **__restrict __rootp,
945 PLIBC_SEARCH__compar_fn_t __compar);
947 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
950 /* Walk through the whole tree and call the ACTION callback for every node
952 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
954 /* Callback type for function to free a tree node. If the keys are atomic
955 data this function should do nothing. */
956 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
958 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
959 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
962 /* Perform linear search for KEY by comparing by COMPAR in an array
963 [BASE,BASE+NMEMB*SIZE). */
964 void *_win_lfind (__const void *__key, __const void *__base,
965 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
967 /* Perform linear search for KEY by comparing by COMPAR function in
968 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
969 void *_win_lsearch (__const void *__key, void *__base,
970 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);