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
71 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
72 (double)((x).LowPart))
89 typedef unsigned int sa_family_t;
105 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
109 #define MSG_DONTWAIT 0
134 #define EDEADLOCK EDEADLK
169 #define ENAMETOOLONG 91
172 #define EOPNOTSUPP 95
173 #define EPFNOSUPPORT 96
174 #define ECONNRESET 104
176 #define EAFNOSUPPORT 106
177 #define EPROTOTYPE 107
179 #define ENOPROTOOPT 109
180 #define ESHUTDOWN 110
181 #define ECONNREFUSED 111
182 #define EADDRINUSE 112
183 #define ECONNABORTED 113
184 #define ENETUNREACH 114
187 #define ETIMEDOUT 116
189 #define EHOSTDOWN 117
190 #define EHOSTUNREACH 118
191 #define EINPROGRESS 119
193 #define EDESTADDRREQ 121
195 #define EPROTONOSUPPORT 123
196 #define ESOCKTNOSUPPORT 124
197 #define EADDRNOTAVAIL 125
198 #define ENETRESET 126
201 #define ETOOMANYREFS 129
209 #define ENOMEDIUM 135
211 #define ECASECLASH 137
212 #define EWOULDBLOCK EAGAIN
213 #define EOVERFLOW 139
215 #undef HOST_NOT_FOUND
216 #define HOST_NOT_FOUND 1
220 #define NO_RECOVERY 3
224 #define PROT_READ 0x1
225 #define PROT_WRITE 0x2
226 #define MAP_SHARED 0x1
227 #define MAP_PRIVATE 0x2
228 #define MAP_FIXED 0x10
229 #define MAP_FAILED ((void *)-1)
245 extern const struct in6_addr in6addr_any;
246 extern const struct in6_addr in6addr_loopback;
250 enum SYSTEM_INFORMATION_CLASS
252 SystemBasicInformation = 0,
254 SystemPerformanceInformation = 2,
255 SystemTimeOfDayInformation = 3,
257 SystemProcessInformation = 5,
260 SystemProcessorPerformanceInformation = 8,
263 SystemDriverInformation,
273 SystemCacheInformation,
275 SystemInterruptInformation = 23,
276 SystemExceptionInformation = 33,
277 SystemRegistryQuotaInformation = 37,
278 SystemLookasideInformation = 45
283 LARGE_INTEGER IdleTime;
284 LARGE_INTEGER KernelTime;
285 LARGE_INTEGER UserTime;
286 LARGE_INTEGER Reserved1[2];
288 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
290 #define sleep(secs) (Sleep(secs * 1000))
294 #define FAKED_BLOCK_SIZE 512
297 #define MSDOS_SUPER_MAGIC 0x4d44
298 #define NTFS_SUPER_MAGIC 0x5346544E
302 #define SHUT_RDWR SD_BOTH
324 #define SHUT_WR SD_SEND
325 #define SHUT_RD SD_RECEIVE
326 #define SHUT_RDWR SD_BOTH
331 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
333 BOOL _plibc_CreateShortcut(
const char *pszSrc,
const char *pszDest);
334 BOOL _plibc_DereferenceShortcut(
char *pszShortcut);
335 char *plibc_ChooseDir(
char *pszTitle,
unsigned long ulFlags);
336 char *plibc_ChooseFile(
char *pszTitle,
unsigned long ulFlags);
337 long QueryRegistry(HKEY hMainKey,
char *pszKey,
char *pszSubKey,
338 char *pszBuffer,
long *pdLength);
340 BOOL __win_IsHandleMarkedAsBlocking(
int hHandle);
341 void __win_SetHandleBlockingMode(
int s, BOOL bBlocking);
342 void __win_DiscardHandleBlockingMode(
int s);
343 int _win_isSocketValid(
int s);
344 int plibc_conv_to_win_path(
const char *pszUnix,
char *pszWindows);
345 unsigned plibc_get_handle_count();
347 typedef void (*TPanicProc) (int,
char *);
348 void plibc_set_panic_proc(TPanicProc proc);
350 int flock(
int fd,
int operation);
351 int fsync(
int fildes);
352 int inet_pton(
int af,
const char *src,
void *dst);
353 int inet_pton4(
const char *src, u_char *dst,
int pton);
355 int inet_pton6(
const char *src, u_char *dst);
357 int truncate(
const char *fname,
int distance);
358 int statfs(
const char *path,
struct statfs *buf);
359 const char *hstrerror(
int err);
360 int mkstemp(
char *tmplate);
361 char *strptime (
const char *buf,
const char *format,
struct tm *tm);
362 const char *inet_ntop(
int af,
const void *src,
char *dst,
size_t size);
364 int plibc_init(
char *pszOrg,
char *pszApp);
365 void plibc_shutdown();
366 int plibc_initialized();
367 int plibc_conv_to_win_path_ex(
const char *pszUnix,
char *pszWindows,
int derefLinks);
368 void _SetErrnoFromWinError(
long lWinError,
char *pszCaller,
int iLine);
369 void SetErrnoFromWinsockError(
long lWinError);
370 void SetHErrnoFromWinError(
long lWinError);
371 void SetErrnoFromHRESULT(HRESULT hRes);
372 int GetErrnoFromWinsockError(
long lWinError);
373 FILE *_win_fopen(
const char *filename,
const char *mode);
374 DIR *_win_opendir(
const char *dirname);
375 int _win_open(
const char *filename,
int oflag, ...);
377 char *_win_bindtextdomain(
const char *domainname,
const char *dirname);
379 int _win_chdir(
const char *path);
380 int _win_close(
int fd);
381 int _win_creat(
const char *path, mode_t mode);
382 char *_win_ctime(
const time_t *clock);
383 char *_win_ctime_r(
const time_t *clock,
char *buf);
384 int _win_fstat(
int handle,
struct stat *buffer);
385 int _win_ftruncate(
int fildes, off_t length);
386 void _win_gettimeofday(
struct timeval *tp,
void *tzp);
387 int _win_kill(pid_t pid,
int sig);
388 int _win_pipe(
int *phandles);
389 int _win_rmdir(
const char *path);
390 int _win_access(
const char *path,
int mode );
391 int _win_chmod(
const char *filename,
int pmode);
392 char *realpath(
const char *file_name,
char *resolved_name);
393 long _win_random(
void);
394 void _win_srandom(
unsigned int seed);
395 int _win_remove(
const char *path);
396 int _win_rename(
const char *oldname,
const char *newname);
397 int _win_stat(
const char *path,
struct stat *buffer);
398 int _win_stat64(
const char *path,
struct stat64 *buffer);
399 long _win_sysconf(
int name);
400 int _win_unlink(
const char *filename);
401 int _win_write(
int fildes,
const void *buf,
size_t nbyte);
402 int _win_read(
int fildes,
void *buf,
size_t nbyte);
403 size_t _win_fwrite(
const void *buffer,
size_t size,
size_t count, FILE *stream);
404 size_t _win_fread(
void *buffer,
size_t size,
size_t count, FILE *stream );
405 int _win_symlink(
const char *path1,
const char *path2);
406 void *_win_mmap(
void *start,
size_t len,
int access,
int flags,
int fd,
407 unsigned long long offset);
408 int _win_munmap(
void *start,
size_t length);
409 int _win_lstat(
const char *path,
struct stat *buf);
410 int _win_lstat64(
const char *path,
struct stat64 *buf);
411 int _win_readlink(
const char *path,
char *buf,
size_t bufsize);
412 int _win_accept(
int s,
struct sockaddr *addr,
int *addrlen);
413 int _win_printf(
const char *format,...);
414 int _win_fprintf(FILE *f,
const char *format,...);
415 int _win_vprintf(
const char *format, va_list ap);
416 int _win_vfprintf(FILE *stream,
const char *format, va_list arg_ptr);
417 int _win_vsprintf(
char *dest,
const char *format, va_list arg_ptr);
418 int _win_vsnprintf(
char* str,
size_t size,
const char *format, va_list arg_ptr);
419 int _win_snprintf(
char *str,
size_t size,
const char *format,...);
420 int _win_sprintf(
char *dest,
const char *format,...);
421 int _win_vsscanf(
const char* str,
const char* format, va_list arg_ptr);
422 int _win_sscanf(
const char *str,
const char *format, ...);
423 int _win_vfscanf(FILE *stream,
const char *format, va_list arg_ptr);
424 int _win_vscanf(
const char *format, va_list arg_ptr);
425 int _win_scanf(
const char *format, ...);
426 int _win_fscanf(FILE *stream,
const char *format, ...);
427 pid_t _win_waitpid(pid_t pid,
int *stat_loc,
int options);
428 int _win_bind(
int s,
const struct sockaddr *name,
int namelen);
429 int _win_connect(
int s,
const struct sockaddr *name,
int namelen);
430 int _win_getpeername(
int s,
struct sockaddr *name,
432 int _win_getsockname(
int s,
struct sockaddr *name,
434 int _win_getsockopt(
int s,
int level,
int optname,
char *optval,
436 int _win_listen(
int s,
int backlog);
437 int _win_recv(
int s,
char *buf,
int len,
int flags);
438 int _win_recvfrom(
int s,
void *buf,
int len,
int flags,
439 struct sockaddr *from,
int *fromlen);
440 int _win_select(
int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
441 const struct timeval *tv);
442 int _win_send(
int s,
const char *buf,
int len,
int flags);
443 int _win_sendto(
int s,
const char *buf,
int len,
int flags,
444 const struct sockaddr *to,
int tolen);
445 int _win_setsockopt(
int s,
int level,
int optname,
const void *optval,
447 int _win_shutdown(
int s,
int how);
448 int _win_socket(
int af,
int type,
int protocol);
449 struct hostent *_win_gethostbyaddr(
const char *addr,
int len,
int type);
450 struct hostent *_win_gethostbyname(
const char *name);
451 struct hostent *gethostbyname2(
const char *name,
int af);
452 char *_win_strerror(
int errnum);
454 char *index(
const char *s,
int c);
457 char *strndup (
const char *s,
size_t n);
460 size_t strnlen (
const char *str,
size_t maxlen);
462 char *stpcpy(
char *dest,
const char *src);
463 char *strcasestr(
const char *haystack_start,
const char *needle_start);
465 #define strcasecmp(a, b) stricmp(a, b)
466 #define strncasecmp(a, b, c) strnicmp(a, b, c)
471 #define DIR_SEPARATOR '/'
472 #define DIR_SEPARATOR_STR "/"
473 #define PATH_SEPARATOR ':'
474 #define PATH_SEPARATOR_STR ":"
478 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
480 #define CREAT(p, m) creat(p, m)
481 #define PLIBC_CTIME(c) ctime(c)
482 #define CTIME_R(c, b) ctime_r(c, b)
484 #define FOPEN(f, m) fopen(f, m)
485 #define FTRUNCATE(f, l) ftruncate(f, l)
486 #define OPENDIR(d) opendir(d)
488 #define CHDIR(d) chdir(d)
489 #define CLOSE(f) close(f)
490 #define LSEEK(f, o, w) lseek(f, o, w)
491 #define RMDIR(f) rmdir(f)
492 #define ACCESS(p, m) access(p, m)
493 #define CHMOD(f, p) chmod(f, p)
494 #define FSTAT(h, b) fstat(h, b)
495 #define PLIBC_KILL(p, s) kill(p, s)
496 #define PIPE(h) pipe(h)
497 #define REMOVE(p) remove(p)
498 #define RENAME(o, n) rename(o, n)
499 #define STAT(p, b) stat(p, b)
500 #define STAT64(p, b) stat64(p, b)
501 #define SYSCONF(n) sysconf(n)
502 #define UNLINK(f) unlink(f)
503 #define WRITE(f, b, n) write(f, b, n)
504 #define READ(f, b, n) read(f, b, n)
505 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
506 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
507 #define SYMLINK(a, b) symlink(a, b)
508 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
509 #define MUNMAP(s, l) munmap(s, l)
510 #define STRERROR(i) strerror(i)
511 #define RANDOM() random()
512 #define SRANDOM(s) srandom(s)
513 #define READLINK(p, b, s) readlink(p, b, s)
514 #define LSTAT(p, b) lstat(p, b)
515 #define LSTAT64(p, b) lstat64(p, b)
516 #define PRINTF printf
517 #define FPRINTF fprintf
518 #define VPRINTF(f, a) vprintf(f, a)
519 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
520 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
521 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
522 #define _REAL_SNPRINTF snprintf
523 #define SPRINTF sprintf
524 #define VSSCANF(s, f, a) vsscanf(s, f, a)
525 #define SSCANF sscanf
526 #define VFSCANF(s, f, a) vfscanf(s, f, a)
527 #define VSCANF(f, a) vscanf(f, a)
529 #define FSCANF fscanf
530 #define WAITPID(p, s, o) waitpid(p, s, o)
531 #define ACCEPT(s, a, l) accept(s, a, l)
532 #define BIND(s, n, l) bind(s, n, l)
533 #define CONNECT(s, n, l) connect(s, n, l)
534 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
535 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
536 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
537 #define LISTEN(s, b) listen(s, b)
538 #define RECV(s, b, l, f) recv(s, b, l, f)
539 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
540 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
541 #define SEND(s, b, l, f) send(s, b, l, f)
542 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
543 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
544 #define SHUTDOWN(s, h) shutdown(s, h)
545 #define SOCKET(a, t, p) socket(a, t, p)
546 #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
547 #define GETHOSTBYNAME(n) gethostbyname(n)
548 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
549 #define INSQUE(e, p) insque(e, p)
550 #define REMQUE(e) remque(e)
551 #define HSEARCH(i, a) hsearch(i, a)
552 #define HCREATE(n) hcreate(n)
553 #define HDESTROY() hdestroy()
554 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
555 #define HCREATE_R(n, h) hcreate_r(n, h)
556 #define HDESTROY_R(h) hdestroy_r(h)
557 #define TSEARCH(k, r, c) tsearch(k, r, c)
558 #define TFIND(k, r, c) tfind(k, r, c)
559 #define TDELETE(k, r, c) tdelete(k, r, c)
560 #define TWALK(r, a) twalk(r, a)
561 #define TDESTROY(r, f) tdestroy(r, f)
562 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
563 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
565 #define DIR_SEPARATOR '\\'
566 #define DIR_SEPARATOR_STR "\\"
567 #define PATH_SEPARATOR ';'
568 #define PATH_SEPARATOR_STR ";"
569 #define NEWLINE "\r\n"
572 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
574 #define CREAT(p, m) _win_creat(p, m)
575 #define PLIBC_CTIME(c) _win_ctime(c)
576 #define CTIME_R(c, b) _win_ctime_r(c, b)
577 #define FOPEN(f, m) _win_fopen(f, m)
578 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
579 #define OPENDIR(d) _win_opendir(d)
580 #define OPEN _win_open
581 #define CHDIR(d) _win_chdir(d)
582 #define CLOSE(f) _win_close(f)
583 #define PLIBC_KILL(p, s) _win_kill(p, s)
584 #define LSEEK(f, o, w) _win_lseek(f, o, w)
585 #define FSTAT(h, b) _win_fstat(h, b)
586 #define RMDIR(f) _win_rmdir(f)
587 #define ACCESS(p, m) _win_access(p, m)
588 #define CHMOD(f, p) _win_chmod(f, p)
589 #define PIPE(h) _win_pipe(h)
590 #define RANDOM() _win_random()
591 #define SRANDOM(s) _win_srandom(s)
592 #define REMOVE(p) _win_remove(p)
593 #define RENAME(o, n) _win_rename(o, n)
594 #define STAT(p, b) _win_stat(p, b)
595 #define STAT64(p, b) _win_stat64(p, b)
596 #define SYSCONF(n) _win_sysconf(n)
597 #define UNLINK(f) _win_unlink(f)
598 #define WRITE(f, b, n) _win_write(f, b, n)
599 #define READ(f, b, n) _win_read(f, b, n)
600 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
601 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
602 #define SYMLINK(a, b) _win_symlink(a, b)
603 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
604 #define MUNMAP(s, l) _win_munmap(s, l)
605 #define STRERROR(i) _win_strerror(i)
606 #define READLINK(p, b, s) _win_readlink(p, b, s)
607 #define LSTAT(p, b) _win_lstat(p, b)
608 #define LSTAT64(p, b) _win_lstat64(p, b)
609 #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
610 #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
611 #define VPRINTF(f, a) _win_vprintf(f, a)
612 #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
613 #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
614 #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
615 #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
616 #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
617 #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
618 #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
619 #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
620 #define VSCANF(f, a) _win_vscanf(f, a)
621 #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
622 #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
623 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
624 #define ACCEPT(s, a, l) _win_accept(s, a, l)
625 #define BIND(s, n, l) _win_bind(s, n, l)
626 #define CONNECT(s, n, l) _win_connect(s, n, l)
627 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
628 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
629 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
630 #define LISTEN(s, b) _win_listen(s, b)
631 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
632 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
633 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
634 #define SEND(s, b, l, f) _win_send(s, b, l, f)
635 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
636 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
637 #define SHUTDOWN(s, h) _win_shutdown(s, h)
638 #define SOCKET(a, t, p) _win_socket(a, t, p)
639 #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
640 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
641 #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
642 #define INSQUE(e, p) _win_insque(e, p)
643 #define REMQUE(e) _win_remque(e)
644 #define HSEARCH(i, a) _win_hsearch(i, a)
645 #define HCREATE(n) _win_hcreate(n)
646 #define HDESTROY() _win_hdestroy()
647 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
648 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
649 #define HDESTROY_R(h) _win_hdestroy_r(h)
650 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
651 #define TFIND(k, r, c) _win_tfind(k, r, c)
652 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
653 #define TWALK(r, a) _win_twalk(r, a)
654 #define TDESTROY(r, f) _win_tdestroy(r, f)
655 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
656 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
758 void *
_win_tsearch (__const
void *__key,
void **__rootp,
763 void *
_win_tfind (__const
void *__key,
void *__const *__rootp,
768 void **__restrict __rootp,
788 void *
_win_lfind (__const
void *__key, __const
void *__base,