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 __MINGW64_VERSION_MAJOR
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 /* Thanks to the Cygwin project */
120 # define ENOCSI 43 /* No CSI structure available */
123 # define EL2HLT 44 /* Level 2 halted */
125 #if !defined(EDEADLK)
126 # define EDEADLK 45 /* Deadlock condition */
129 # define ENOLCK 46 /* No record locks available */
132 # define EBADE 50 /* Invalid exchange */
135 # define EBADR 51 /* Invalid request descriptor */
138 # define EXFULL 52 /* Exchange full */
141 # define ENOANO 53 /* No anode */
143 #if !defined(EBADRQC)
144 # define EBADRQC 54 /* Invalid request code */
146 #if !defined(EBADSLT)
147 # define EBADSLT 55 /* Invalid slot */
149 #if !defined(EDEADLOCK)
150 # define EDEADLOCK EDEADLK /* File locking deadlock error */
153 # define EBFONT 57 /* Bad font file fmt */
156 # define ENOSTR 60 /* Device not a stream */
158 #if !defined(ENODATA)
159 # define ENODATA 61 /* No data (for no delay io) */
162 # define ETIME 62 /* Timer expired */
165 # define ENOSR 63 /* Out of streams resources */
168 # define ENONET 64 /* Machine is not on the network */
171 # define ENOPKG 65 /* Package not installed */
173 #if !defined(EREMOTE)
174 # define EREMOTE 66 /* The object is remote */
176 #if !defined(ENOLINK)
177 # define ENOLINK 67 /* The link has been severed */
180 # define EADV 68 /* Advertise error */
183 # define ESRMNT 69 /* Srmount error */
186 # define ECOMM 70 /* Communication error on send */
188 #if !defined(EMULTIHOP)
189 # define EMULTIHOP 74 /* Multihop attempted */
192 # define ELBIN 75 /* Inode is remote (not really error) */
194 #if !defined(EDOTDOT)
195 # define EDOTDOT 76 /* Cross mount point (not really error) */
197 #if !defined(EBADMSG)
198 # define EBADMSG 77 /* Trying to read unreadable message */
200 #if !defined(ENOTUNIQ)
201 # define ENOTUNIQ 80 /* Given log. name not unique */
204 # define EBADFD 81 /* f.d. invalid for this operation */
206 #if !defined(EREMCHG)
207 # define EREMCHG 82 /* Remote address changed */
209 #if !defined(ELIBACC)
210 # define ELIBACC 83 /* Can't access a needed shared lib */
212 #if !defined(ELIBBAD)
213 # define ELIBBAD 84 /* Accessing a corrupted shared lib */
215 #if !defined(ELIBSCN)
216 # define ELIBSCN 85 /* .lib section in a.out corrupted */
218 #if !defined(ELIBMAX)
219 # define ELIBMAX 86 /* Attempting to link in too many libs */
221 #if !defined(ELIBEXEC)
222 # define ELIBEXEC 87 /* Attempting to exec a shared library */
225 # define ENOSYS 88 /* Function not implemented */
227 #if !defined(ENMFILE)
228 # define ENMFILE 89 /* No more files */
230 #if !defined(ENOTEMPTY)
231 # define ENOTEMPTY 90 /* Directory not empty */
233 #if !defined(ENAMETOOLONG)
234 # define ENAMETOOLONG 91 /* File or path name too long */
236 #if !defined(EPFNOSUPPORT)
237 # define EPFNOSUPPORT 96 /* Protocol family not supported */
239 #if !defined(ENOSHARE)
240 # define ENOSHARE 97 /* No such host or network path */
242 #if !defined(ENOMEDIUM)
243 # define ENOMEDIUM 98 /* No medium (in tape drive) */
245 #if !defined(ESHUTDOWN)
246 # define ESHUTDOWN 99 /* Can't send after socket shutdown */
248 #if !defined(EADDRINUSE)
249 # define EADDRINUSE 100 /* Address already in use */
251 #if !defined(EADDRNOTAVAIL)
252 # define EADDRNOTAVAIL 101 /* Address not available */
254 #if !defined(EAFNOSUPPORT)
255 # define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
257 #if !defined(EALREADY)
258 # define EALREADY 103 /* Socket already connected */
260 #if !defined(ECANCELED)
261 # define ECANCELED 105 /* Connection cancelled */
263 #if !defined(ECONNABORTED)
264 # define ECONNABORTED 106 /* Connection aborted */
266 #if !defined(ECONNREFUSED)
267 # define ECONNREFUSED 107 /* Connection refused */
269 #if !defined(ECONNRESET)
270 # define ECONNRESET 108 /* Connection reset by peer */
272 #if !defined(EDESTADDRREQ)
273 # define EDESTADDRREQ 109 /* Destination address required */
275 #if !defined(EHOSTUNREACH)
276 # define EHOSTUNREACH 110 /* Host is unreachable */
278 #if !defined(ECONNABORTED)
279 # define ECONNABORTED 111 /* Connection aborted */
281 #if !defined(EINPROGRESS)
282 # define EINPROGRESS 112 /* Connection already in progress */
284 #if !defined(EISCONN)
285 # define EISCONN 113 /* Socket is already connected */
288 # define ELOOP 114 /* Too many symbolic links */
290 #if !defined(EMSGSIZE)
291 # define EMSGSIZE 115 /* Message too long */
293 #if !defined(ENETDOWN)
294 # define ENETDOWN 116 /* Network interface is not configured */
296 #if !defined(ENETRESET)
297 # define ENETRESET 117 /* Connection aborted by network */
299 #if !defined(ENETUNREACH)
300 # define ENETUNREACH 118 /* Network is unreachable */
302 #if !defined(ENOBUFS)
303 # define ENOBUFS 119 /* No buffer space available */
305 #if !defined(EHOSTDOWN)
306 # define EHOSTDOWN 120 /* Host is down */
308 #if !defined(EPROCLIM)
309 # define EPROCLIM 121 /* Too many processes */
312 # define EDQUOT 122 /* Disk quota exceeded */
314 #if !defined(ENOPROTOOPT)
315 # define ENOPROTOOPT 123 /* Protocol not available */
317 #if !defined(ESOCKTNOSUPPORT)
318 # define ESOCKTNOSUPPORT 124 /* Socket type not supported */
321 # define ESTALE 125 /* Unknown error */
323 #if !defined(ENOTCONN)
324 # define ENOTCONN 126 /* Socket is not connected */
326 #if !defined(ETOOMANYREFS)
327 # define ETOOMANYREFS 127 /* Too many references: cannot splice */
329 #if !defined(ENOTSOCK)
330 # define ENOTSOCK 128 /* Socket operation on non-socket */
332 #if !defined(ENOTSUP)
333 # define ENOTSUP 129 /* Not supported */
335 #if !defined(EOPNOTSUPP)
336 # define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
339 # define EUSERS 131 /* Too many users */
341 #if !defined(EOVERFLOW)
342 # define EOVERFLOW 132 /* Value too large for defined data type */
344 #if !defined(EOWNERDEAD)
345 # define EOWNERDEAD 133 /* Unknown error */
348 # define EPROTO 134 /* Protocol error */
350 #if !defined(EPROTONOSUPPORT)
351 # define EPROTONOSUPPORT 135 /* Unknown protocol */
353 #if !defined(EPROTOTYPE)
354 # define EPROTOTYPE 136 /* Protocol wrong type for socket */
356 #if !defined(ECASECLASH)
357 # define ECASECLASH 137 /* Filename exists with different case */
359 #if !defined(ETIMEDOUT)
360 /* Make sure it's the same as WSATIMEDOUT */
361 # define ETIMEDOUT 138 /* Connection timed out */
363 #if !defined(EWOULDBLOCK) || EWOULBLOCK == 140
364 # undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
365 # define EWOULDBLOCK EAGAIN /* Operation would block */
368 #undef HOST_NOT_FOUND
369 #define HOST_NOT_FOUND 1
373 #define NO_RECOVERY 3
377 #define PROT_READ 0x1
378 #define PROT_WRITE 0x2
379 #define MAP_SHARED 0x1
380 #define MAP_PRIVATE 0x2 /* unsupported */
381 #define MAP_FIXED 0x10
382 #define MAP_ANONYMOUS 0x20 /* unsupported */
383 #define MAP_FAILED ((void *)-1)
385 #define MS_ASYNC 1 /* sync memory asynchronously */
386 #define MS_INVALIDATE 2 /* invalidate the caches */
387 #define MS_SYNC 4 /* synchronous memory sync */
391 long f_type; /* type of filesystem (see below) */
392 long f_bsize; /* optimal transfer block size */
393 long f_blocks; /* total data blocks in file system */
394 long f_bfree; /* free blocks in fs */
395 long f_bavail; /* free blocks avail to non-superuser */
396 long f_files; /* total file nodes in file system */
397 long f_ffree; /* free file nodes in fs */
398 long f_fsid; /* file system id */
399 long f_namelen; /* maximum length of filenames */
400 long f_spare[6]; /* spare for later */
403 /* Taken from the Wine project <http://www.winehq.org>
404 /wine/include/winternl.h */
405 enum SYSTEM_INFORMATION_CLASS
407 SystemBasicInformation = 0,
409 SystemPerformanceInformation = 2,
410 SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
412 SystemProcessInformation = 5,
415 SystemProcessorPerformanceInformation = 8,
418 SystemDriverInformation,
428 SystemCacheInformation,
430 SystemInterruptInformation = 23,
431 SystemExceptionInformation = 33,
432 SystemRegistryQuotaInformation = 37,
433 SystemLookasideInformation = 45
438 LARGE_INTEGER IdleTime;
439 LARGE_INTEGER KernelTime;
440 LARGE_INTEGER UserTime;
441 LARGE_INTEGER Reserved1[2];
443 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
445 #define sleep(secs) (Sleep(secs * 1000))
447 /*********************** statfs *****************************/
448 /* fake block size */
449 #define FAKED_BLOCK_SIZE 512
451 /* linux-compatible values for fs type */
452 #define MSDOS_SUPER_MAGIC 0x4d44
453 #define NTFS_SUPER_MAGIC 0x5346544E
455 /*********************** End of statfs ***********************/
457 #define SHUT_RDWR SD_BOTH
459 /* Operations for flock() */
460 #define LOCK_SH 1 /* shared lock */
461 #define LOCK_EX 2 /* exclusive lock */
462 #define LOCK_NB 4 /* or'd with one of the above to prevent
464 #define LOCK_UN 8 /* remove lock */
466 /* Not supported under MinGW */
479 #define SHUT_WR SD_SEND
480 #define SHUT_RD SD_RECEIVE
481 #define SHUT_RDWR SD_BOTH
486 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
488 BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
489 BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
490 BOOL _plibc_DereferenceShortcut(char *pszShortcut);
491 BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
492 char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
493 wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
494 char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
495 wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
497 long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
498 char *pszBuffer, long *pdLength);
499 long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
500 wchar_t *pszBuffer, long *pdLength);
502 BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
503 void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
504 void __win_DiscardHandleBlockingMode(int s);
505 int _win_isSocketValid(int s);
506 int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
507 int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
509 int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
510 int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
512 unsigned plibc_get_handle_count();
514 typedef void (*TPanicProc) (int, char *);
515 void plibc_set_panic_proc(TPanicProc proc);
517 int flock(int fd, int operation);
518 int fsync(int fildes);
519 int inet_pton(int af, const char *src, void *dst);
520 int inet_pton4(const char *src, u_char *dst, int pton);
522 int inet_pton6(const char *src, u_char *dst);
524 #if !defined(FTRUNCATE_DEFINED)
525 int truncate(const char *fname, int distance);
527 int statfs(const char *path, struct statfs *buf);
528 const char *hstrerror(int err);
529 int mkstemp(char *tmplate);
530 char *strptime (const char *buf, const char *format, struct tm *tm);
531 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
533 struct tm *gmtime_r(const time_t *clock, struct tm *result);
536 int plibc_init(char *pszOrg, char *pszApp);
537 int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
538 void plibc_shutdown();
539 int plibc_initialized();
541 void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
542 void SetErrnoFromWinsockError(long lWinError);
543 void SetHErrnoFromWinError(long lWinError);
544 void SetErrnoFromHRESULT(HRESULT hRes);
545 int GetErrnoFromWinsockError(long lWinError);
546 FILE *_win_fopen(const char *filename, const char *mode);
547 int _win_fclose(FILE *);
548 DIR *_win_opendir(const char *dirname);
549 struct dirent *_win_readdir(DIR *dirp);
550 int _win_closedir(DIR *dirp);
551 int _win_open(const char *filename, int oflag, ...);
553 char *_win_bindtextdomain(const char *domainname, const char *dirname);
555 int _win_chdir(const char *path);
556 int _win_close(int fd);
557 int _win_creat(const char *path, mode_t mode);
558 char *_win_ctime(const time_t *clock);
559 char *_win_ctime_r(const time_t *clock, char *buf);
560 int _win_fstat(int handle, struct stat *buffer);
561 off_t _win_lseek(int fildes, off_t offset, int whence);
562 int _win_ftruncate(int fildes, off_t length);
563 void _win_gettimeofday(struct timeval *tp, void *tzp);
564 int _win_kill(pid_t pid, int sig);
565 int _win_pipe(int *phandles);
566 intptr_t _win_mkfifo(const char *path, mode_t mode);
567 int _win_rmdir(const char *path);
568 int _win_access( const char *path, int mode );
569 int _win_chmod(const char *filename, int pmode);
570 char *realpath(const char *file_name, char *resolved_name);
571 long _win_random(void);
572 void _win_srandom(unsigned int seed);
573 int _win_remove(const char *path);
574 int _win_rename(const char *oldname, const char *newname);
575 int _win_stat(const char *path, struct stat *buffer);
576 int _win_stat64(const char *path, struct stat64 *buffer);
577 long _win_sysconf(int name);
578 int _win_unlink(const char *filename);
579 int _win_write(int fildes, const void *buf, size_t nbyte);
580 int _win_read(int fildes, void *buf, size_t nbyte);
581 size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
582 size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
583 int _win_symlink(const char *path1, const char *path2);
584 void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
585 unsigned long long offset);
586 int _win_msync(void *start, size_t length, int flags);
587 int _win_munmap(void *start, size_t length);
588 int _win_lstat(const char *path, struct stat *buf);
589 int _win_lstat64(const char *path, struct stat64 *buf);
590 int _win_readlink(const char *path, char *buf, size_t bufsize);
591 int _win_accept(int s, struct sockaddr *addr, int *addrlen);
593 int _win_printf(const char *format,...);
594 int _win_wprintf(const wchar_t *format, ...);
596 int _win_fprintf(FILE *f,const char *format,...);
597 int _win_fwprintf(FILE *f,const wchar_t *format, ...);
599 int _win_vprintf(const char *format, va_list ap);
600 int _win_vfwprintf(FILE *stream, const wchar_t *format, va_list arg_ptr);
602 int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
603 int _win_vwprintf(const wchar_t *format, va_list ap);
605 int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
606 int _win_vswprintf(wchar_t *dest, const wchar_t *format, va_list arg_ptr);
608 int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr);
609 int _win_vsnwprintf(wchar_t* wstr, size_t size, const wchar_t *format, va_list arg_ptr);
611 int _win_snprintf(char *str,size_t size,const char *format,...);
612 int _win_snwprintf(wchar_t *str, size_t size, const wchar_t *format, ...);
614 int _win_sprintf(char *dest,const char *format,...);
615 int _win_swprintf(wchar_t *dest, const wchar_t *format, ...);
617 int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
618 int _win_vswscanf(const wchar_t* wstr, const wchar_t* format, va_list arg_ptr);
620 int _win_sscanf(const char *str, const char *format, ...);
621 int _win_swscanf(const wchar_t *wstr, const wchar_t *format, ...);
623 int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
624 int _win_vfwscanf(FILE *stream, const wchar_t *format, va_list arg_ptr);
626 int _win_vscanf(const char *format, va_list arg_ptr);
627 int _win_vwscanf(const wchar_t *format, va_list arg_ptr);
629 int _win_scanf(const char *format, ...);
630 int _win_wscanf(const wchar_t *format, ...);
632 int _win_fscanf(FILE *stream, const char *format, ...);
633 int _win_fwscanf(FILE *stream, const wchar_t *format, ...);
636 pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
637 int _win_bind(int s, const struct sockaddr *name, int namelen);
638 int _win_connect(int s,const struct sockaddr *name, int namelen);
639 int _win_getpeername(int s, struct sockaddr *name,
641 int _win_getsockname(int s, struct sockaddr *name,
643 int _win_getsockopt(int s, int level, int optname, char *optval,
645 int _win_listen(int s, int backlog);
646 int _win_recv(int s, char *buf, int len, int flags);
647 int _win_recvfrom(int s, void *buf, int len, int flags,
648 struct sockaddr *from, int *fromlen);
649 int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
650 const struct timeval *tv);
651 int _win_send(int s, const char *buf, int len, int flags);
652 int _win_sendto(int s, const char *buf, int len, int flags,
653 const struct sockaddr *to, int tolen);
654 int _win_setsockopt(int s, int level, int optname, const void *optval,
656 int _win_shutdown(int s, int how);
657 int _win_socket(int af, int type, int protocol);
658 struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
659 struct hostent *_win_gethostbyname(const char *name);
660 struct hostent *gethostbyname2(const char *name, int af);
661 char *_win_strerror(int errnum);
663 char *index(const char *s, int c);
666 char *strndup (const char *s, size_t n);
668 #if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
669 size_t strnlen (const char *str, size_t maxlen);
672 char *strtok_r (char *ptr, const char *sep, char **end);
674 char *stpcpy(char *dest, const char *src);
675 char *strcasestr(const char *haystack_start, const char *needle_start);
676 #ifndef __MINGW64_VERSION_MAJOR
677 #define strcasecmp(a, b) stricmp(a, b)
678 #define strncasecmp(a, b, c) strnicmp(a, b, c)
681 #define wcscasecmp(a, b) wcsicmp(a, b)
684 #define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
689 #define DIR_SEPARATOR '/'
690 #define DIR_SEPARATOR_STR "/"
691 #define PATH_SEPARATOR ':'
692 #define PATH_SEPARATOR_STR ":"
696 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
698 #define CREAT(p, m) creat(p, m)
699 #define PLIBC_CTIME(c) ctime(c)
700 #define CTIME_R(c, b) ctime_r(c, b)
702 #define FOPEN(f, m) fopen(f, m)
703 #define FCLOSE(f) fclose(f)
704 #define FTRUNCATE(f, l) ftruncate(f, l)
705 #define OPENDIR(d) opendir(d)
706 #define CLOSEDIR(d) closedir(d)
707 #define READDIR(d) readdir(d)
709 #define CHDIR(d) chdir(d)
710 #define CLOSE(f) close(f)
711 #define LSEEK(f, o, w) lseek(f, o, w)
712 #define RMDIR(f) rmdir(f)
713 #define ACCESS(p, m) access(p, m)
714 #define CHMOD(f, p) chmod(f, p)
715 #define FSTAT(h, b) fstat(h, b)
716 #define PLIBC_KILL(p, s) kill(p, s)
717 #define PIPE(h) pipe(h)
718 #define REMOVE(p) remove(p)
719 #define RENAME(o, n) rename(o, n)
720 #define STAT(p, b) stat(p, b)
721 #define STAT64(p, b) stat64(p, b)
722 #define SYSCONF(n) sysconf(n)
723 #define UNLINK(f) unlink(f)
724 #define WRITE(f, b, n) write(f, b, n)
725 #define READ(f, b, n) read(f, b, n)
726 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
727 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
728 #define SYMLINK(a, b) symlink(a, b)
729 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
730 #define MKFIFO(p, m) mkfifo(p, m)
731 #define MSYNC(s, l, f) msync(s, l, f)
732 #define MUNMAP(s, l) munmap(s, l)
733 #define STRERROR(i) strerror(i)
734 #define RANDOM() random()
735 #define SRANDOM(s) srandom(s)
736 #define READLINK(p, b, s) readlink(p, b, s)
737 #define LSTAT(p, b) lstat(p, b)
738 #define LSTAT64(p, b) lstat64(p, b)
739 #define PRINTF printf
740 #define FPRINTF fprintf
741 #define VPRINTF(f, a) vprintf(f, a)
742 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
743 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
744 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
745 #define _REAL_SNPRINTF snprintf
746 #define SPRINTF sprintf
747 #define VSSCANF(s, f, a) vsscanf(s, f, a)
748 #define SSCANF sscanf
749 #define VFSCANF(s, f, a) vfscanf(s, f, a)
750 #define VSCANF(f, a) vscanf(f, a)
752 #define FSCANF fscanf
753 #define WAITPID(p, s, o) waitpid(p, s, o)
754 #define ACCEPT(s, a, l) accept(s, a, l)
755 #define BIND(s, n, l) bind(s, n, l)
756 #define CONNECT(s, n, l) connect(s, n, l)
757 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
758 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
759 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
760 #define LISTEN(s, b) listen(s, b)
761 #define RECV(s, b, l, f) recv(s, b, l, f)
762 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
763 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
764 #define SEND(s, b, l, f) send(s, b, l, f)
765 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
766 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
767 #define SHUTDOWN(s, h) shutdown(s, h)
768 #define SOCKET(a, t, p) socket(a, t, p)
769 #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t)
770 #define GETHOSTBYNAME(n) gethostbyname(n)
771 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
772 #define INSQUE(e, p) insque(e, p)
773 #define REMQUE(e) remque(e)
774 #define HSEARCH(i, a) hsearch(i, a)
775 #define HCREATE(n) hcreate(n)
776 #define HDESTROY() hdestroy()
777 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
778 #define HCREATE_R(n, h) hcreate_r(n, h)
779 #define HDESTROY_R(h) hdestroy_r(h)
780 #define TSEARCH(k, r, c) tsearch(k, r, c)
781 #define TFIND(k, r, c) tfind(k, r, c)
782 #define TDELETE(k, r, c) tdelete(k, r, c)
783 #define TWALK(r, a) twalk(r, a)
784 #define TDESTROY(r, f) tdestroy(r, f)
785 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
786 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
788 #define DIR_SEPARATOR '\\'
789 #define DIR_SEPARATOR_STR "\\"
790 #define PATH_SEPARATOR ';'
791 #define PATH_SEPARATOR_STR ";"
792 #define NEWLINE "\r\n"
795 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
797 #define CREAT(p, m) _win_creat(p, m)
798 #define PLIBC_CTIME(c) _win_ctime(c)
799 #define CTIME_R(c, b) _win_ctime_r(c, b)
800 #define FOPEN(f, m) _win_fopen(f, m)
801 #define FCLOSE(f) _win_fclose(f)
802 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
803 #define OPENDIR(d) _win_opendir(d)
804 #define CLOSEDIR(d) _win_closedir(d)
805 #define READDIR(d) _win_readdir(d)
806 #define OPEN _win_open
807 #define CHDIR(d) _win_chdir(d)
808 #define CLOSE(f) _win_close(f)
809 #define PLIBC_KILL(p, s) _win_kill(p, s)
810 #define LSEEK(f, o, w) _win_lseek(f, o, w)
811 #define FSTAT(h, b) _win_fstat(h, b)
812 #define RMDIR(f) _win_rmdir(f)
813 #define ACCESS(p, m) _win_access(p, m)
814 #define CHMOD(f, p) _win_chmod(f, p)
815 #define PIPE(h) _win_pipe(h)
816 #define RANDOM() _win_random()
817 #define SRANDOM(s) _win_srandom(s)
818 #define REMOVE(p) _win_remove(p)
819 #define RENAME(o, n) _win_rename(o, n)
820 #define STAT(p, b) _win_stat(p, b)
821 #define STAT64(p, b) _win_stat64(p, b)
822 #define SYSCONF(n) _win_sysconf(n)
823 #define UNLINK(f) _win_unlink(f)
824 #define WRITE(f, b, n) _win_write(f, b, n)
825 #define READ(f, b, n) _win_read(f, b, n)
826 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
827 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
828 #define SYMLINK(a, b) _win_symlink(a, b)
829 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
830 #define MKFIFO(p, m) _win_mkfifo(p, m)
831 #define MSYNC(s, l, f) _win_msync(s, l, f)
832 #define MUNMAP(s, l) _win_munmap(s, l)
833 #define STRERROR(i) _win_strerror(i)
834 #define READLINK(p, b, s) _win_readlink(p, b, s)
835 #define LSTAT(p, b) _win_lstat(p, b)
836 #define LSTAT64(p, b) _win_lstat64(p, b)
837 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
838 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
839 #define VPRINTF(f, a) _win_vprintf(f, a)
840 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
841 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
842 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
843 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
844 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
845 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
846 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
847 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
848 #define VSCANF(f, a) _win_vscanf(f, a)
849 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
850 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
851 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
852 #define ACCEPT(s, a, l) _win_accept(s, a, l)
853 #define BIND(s, n, l) _win_bind(s, n, l)
854 #define CONNECT(s, n, l) _win_connect(s, n, l)
855 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
856 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
857 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
858 #define LISTEN(s, b) _win_listen(s, b)
859 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
860 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
861 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
862 #define SEND(s, b, l, f) _win_send(s, b, l, f)
863 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
864 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
865 #define SHUTDOWN(s, h) _win_shutdown(s, h)
866 #define SOCKET(a, t, p) _win_socket(a, t, p)
867 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t)
868 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
869 #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
870 #define INSQUE(e, p) _win_insque(e, p)
871 #define REMQUE(e) _win_remque(e)
872 #define HSEARCH(i, a) _win_hsearch(i, a)
873 #define HCREATE(n) _win_hcreate(n)
874 #define HDESTROY() _win_hdestroy()
875 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
876 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
877 #define HDESTROY_R(h) _win_hdestroy_r(h)
878 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
879 #define TFIND(k, r, c) _win_tfind(k, r, c)
880 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
881 #define TWALK(r, a) _win_twalk(r, a)
882 #define TDESTROY(r, f) _win_tdestroy(r, f)
883 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
884 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
889 /* Prototype structure for a linked-list data structure.
890 This is the type used by the `insque' and `remque' functions. */
892 struct PLIBC_SEARCH_QELEM
894 struct qelem *q_forw;
895 struct qelem *q_back;
900 /* Insert ELEM into a doubly-linked list, after PREV. */
901 void _win_insque (void *__elem, void *__prev);
903 /* Unlink ELEM from the doubly-linked list that it is in. */
904 void _win_remque (void *__elem);
907 /* For use with hsearch(3). */
908 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
910 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
912 /* Action which shall be performed in the call the hsearch. */
920 typedef struct PLIBC_SEARCH_entry
927 /* The reentrant version has no static variables to maintain the state.
928 Instead the interface of all functions is extended to take an argument
929 which describes the current status. */
930 typedef struct _PLIBC_SEARCH_ENTRY
933 PLIBC_SEARCH_ENTRY entry;
938 /* Family of hash table handling functions. The functions also
939 have reentrant counterparts ending with _r. The non-reentrant
940 functions all work on a signle internal hashing table. */
942 /* Search for entry matching ITEM.key in internal hash table. If
943 ACTION is `FIND' return found entry or signal error by returning
944 NULL. If ACTION is `ENTER' replace existing data (if any) with
946 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
948 /* Create a new hashing table which will at most contain NEL elements. */
949 int _win_hcreate (size_t __nel);
951 /* Destroy current internal hashing table. */
952 void _win_hdestroy (void);
954 /* Data type for reentrant functions. */
955 struct PLIBC_SEARCH_hsearch_data
957 struct _PLIBC_SEARCH_ENTRY *table;
962 /* Reentrant versions which can handle multiple hashing tables at the
964 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
965 struct PLIBC_SEARCH_hsearch_data *__htab);
966 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
967 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
970 /* The tsearch routines are very interesting. They make many
971 assumptions about the compiler. It assumes that the first field
972 in node must be the "key" field, which points to the datum.
973 Everything depends on that. */
977 PLIBC_SEARCH_preorder,
978 PLIBC_SEARCH_postorder,
979 PLIBC_SEARCH_endorder,
984 /* Search for an entry matching the given KEY in the tree pointed to
985 by *ROOTP and insert a new element if not found. */
986 void *_win_tsearch (__const void *__key, void **__rootp,
987 PLIBC_SEARCH__compar_fn_t __compar);
989 /* Search for an entry matching the given KEY in the tree pointed to
990 by *ROOTP. If no matching entry is available return NULL. */
991 void *_win_tfind (__const void *__key, void *__const *__rootp,
992 PLIBC_SEARCH__compar_fn_t __compar);
994 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
995 void *_win_tdelete (__const void *__restrict __key,
996 void **__restrict __rootp,
997 PLIBC_SEARCH__compar_fn_t __compar);
999 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
1002 /* Walk through the whole tree and call the ACTION callback for every node
1004 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
1006 /* Callback type for function to free a tree node. If the keys are atomic
1007 data this function should do nothing. */
1008 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
1010 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
1011 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
1014 /* Perform linear search for KEY by comparing by COMPAR in an array
1015 [BASE,BASE+NMEMB*SIZE). */
1016 void *_win_lfind (__const void *__key, __const void *__base,
1017 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
1019 /* Perform linear search for KEY by comparing by COMPAR function in
1020 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
1021 void *_win_lsearch (__const void *__key, void *__base,
1022 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
1032 /* end of plibc.h */