GNUnet  0.10.x
plibc.h
Go to the documentation of this file.
1 /*
2  This file is part of PlibC.
3  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
4 
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.
9 
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.
14 
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
18 */
19 
30 #ifndef _PLIBC_H_
31 #define _PLIBC_H_
32 
33 #ifndef SIGALRM
34  #define SIGALRM 14
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <stddef.h>
42 
43 #ifdef Q_OS_WIN32
44  #define WINDOWS 1
45 #endif
46 
47 #define HAVE_PLIBC_FD 0
48 
49 #ifdef WINDOWS
50 
51 #if ENABLE_NLS
52  #include "langinfo.h"
53 #endif
54 
55 #include <ws2tcpip.h>
56 #include <windows.h>
57 #include <sys/types.h>
58 #include <time.h>
59 #include <stdio.h>
60 #include <sys/types.h>
61 #include <sys/stat.h>
62 #include <dirent.h>
63 #include <errno.h>
64 #include <stdarg.h>
65 
66 #define __BYTE_ORDER BYTE_ORDER
67 #define __BIG_ENDIAN BIG_ENDIAN
68 
69 /* Conflicts with our definitions */
70 #define __G_WIN32_H__
71 
72 /* Convert LARGE_INTEGER to double */
73 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
74  (double)((x).LowPart))
75 #ifndef HAVE_DECL__STATI64
76 struct _stati64
77 {
78  _dev_t st_dev;
79  _ino_t st_ino;
80  _mode_t st_mode;
81  short st_nlink;
82  short st_uid;
83  short st_gid;
84  _dev_t st_rdev;
85  __int64 st_size;
86  time_t st_atime;
87  time_t st_mtime;
88  time_t st_ctime;
89 };
90 #endif
91 typedef unsigned int sa_family_t;
92 
93 struct sockaddr_un {
94  short sun_family; /*AF_UNIX*/
95  char sun_path[108]; /*path name */
96 };
97 
98 #ifndef pid_t
99  #define pid_t DWORD
100 #endif
101 
102 #ifndef error_t
103  #define error_t int
104 #endif
105 
106 #ifndef WEXITSTATUS
107  #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
108 #endif
109 
110 #ifndef MSG_DONTWAIT
111  #define MSG_DONTWAIT 0
112 #endif
113 
114 enum
115 {
116  _SC_PAGESIZE = 30,
117  _SC_PAGE_SIZE = 30
118 };
119 
120 #if !defined(EACCESS)
121 # define EACCESS EACCES
122 #endif
123 
124 /* Thanks to the Cygwin project */
125 #if !defined(ENOCSI)
126 # define ENOCSI 43 /* No CSI structure available */
127 #endif
128 #if !defined(EL2HLT)
129 # define EL2HLT 44 /* Level 2 halted */
130 #endif
131 #if !defined(EDEADLK)
132 # define EDEADLK 45 /* Deadlock condition */
133 #endif
134 #if !defined(ENOLCK)
135 # define ENOLCK 46 /* No record locks available */
136 #endif
137 #if !defined(EBADE)
138 # define EBADE 50 /* Invalid exchange */
139 #endif
140 #if !defined(EBADR)
141 # define EBADR 51 /* Invalid request descriptor */
142 #endif
143 #if !defined(EXFULL)
144 # define EXFULL 52 /* Exchange full */
145 #endif
146 #if !defined(ENOANO)
147 # define ENOANO 53 /* No anode */
148 #endif
149 #if !defined(EBADRQC)
150 # define EBADRQC 54 /* Invalid request code */
151 #endif
152 #if !defined(EBADSLT)
153 # define EBADSLT 55 /* Invalid slot */
154 #endif
155 #if !defined(EDEADLOCK)
156 # define EDEADLOCK EDEADLK /* File locking deadlock error */
157 #endif
158 #if !defined(EBFONT)
159 # define EBFONT 57 /* Bad font file fmt */
160 #endif
161 #if !defined(ENOSTR)
162 # define ENOSTR 60 /* Device not a stream */
163 #endif
164 #if !defined(ENODATA)
165 # define ENODATA 61 /* No data (for no delay io) */
166 #endif
167 #if !defined(ETIME)
168 # define ETIME 62 /* Timer expired */
169 #endif
170 #if !defined(ENOSR)
171 # define ENOSR 63 /* Out of streams resources */
172 #endif
173 #if !defined(ENONET)
174 # define ENONET 64 /* Machine is not on the network */
175 #endif
176 #if !defined(ENOPKG)
177 # define ENOPKG 65 /* Package not installed */
178 #endif
179 #if !defined(EREMOTE)
180 # define EREMOTE 66 /* The object is remote */
181 #endif
182 #if !defined(ENOLINK)
183 # define ENOLINK 67 /* The link has been severed */
184 #endif
185 #if !defined(EADV)
186 # define EADV 68 /* Advertise error */
187 #endif
188 #if !defined(ESRMNT)
189 # define ESRMNT 69 /* Srmount error */
190 #endif
191 #if !defined(ECOMM)
192 # define ECOMM 70 /* Communication error on send */
193 #endif
194 #if !defined(EMULTIHOP)
195 # define EMULTIHOP 74 /* Multihop attempted */
196 #endif
197 #if !defined(ELBIN)
198 # define ELBIN 75 /* Inode is remote (not really error) */
199 #endif
200 #if !defined(EDOTDOT)
201 # define EDOTDOT 76 /* Cross mount point (not really error) */
202 #endif
203 #if !defined(EBADMSG)
204 # define EBADMSG 77 /* Trying to read unreadable message */
205 #endif
206 #if !defined(ENOTUNIQ)
207 # define ENOTUNIQ 80 /* Given log. name not unique */
208 #endif
209 #if !defined(EBADFD)
210 # define EBADFD 81 /* f.d. invalid for this operation */
211 #endif
212 #if !defined(EREMCHG)
213 # define EREMCHG 82 /* Remote address changed */
214 #endif
215 #if !defined(ELIBACC)
216 # define ELIBACC 83 /* Can't access a needed shared lib */
217 #endif
218 #if !defined(ELIBBAD)
219 # define ELIBBAD 84 /* Accessing a corrupted shared lib */
220 #endif
221 #if !defined(ELIBSCN)
222 # define ELIBSCN 85 /* .lib section in a.out corrupted */
223 #endif
224 #if !defined(ELIBMAX)
225 # define ELIBMAX 86 /* Attempting to link in too many libs */
226 #endif
227 #if !defined(ELIBEXEC)
228 # define ELIBEXEC 87 /* Attempting to exec a shared library */
229 #endif
230 #if !defined(ENOSYS)
231 # define ENOSYS 88 /* Function not implemented */
232 #endif
233 #if !defined(ENMFILE)
234 # define ENMFILE 89 /* No more files */
235 #endif
236 #if !defined(ENOTEMPTY)
237 # define ENOTEMPTY 90 /* Directory not empty */
238 #endif
239 #if !defined(ENAMETOOLONG)
240 # define ENAMETOOLONG 91 /* File or path name too long */
241 #endif
242 #if !defined(EPFNOSUPPORT)
243 # define EPFNOSUPPORT 96 /* Protocol family not supported */
244 #endif
245 #if !defined(ENOSHARE)
246 # define ENOSHARE 97 /* No such host or network path */
247 #endif
248 #if !defined(ENOMEDIUM)
249 # define ENOMEDIUM 98 /* No medium (in tape drive) */
250 #endif
251 #if !defined(ESHUTDOWN)
252 # define ESHUTDOWN 99 /* Can't send after socket shutdown */
253 #endif
254 #if !defined(EADDRINUSE)
255 # define EADDRINUSE 100 /* Address already in use */
256 #endif
257 #if !defined(EADDRNOTAVAIL)
258 # define EADDRNOTAVAIL 101 /* Address not available */
259 #endif
260 #if !defined(EAFNOSUPPORT)
261 # define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
262 #endif
263 #if !defined(EALREADY)
264 # define EALREADY 103 /* Socket already connected */
265 #endif
266 #if !defined(ECANCELED)
267 # define ECANCELED 105 /* Connection cancelled */
268 #endif
269 #if !defined(ECONNABORTED)
270 # define ECONNABORTED 106 /* Connection aborted */
271 #endif
272 #if !defined(ECONNREFUSED)
273 # define ECONNREFUSED 107 /* Connection refused */
274 #endif
275 #if !defined(ECONNRESET)
276 # define ECONNRESET 108 /* Connection reset by peer */
277 #endif
278 #if !defined(EDESTADDRREQ)
279 # define EDESTADDRREQ 109 /* Destination address required */
280 #endif
281 #if !defined(EHOSTUNREACH)
282 # define EHOSTUNREACH 110 /* Host is unreachable */
283 #endif
284 #if !defined(ECONNABORTED)
285 # define ECONNABORTED 111 /* Connection aborted */
286 #endif
287 #if !defined(EINPROGRESS)
288 # define EINPROGRESS 112 /* Connection already in progress */
289 #endif
290 #if !defined(EISCONN)
291 # define EISCONN 113 /* Socket is already connected */
292 #endif
293 #if !defined(ELOOP)
294 # define ELOOP 114 /* Too many symbolic links */
295 #endif
296 #if !defined(EMSGSIZE)
297 # define EMSGSIZE 115 /* Message too long */
298 #endif
299 #if !defined(ENETDOWN)
300 # define ENETDOWN 116 /* Network interface is not configured */
301 #endif
302 #if !defined(ENETRESET)
303 # define ENETRESET 117 /* Connection aborted by network */
304 #endif
305 #if !defined(ENETUNREACH)
306 # define ENETUNREACH 118 /* Network is unreachable */
307 #endif
308 #if !defined(ENOBUFS)
309 # define ENOBUFS 119 /* No buffer space available */
310 #endif
311 #if !defined(EHOSTDOWN)
312 # define EHOSTDOWN 120 /* Host is down */
313 #endif
314 #if !defined(EPROCLIM)
315 # define EPROCLIM 121 /* Too many processes */
316 #endif
317 #if !defined(EDQUOT)
318 # define EDQUOT 122 /* Disk quota exceeded */
319 #endif
320 #if !defined(ENOPROTOOPT)
321 # define ENOPROTOOPT 123 /* Protocol not available */
322 #endif
323 #if !defined(ESOCKTNOSUPPORT)
324 # define ESOCKTNOSUPPORT 124 /* Socket type not supported */
325 #endif
326 #if !defined(ESTALE)
327 # define ESTALE 125 /* Unknown error */
328 #endif
329 #if !defined(ENOTCONN)
330 # define ENOTCONN 126 /* Socket is not connected */
331 #endif
332 #if !defined(ETOOMANYREFS)
333 # define ETOOMANYREFS 127 /* Too many references: cannot splice */
334 #endif
335 #if !defined(ENOTSOCK)
336 # define ENOTSOCK 128 /* Socket operation on non-socket */
337 #endif
338 #if !defined(ENOTSUP)
339 # define ENOTSUP 129 /* Not supported */
340 #endif
341 #if !defined(EOPNOTSUPP)
342 # define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
343 #endif
344 #if !defined(EUSERS)
345 # define EUSERS 131 /* Too many users */
346 #endif
347 #if !defined(EOVERFLOW)
348 # define EOVERFLOW 132 /* Value too large for defined data type */
349 #endif
350 #if !defined(EOWNERDEAD)
351 # define EOWNERDEAD 133 /* Unknown error */
352 #endif
353 #if !defined(EPROTO)
354 # define EPROTO 134 /* Protocol error */
355 #endif
356 #if !defined(EPROTONOSUPPORT)
357 # define EPROTONOSUPPORT 135 /* Unknown protocol */
358 #endif
359 #if !defined(EPROTOTYPE)
360 # define EPROTOTYPE 136 /* Protocol wrong type for socket */
361 #endif
362 #if !defined(ECASECLASH)
363 # define ECASECLASH 137 /* Filename exists with different case */
364 #endif
365 #if !defined(ETIMEDOUT)
366 /* Make sure it's the same as WSATIMEDOUT */
367 # define ETIMEDOUT 138 /* Connection timed out */
368 #endif
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 */
372 #endif
373 
374 #undef HOST_NOT_FOUND
375 #define HOST_NOT_FOUND 1
376 #undef TRY_AGAIN
377 #define TRY_AGAIN 2
378 #undef NO_RECOVERY
379 #define NO_RECOVERY 3
380 #undef NO_ADDRESS
381 #define NO_ADDRESS 4
382 
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)
390 
391 #define MS_ASYNC 1 /* sync memory asynchronously */
392 #define MS_INVALIDATE 2 /* invalidate the caches */
393 #define MS_SYNC 4 /* synchronous memory sync */
394 
395 struct statfs
396 {
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 */
407 };
408 #define sleep(secs) (Sleep(secs * 1000))
409 
410 /*********************** statfs *****************************/
411 /* fake block size */
412 #define FAKED_BLOCK_SIZE 512
413 
414 /* linux-compatible values for fs type */
415 #define MSDOS_SUPER_MAGIC 0x4d44
416 #define NTFS_SUPER_MAGIC 0x5346544E
417 
418 /*********************** End of statfs ***********************/
419 
420 #define SHUT_RDWR SD_BOTH
421 
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
426  blocking */
427 #define LOCK_UN 8 /* remove lock */
428 
429 /* Not supported under MinGW */
430 #ifndef S_IRGRP
431 #define S_IRGRP 0
432 #endif
433 #ifndef S_IWGRP
434 #define S_IWGRP 0
435 #endif
436 #ifndef S_IROTH
437 #define S_IROTH 0
438 #endif
439 #ifndef S_IXGRP
440 #define S_IXGRP 0
441 #endif
442 #ifndef S_IWOTH
443 #define S_IWOTH 0
444 #endif
445 #ifndef S_IXOTH
446 #define S_IXOTH 0
447 #endif
448 #ifndef S_ISUID
449 #define S_ISUID 0
450 #endif
451 #ifndef S_ISGID
452 #define S_ISGID 0
453 #endif
454 #ifndef S_ISVTX
455 #define S_ISVTX 0
456 #endif
457 #ifndef S_IRWXG
458 #define S_IRWXG 0
459 #endif
460 #ifndef S_IRWXO
461 #define S_IRWXO 0
462 #endif
463 
464 #define SHUT_WR SD_SEND
465 #define SHUT_RD SD_RECEIVE
466 #define SHUT_RDWR SD_BOTH
467 
468 #define SIGKILL 9
469 #define SIGTERM 15
470 
471 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
472 
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);
481 
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);
486 
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);
493 
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);
496 
497 unsigned plibc_get_handle_count();
498 
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);
503 
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);
508 #if USE_IPV6
509 int inet_pton6(const char *src, u_char *dst);
510 #endif
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);
516 #ifndef gmtime_r
517 struct tm *gmtime_r(const time_t *clock, struct tm *result);
518 #endif
519 
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();
524 
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, ...);
536 #ifdef ENABLE_NLS
537 char *_win_bindtextdomain(const char *domainname, const char *dirname);
538 #endif
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);
575 
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,
580  int *namelen);
581 int _win_getsockname(int s, struct sockaddr *name,
582  int *namelen);
583 int _win_getsockopt(int s, int level, int optname, char *optval,
584  int *optlen);
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,
595  int optlen);
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);
603 int IsWinNT();
604 char *index(const char *s, int c);
605 char *_win_strtok_r (char *ptr, const char *sep, char **end);
606 
607 #if !HAVE_STRNDUP
608 char *strndup (const char *s, size_t n);
609 #endif
610 #if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
611 size_t strnlen (const char *str, size_t maxlen);
612 #endif
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)
618 #endif
619 #ifndef wcscasecmp
620 #define wcscasecmp(a, b) wcsicmp(a, b)
621 #endif
622 #ifndef wcsncasecmp
623 #define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
624 #endif
625 #ifndef strtok_r /* winpthreads defines it in pthread.h */
626 #define strtok_r _win_strtok_r
627 #endif
628 #endif /* WINDOWS */
629 
630 #ifndef WINDOWS
631  #define DIR_SEPARATOR '/'
632  #define DIR_SEPARATOR_STR "/"
633  #define PATH_SEPARATOR ':'
634  #define PATH_SEPARATOR_STR ":"
635  #define NEWLINE "\n"
636 
637 #ifdef ENABLE_NLS
638  #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
639 #endif
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)
643  #undef FOPEN
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)
651  #define OPEN open
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)
694  #define SCANF scanf
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
732 #else
733  #define DIR_SEPARATOR '\\'
734  #define DIR_SEPARATOR_STR "\\"
735  #define PATH_SEPARATOR ';'
736  #define PATH_SEPARATOR_STR ";"
737  #define NEWLINE "\r\n"
738 
739 #ifdef ENABLE_NLS
740  #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
741 #endif
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)
795  #define SCANF scanf
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
833 #endif
834 
835 /* search.h */
836 
837 /* Prototype structure for a linked-list data structure.
838  This is the type used by the `insque' and `remque' functions. */
839 
841  {
842  struct qelem *q_forw;
843  struct qelem *q_back;
844  char q_data[1];
845  };
846 
847 
848 /* Insert ELEM into a doubly-linked list, after PREV. */
849 void _win_insque (void *__elem, void *__prev);
850 
851 /* Unlink ELEM from the doubly-linked list that it is in. */
852 void _win_remque (void *__elem);
853 
854 
855 /* For use with hsearch(3). */
856 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
857 
859 
860 /* Action which shall be performed in the call the hsearch. */
861 typedef enum
862  {
865  }
867 
868 typedef struct PLIBC_SEARCH_entry
869  {
870  char *key;
871  void *data;
872  }
874 
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
879 {
880  unsigned int used;
882 }
884 
885 
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. */
889 
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
893  ITEM.data. */
894 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
895 
896 /* Create a new hashing table which will at most contain NEL elements. */
897 int _win_hcreate (size_t __nel);
898 
899 /* Destroy current internal hashing table. */
900 void _win_hdestroy (void);
901 
902 /* Data type for reentrant functions. */
904  {
906  unsigned int size;
907  unsigned int filled;
908  };
909 
910 /* Reentrant versions which can handle multiple hashing tables at the
911  same time. */
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);
916 
917 
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. */
922 /* For tsearch */
923 typedef enum
924 {
929 }
931 
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);
936 
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);
941 
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);
946 
947 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
948  int __level);
949 
950 /* Walk through the whole tree and call the ACTION callback for every node
951  or leaf. */
952 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
953 
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);
957 
958 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
959 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
960 
961 
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);
966 
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);
971 
972 
973 #ifdef __cplusplus
974 }
975 #endif
976 
977 
978 #endif //_PLIBC_H_
979 
980 /* end of plibc.h */
struct _PLIBC_SEARCH_ENTRY _PLIBC_SEARCH_ENTRY
void _win_hdestroy_r(struct PLIBC_SEARCH_hsearch_data *__htab)
PLIBC_SEARCH_ENTRY entry
Definition: plibc.h:881
int _win_hcreate_r(size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab)
unsigned int size
Definition: plibc.h:906
int(* PLIBC_SEARCH__compar_fn_t)(__const void *, __const void *)
Definition: plibc.h:856
PLIBC_SEARCH_ENTRY * _win_hsearch(PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action)
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
void _win_hdestroy(void)
Definition: plibc.h:868
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
void * data
Definition: plibc.h:871
void * _win_lsearch(__const void *__key, void *__base, size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar)
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
void(* PLIBC_SEARCH__action_fn_t)(__const void *__nodep, PLIBC_SEARCH_VISIT __value, int __level)
Definition: plibc.h:947
static char * file_name
Dump file name.
struct _PLIBC_SEARCH_ENTRY * table
Definition: plibc.h:905
void _win_remque(void *__elem)
long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, char *pszBuffer, long *pdLength)
void _win_twalk(__const void *__root, PLIBC_SEARCH__action_fn_t __action)
Definition: plibc.h:878
PLIBC_SEARCH_VISIT
Definition: plibc.h:923
struct PLIBC_SEARCH_entry PLIBC_SEARCH_ENTRY
static char buf[2048]
static char * filename
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows)
void * _win_lfind(__const void *__key, __const void *__base, size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar)
static unsigned int size
Size of the "table".
Definition: peer.c:67
void _win_insque(void *__elem, void *__prev)
const char * name
char * key
Definition: plibc.h:870
PLIBC_SEARCH_ACTION
Definition: plibc.h:861
int _win_hcreate(size_t __nel)
unsigned int filled
Definition: plibc.h:907
void * _win_tdelete(__const void *__restrict __key, void **__restrict __rootp, PLIBC_SEARCH__compar_fn_t __compar)
struct qelem * q_forw
Definition: plibc.h:842
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
void * _win_tfind(__const void *__key, void *__const *__rootp, PLIBC_SEARCH__compar_fn_t __compar)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t
Definition: plibc.h:858
int _win_hsearch_r(PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval, struct PLIBC_SEARCH_hsearch_data *__htab)
unsigned int used
Definition: plibc.h:880
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct qelem * q_back
Definition: plibc.h:843
void(* PLIBC_SEARCH__free_fn_t)(void *__nodep)
Definition: plibc.h:956
static size_t strnlen(const char *s, size_t n)
void * _win_tsearch(__const void *__key, void **__rootp, PLIBC_SEARCH__compar_fn_t __compar)
void _win_tdestroy(void *__root, PLIBC_SEARCH__free_fn_t __freefct)
static enum @11 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...