aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-30 14:21:30 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-30 14:21:30 +0100
commitba1b54bd1346278b9f8674aa216ec2c7c16ad32c (patch)
tree1de84c13160154230f15e4606aa6697a5e26b37e
parent32e5c9789df128686ebda877472e5fac81fc7bdc (diff)
downloadlibextractor-ba1b54bd1346278b9f8674aa216ec2c7c16ad32c.tar.gz
libextractor-ba1b54bd1346278b9f8674aa216ec2c7c16ad32c.zip
mask SIGPIPE to avoid problems with crashing in test (should fix #6709)
-rw-r--r--src/include/plibc.h1092
-rw-r--r--src/plugins/test_lib.c33
2 files changed, 32 insertions, 1093 deletions
diff --git a/src/include/plibc.h b/src/include/plibc.h
deleted file mode 100644
index 9199072..0000000
--- a/src/include/plibc.h
+++ /dev/null
@@ -1,1092 +0,0 @@
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
20/**
21 * @file include/plibc.h
22 * @brief PlibC header
23 * @attention This file is usually not installed under Unix,
24 * so ship it with your application
25 * @version $Revision: 158 $
26 */
27
28#ifndef _PLIBC_H_
29#define _PLIBC_H_
30
31#ifndef SIGALRM
32 #define SIGALRM 14
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include <stddef.h>
40
41#ifdef Q_OS_WIN32
42 #define WINDOWS 1
43#endif
44
45#define HAVE_PLIBC_FD 0
46
47#ifdef WINDOWS
48
49#if ENABLE_NLS
50 #include "langinfo.h"
51#endif
52
53#include <ws2tcpip.h>
54#include <windows.h>
55#include <sys/types.h>
56#include <time.h>
57#include <stdio.h>
58#include <sys/types.h>
59#include <sys/stat.h>
60#include <dirent.h>
61#include <errno.h>
62#include <stdarg.h>
63
64#define __BYTE_ORDER BYTE_ORDER
65#define __BIG_ENDIAN BIG_ENDIAN
66
67/* Conflicts with our definitions */
68#define __G_WIN32_H__
69
70/* Convert LARGE_INTEGER to double */
71#define Li2Double(x) ((double) ((x).HighPart) * 4.294967296E9 \
72 + (double) ((x).LowPart))
73#ifndef HAVE_DECL__STATI64
74struct _stati64
75{
76 _dev_t st_dev;
77 _ino_t st_ino;
78 _mode_t st_mode;
79 short st_nlink;
80 short st_uid;
81 short st_gid;
82 _dev_t st_rdev;
83 __int64 st_size;
84 time_t st_atime;
85 time_t st_mtime;
86 time_t st_ctime;
87};
88#endif
89typedef unsigned int sa_family_t;
90
91struct sockaddr_un
92{
93 short sun_family; /*AF_UNIX*/
94 char sun_path[108]; /*path name */
95};
96
97#ifndef pid_t
98 #define pid_t DWORD
99#endif
100
101#ifndef error_t
102 #define error_t int
103#endif
104
105#ifndef WEXITSTATUS
106 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
107#endif
108
109#ifndef MSG_DONTWAIT
110 #define MSG_DONTWAIT 0
111#endif
112
113enum
114{
115 _SC_PAGESIZE = 30,
116 _SC_PAGE_SIZE = 30
117};
118
119#if ! defined(EACCESS)
120# define EACCESS EACCES
121#endif
122
123/* Thanks to the Cygwin project */
124#if ! defined(ENOCSI)
125# define ENOCSI 43 /* No CSI structure available */
126#endif
127#if ! defined(EL2HLT)
128# define EL2HLT 44 /* Level 2 halted */
129#endif
130#if ! defined(EDEADLK)
131# define EDEADLK 45 /* Deadlock condition */
132#endif
133#if ! defined(ENOLCK)
134# define ENOLCK 46 /* No record locks available */
135#endif
136#if ! defined(EBADE)
137# define EBADE 50 /* Invalid exchange */
138#endif
139#if ! defined(EBADR)
140# define EBADR 51 /* Invalid request descriptor */
141#endif
142#if ! defined(EXFULL)
143# define EXFULL 52 /* Exchange full */
144#endif
145#if ! defined(ENOANO)
146# define ENOANO 53 /* No anode */
147#endif
148#if ! defined(EBADRQC)
149# define EBADRQC 54 /* Invalid request code */
150#endif
151#if ! defined(EBADSLT)
152# define EBADSLT 55 /* Invalid slot */
153#endif
154#if ! defined(EDEADLOCK)
155# define EDEADLOCK EDEADLK /* File locking deadlock error */
156#endif
157#if ! defined(EBFONT)
158# define EBFONT 57 /* Bad font file fmt */
159#endif
160#if ! defined(ENOSTR)
161# define ENOSTR 60 /* Device not a stream */
162#endif
163#if ! defined(ENODATA)
164# define ENODATA 61 /* No data (for no delay io) */
165#endif
166#if ! defined(ETIME)
167# define ETIME 62 /* Timer expired */
168#endif
169#if ! defined(ENOSR)
170# define ENOSR 63 /* Out of streams resources */
171#endif
172#if ! defined(ENONET)
173# define ENONET 64 /* Machine is not on the network */
174#endif
175#if ! defined(ENOPKG)
176# define ENOPKG 65 /* Package not installed */
177#endif
178#if ! defined(EREMOTE)
179# define EREMOTE 66 /* The object is remote */
180#endif
181#if ! defined(ENOLINK)
182# define ENOLINK 67 /* The link has been severed */
183#endif
184#if ! defined(EADV)
185# define EADV 68 /* Advertise error */
186#endif
187#if ! defined(ESRMNT)
188# define ESRMNT 69 /* Srmount error */
189#endif
190#if ! defined(ECOMM)
191# define ECOMM 70 /* Communication error on send */
192#endif
193#if ! defined(EMULTIHOP)
194# define EMULTIHOP 74 /* Multihop attempted */
195#endif
196#if ! defined(ELBIN)
197# define ELBIN 75 /* Inode is remote (not really error) */
198#endif
199#if ! defined(EDOTDOT)
200# define EDOTDOT 76 /* Cross mount point (not really error) */
201#endif
202#if ! defined(EBADMSG)
203# define EBADMSG 77 /* Trying to read unreadable message */
204#endif
205#if ! defined(ENOTUNIQ)
206# define ENOTUNIQ 80 /* Given log. name not unique */
207#endif
208#if ! defined(EBADFD)
209# define EBADFD 81 /* f.d. invalid for this operation */
210#endif
211#if ! defined(EREMCHG)
212# define EREMCHG 82 /* Remote address changed */
213#endif
214#if ! defined(ELIBACC)
215# define ELIBACC 83 /* Can't access a needed shared lib */
216#endif
217#if ! defined(ELIBBAD)
218# define ELIBBAD 84 /* Accessing a corrupted shared lib */
219#endif
220#if ! defined(ELIBSCN)
221# define ELIBSCN 85 /* .lib section in a.out corrupted */
222#endif
223#if ! defined(ELIBMAX)
224# define ELIBMAX 86 /* Attempting to link in too many libs */
225#endif
226#if ! defined(ELIBEXEC)
227# define ELIBEXEC 87 /* Attempting to exec a shared library */
228#endif
229#if ! defined(ENOSYS)
230# define ENOSYS 88 /* Function not implemented */
231#endif
232#if ! defined(ENMFILE)
233# define ENMFILE 89 /* No more files */
234#endif
235#if ! defined(ENOTEMPTY)
236# define ENOTEMPTY 90 /* Directory not empty */
237#endif
238#if ! defined(ENAMETOOLONG)
239# define ENAMETOOLONG 91 /* File or path name too long */
240#endif
241#if ! defined(EPFNOSUPPORT)
242# define EPFNOSUPPORT 96 /* Protocol family not supported */
243#endif
244#if ! defined(ENOSHARE)
245# define ENOSHARE 97 /* No such host or network path */
246#endif
247#if ! defined(ENOMEDIUM)
248# define ENOMEDIUM 98 /* No medium (in tape drive) */
249#endif
250#if ! defined(ESHUTDOWN)
251# define ESHUTDOWN 99 /* Can't send after socket shutdown */
252#endif
253#if ! defined(EADDRINUSE)
254# define EADDRINUSE 100 /* Address already in use */
255#endif
256#if ! defined(EADDRNOTAVAIL)
257# define EADDRNOTAVAIL 101 /* Address not available */
258#endif
259#if ! defined(EAFNOSUPPORT)
260# define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
261#endif
262#if ! defined(EALREADY)
263# define EALREADY 103 /* Socket already connected */
264#endif
265#if ! defined(ECANCELED)
266# define ECANCELED 105 /* Connection cancelled */
267#endif
268#if ! defined(ECONNABORTED)
269# define ECONNABORTED 106 /* Connection aborted */
270#endif
271#if ! defined(ECONNREFUSED)
272# define ECONNREFUSED 107 /* Connection refused */
273#endif
274#if ! defined(ECONNRESET)
275# define ECONNRESET 108 /* Connection reset by peer */
276#endif
277#if ! defined(EDESTADDRREQ)
278# define EDESTADDRREQ 109 /* Destination address required */
279#endif
280#if ! defined(EHOSTUNREACH)
281# define EHOSTUNREACH 110 /* Host is unreachable */
282#endif
283#if ! defined(ECONNABORTED)
284# define ECONNABORTED 111 /* Connection aborted */
285#endif
286#if ! defined(EINPROGRESS)
287# define EINPROGRESS 112 /* Connection already in progress */
288#endif
289#if ! defined(EISCONN)
290# define EISCONN 113 /* Socket is already connected */
291#endif
292#if ! defined(ELOOP)
293# define ELOOP 114 /* Too many symbolic links */
294#endif
295#if ! defined(EMSGSIZE)
296# define EMSGSIZE 115 /* Message too long */
297#endif
298#if ! defined(ENETDOWN)
299# define ENETDOWN 116 /* Network interface is not configured */
300#endif
301#if ! defined(ENETRESET)
302# define ENETRESET 117 /* Connection aborted by network */
303#endif
304#if ! defined(ENETUNREACH)
305# define ENETUNREACH 118 /* Network is unreachable */
306#endif
307#if ! defined(ENOBUFS)
308# define ENOBUFS 119 /* No buffer space available */
309#endif
310#if ! defined(EHOSTDOWN)
311# define EHOSTDOWN 120 /* Host is down */
312#endif
313#if ! defined(EPROCLIM)
314# define EPROCLIM 121 /* Too many processes */
315#endif
316#if ! defined(EDQUOT)
317# define EDQUOT 122 /* Disk quota exceeded */
318#endif
319#if ! defined(ENOPROTOOPT)
320# define ENOPROTOOPT 123 /* Protocol not available */
321#endif
322#if ! defined(ESOCKTNOSUPPORT)
323# define ESOCKTNOSUPPORT 124 /* Socket type not supported */
324#endif
325#if ! defined(ESTALE)
326# define ESTALE 125 /* Unknown error */
327#endif
328#if ! defined(ENOTCONN)
329# define ENOTCONN 126 /* Socket is not connected */
330#endif
331#if ! defined(ETOOMANYREFS)
332# define ETOOMANYREFS 127 /* Too many references: cannot splice */
333#endif
334#if ! defined(ENOTSOCK)
335# define ENOTSOCK 128 /* Socket operation on non-socket */
336#endif
337#if ! defined(ENOTSUP)
338# define ENOTSUP 129 /* Not supported */
339#endif
340#if ! defined(EOPNOTSUPP)
341# define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
342#endif
343#if ! defined(EUSERS)
344# define EUSERS 131 /* Too many users */
345#endif
346#if ! defined(EOVERFLOW)
347# define EOVERFLOW 132 /* Value too large for defined data type */
348#endif
349#if ! defined(EOWNERDEAD)
350# define EOWNERDEAD 133 /* Unknown error */
351#endif
352#if ! defined(EPROTO)
353# define EPROTO 134 /* Protocol error */
354#endif
355#if ! defined(EPROTONOSUPPORT)
356# define EPROTONOSUPPORT 135 /* Unknown protocol */
357#endif
358#if ! defined(EPROTOTYPE)
359# define EPROTOTYPE 136 /* Protocol wrong type for socket */
360#endif
361#if ! defined(ECASECLASH)
362# define ECASECLASH 137 /* Filename exists with different case */
363#endif
364#if ! defined(ETIMEDOUT)
365/* Make sure it's the same as WSATIMEDOUT */
366# define ETIMEDOUT 138 /* Connection timed out */
367#endif
368#if ! defined(EWOULDBLOCK) || EWOULDBLOCK == 140
369# undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
370# define EWOULDBLOCK EAGAIN /* Operation would block */
371#endif
372
373#undef HOST_NOT_FOUND
374#define HOST_NOT_FOUND 1
375#undef TRY_AGAIN
376#define TRY_AGAIN 2
377#undef NO_RECOVERY
378#define NO_RECOVERY 3
379#undef NO_ADDRESS
380#define NO_ADDRESS 4
381
382#define PROT_READ 0x1
383#define PROT_WRITE 0x2
384#define MAP_SHARED 0x1
385#define MAP_PRIVATE 0x2 /* unsupported */
386#define MAP_FIXED 0x10
387#define MAP_ANONYMOUS 0x20 /* unsupported */
388#define MAP_FAILED ((void *) -1)
389
390#define MS_ASYNC 1 /* sync memory asynchronously */
391#define MS_INVALIDATE 2 /* invalidate the caches */
392#define MS_SYNC 4 /* synchronous memory sync */
393
394struct statfs
395{
396 long f_type; /* type of filesystem (see below) */
397 long f_bsize; /* optimal transfer block size */
398 long f_blocks; /* total data blocks in file system */
399 long f_bfree; /* free blocks in fs */
400 long f_bavail; /* free blocks avail to non-superuser */
401 long f_files; /* total file nodes in file system */
402 long f_ffree; /* free file nodes in fs */
403 long f_fsid; /* file system id */
404 long f_namelen; /* maximum length of filenames */
405 long f_spare[6]; /* spare for later */
406};
407#define sleep(secs) (Sleep (secs * 1000))
408
409/*********************** statfs *****************************/
410/* fake block size */
411#define FAKED_BLOCK_SIZE 512
412
413/* linux-compatible values for fs type */
414#define MSDOS_SUPER_MAGIC 0x4d44
415#define NTFS_SUPER_MAGIC 0x5346544E
416
417/*********************** End of statfs ***********************/
418
419#define SHUT_RDWR SD_BOTH
420
421/* Operations for flock() */
422#define LOCK_SH 1 /* shared lock */
423#define LOCK_EX 2 /* exclusive lock */
424#define LOCK_NB 4 /* or'd with one of the above to prevent
425 blocking */
426#define LOCK_UN 8 /* remove lock */
427
428/* Not supported under MinGW */
429#ifndef S_IRGRP
430#define S_IRGRP 0
431#endif
432#ifndef S_IWGRP
433#define S_IWGRP 0
434#endif
435#ifndef S_IROTH
436#define S_IROTH 0
437#endif
438#ifndef S_IXGRP
439#define S_IXGRP 0
440#endif
441#ifndef S_IWOTH
442#define S_IWOTH 0
443#endif
444#ifndef S_IXOTH
445#define S_IXOTH 0
446#endif
447#ifndef S_ISUID
448#define S_ISUID 0
449#endif
450#ifndef S_ISGID
451#define S_ISGID 0
452#endif
453#ifndef S_ISVTX
454#define S_ISVTX 0
455#endif
456#ifndef S_IRWXG
457#define S_IRWXG 0
458#endif
459#ifndef S_IRWXO
460#define S_IRWXO 0
461#endif
462
463#define SHUT_WR SD_SEND
464#define SHUT_RD SD_RECEIVE
465#define SHUT_RDWR SD_BOTH
466
467#define SIGKILL 9
468#define SIGTERM 15
469
470#define SetErrnoFromWinError(e) _SetErrnoFromWinError (e, __FILE__, __LINE__)
471
472BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest);
473
474BOOL _plibc_CreateShortcutW (const wchar_t *pwszSrc, const wchar_t *pwszDest);
475
476BOOL _plibc_DereferenceShortcut (char *pszShortcut);
477
478BOOL _plibc_DereferenceShortcutW (wchar_t *pwszShortcut);
479
480char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags);
481
482wchar_t *plibc_ChooseDirW (wchar_t *pwszTitle, unsigned long ulFlags);
483
484char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags);
485
486wchar_t *plibc_ChooseFileW (wchar_t *pwszTitle, unsigned long ulFlags);
487
488long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
489 char *pszBuffer, long *pdLength);
490
491long QueryRegistryW (HKEY hMainKey, const wchar_t *pszKey, const
492 wchar_t *pszSubKey,
493 wchar_t *pszBuffer, long *pdLength);
494
495BOOL __win_IsHandleMarkedAsBlocking (int hHandle);
496
497void __win_SetHandleBlockingMode (int s, BOOL bBlocking);
498
499void __win_DiscardHandleBlockingMode (int s);
500
501int _win_isSocketValid (int s);
502
503int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows);
504
505int plibc_conv_to_win_pathw (const wchar_t *pszUnix, wchar_t *pwszWindows);
506
507int plibc_conv_to_win_pathwconv (const char *pszUnix, wchar_t *pwszWindows);
508
509int plibc_conv_to_win_pathwconv_ex (const char *pszUnix, wchar_t *pszWindows,
510 int derefLinks);
511
512unsigned plibc_get_handle_count ();
513
514typedef void (*TPanicProc) (int, char *);
515void plibc_set_panic_proc (TPanicProc proc);
516
517void plibc_set_stat_size_size (int iLength);
518
519void plibc_set_stat_time_size (int iLength);
520
521int flock (int fd, int operation);
522
523int fsync (int fildes);
524
525int inet_pton (int af, const char *src, void *dst);
526
527int inet_pton4 (const char *src, u_char *dst, int pton);
528
529#if USE_IPV6
530int inet_pton6 (const char *src, u_char *dst);
531
532#endif
533int statfs (const char *path, struct statfs *buf);
534
535const char *hstrerror (int err);
536
537int mkstemp (char *tmplate);
538
539char *strptime (const char *buf, const char *format, struct tm *tm);
540
541const char *inet_ntop (int af, const void *src, char *dst, size_t size);
542
543#ifndef gmtime_r
544struct tm *gmtime_r (const time_t *clock, struct tm *result);
545
546#endif
547
548int plibc_init (char *pszOrg, char *pszApp);
549
550int plibc_init_utf8 (char *pszOrg, char *pszApp, int utf8_mode);
551
552void plibc_shutdown ();
553
554int plibc_initialized ();
555
556void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine);
557
558void SetErrnoFromWinsockError (long lWinError);
559
560void SetHErrnoFromWinError (long lWinError);
561
562void SetErrnoFromHRESULT (HRESULT hRes);
563
564int GetErrnoFromWinsockError (long lWinError);
565
566FILE *_win_fopen (const char *filename, const char *mode);
567
568int _win_fclose (FILE *);
569
570DIR *_win_opendir (const char *dirname);
571
572struct dirent *_win_readdir (DIR *dirp);
573
574int _win_closedir (DIR *dirp);
575
576int _win_open (const char *filename, int oflag, ...);
577
578#ifdef ENABLE_NLS
579char *_win_bindtextdomain (const char *domainname, const char *dirname);
580
581#endif
582int _win_chdir (const char *path);
583
584int _win_close (int fd);
585
586int _win_creat (const char *path, mode_t mode);
587
588char *_win_ctime (const time_t *clock);
589
590char *_win_ctime_r (const time_t *clock, char *buf);
591
592int _win_fstat (int handle, struct stat *buffer);
593
594int _win_ftruncate (int fildes, off_t length);
595
596int _win_truncate (const char *fname, int distance);
597
598int _win_kill (pid_t pid, int sig);
599
600int _win_pipe (int *phandles);
601
602int _win_mkfifo (const char *path, mode_t mode);
603
604int _win_rmdir (const char *path);
605
606int _win_access (const char *path, int mode);
607
608int _win_chmod (const char *filename, int pmode);
609
610char *realpath (const char *file_name, char *resolved_name);
611
612long _win_random (void);
613
614void _win_srandom (unsigned int seed);
615
616int _win_remove (const char *path);
617
618int _win_rename (const char *oldname, const char *newname);
619
620int _win_stat (const char *path, struct stat *buffer);
621
622int _win_stati64 (const char *path, struct _stati64 *buffer);
623
624long _win_sysconf (int name);
625
626int _win_unlink (const char *filename);
627
628int _win_write (int fildes, const void *buf, size_t nbyte);
629
630int _win_read (int fildes, void *buf, size_t nbyte);
631
632size_t _win_fwrite (const void *buffer, size_t size, size_t count,
633 FILE *stream);
634
635size_t _win_fread (void *buffer, size_t size, size_t count, FILE *stream);
636
637int _win_symlink (const char *path1, const char *path2);
638
639void *_win_mmap (void *start, size_t len, int access, int flags, int fd,
640 unsigned long long offset);
641
642int _win_msync (void *start, size_t length, int flags);
643
644int _win_munmap (void *start, size_t length);
645
646int _win_lstat (const char *path, struct stat *buf);
647
648int _win_lstati64 (const char *path, struct _stati64 *buf);
649
650int _win_readlink (const char *path, char *buf, size_t bufsize);
651
652int _win_accept (int s, struct sockaddr *addr, int *addrlen);
653
654pid_t _win_waitpid (pid_t pid, int *stat_loc, int options);
655
656int _win_bind (int s, const struct sockaddr *name, int namelen);
657
658int _win_connect (int s,const struct sockaddr *name, int namelen);
659
660int _win_getpeername (int s, struct sockaddr *name,
661 int *namelen);
662
663int _win_getsockname (int s, struct sockaddr *name,
664 int *namelen);
665
666int _win_getsockopt (int s, int level, int optname, char *optval,
667 int *optlen);
668
669int _win_listen (int s, int backlog);
670
671int _win_recv (int s, char *buf, int len, int flags);
672
673int _win_recvfrom (int s, void *buf, int len, int flags,
674 struct sockaddr *from, int *fromlen);
675
676int _win_select (int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
677 const struct timeval *tv);
678
679int _win_send (int s, const char *buf, int len, int flags);
680
681int _win_sendto (int s, const char *buf, int len, int flags,
682 const struct sockaddr *to, int tolen);
683
684int _win_setsockopt (int s, int level, int optname, const void *optval,
685 int optlen);
686
687int _win_shutdown (int s, int how);
688
689int _win_socket (int af, int type, int protocol);
690
691int _win_socketpair (int af, int type, int protocol, int socket_vector[2]);
692
693struct hostent *_win_gethostbyaddr (const char *addr, int len, int type);
694
695struct hostent *_win_gethostbyname (const char *name);
696
697struct hostent *gethostbyname2 (const char *name, int af);
698
699char *_win_strerror (int errnum);
700
701int IsWinNT ();
702
703char *index (const char *s, int c);
704
705char *_win_strtok_r (char *ptr, const char *sep, char **end);
706
707#if ! HAVE_STRNDUP
708char *strndup (const char *s, size_t n);
709
710#endif
711#if ! HAVE_STRNLEN && (! defined(__MINGW64_VERSION_MAJOR) || \
712 ! defined(_INC_STRING))
713size_t strnlen (const char *str, size_t maxlen);
714
715#endif
716char *stpcpy (char *dest, const char *src);
717
718char *strcasestr (const char *haystack_start, const char *needle_start);
719
720#ifndef __MINGW64_VERSION_MAJOR
721#define strcasecmp(a, b) stricmp (a, b)
722#define strncasecmp(a, b, c) strnicmp (a, b, c)
723#endif
724#ifndef wcscasecmp
725#define wcscasecmp(a, b) wcsicmp (a, b)
726#endif
727#ifndef wcsncasecmp
728#define wcsncasecmp(a, b, c) wcsnicmp (a, b, c)
729#endif
730#ifndef strtok_r /* winpthreads defines it in pthread.h */
731#define strtok_r _win_strtok_r
732#endif
733#endif /* WINDOWS */
734
735#ifndef WINDOWS
736 #define DIR_SEPARATOR '/'
737 #define DIR_SEPARATOR_STR "/"
738 #define PATH_SEPARATOR ':'
739 #define PATH_SEPARATOR_STR ":"
740 #define NEWLINE "\n"
741
742#ifdef ENABLE_NLS
743 #define BINDTEXTDOMAIN(d, n) bindtextdomain (d, n)
744#endif
745 #define CREAT(p, m) creat (p, m)
746 #define PLIBC_CTIME(c) ctime (c)
747 #define CTIME_R(c, b) ctime_r (c, b)
748 #undef FOPEN
749 #define FOPEN(f, m) fopen (f, m)
750 #define FCLOSE(f) fclose (f)
751 #define FTRUNCATE(f, l) ftruncate (f, l)
752 #define TRUNCATE(f, l) truncate (f, l)
753 #define OPENDIR(d) opendir (d)
754 #define CLOSEDIR(d) closedir (d)
755 #define READDIR(d) readdir (d)
756 #define OPEN open
757 #define CHDIR(d) chdir (d)
758 #define CLOSE(f) close (f)
759 #define LSEEK(f, o, w) lseek (f, o, w)
760 #define RMDIR(f) rmdir (f)
761 #define ACCESS(p, m) access (p, m)
762 #define CHMOD(f, p) chmod (f, p)
763 #define FSTAT(h, b) fstat (h, b)
764 #define PLIBC_KILL(p, s) kill (p, s)
765 #define PIPE(h) pipe (h)
766 #define REMOVE(p) remove (p)
767 #define RENAME(o, n) rename (o, n)
768 #define STAT(p, b) stat (p, b)
769 #define STAT64(p, b) stat64 (p, b)
770 #define SYSCONF(n) sysconf (n)
771 #define UNLINK(f) unlink (f)
772 #define WRITE(f, b, n) write (f, b, n)
773 #define READ(f, b, n) read (f, b, n)
774 #define GN_FREAD(b, s, c, f) fread (b, s, c, f)
775 #define GN_FWRITE(b, s, c, f) fwrite (b, s, c, f)
776 #define SYMLINK(a, b) symlink (a, b)
777 #define MMAP(s, l, p, f, d, o) mmap (s, l, p, f, d, o)
778 #define MKFIFO(p, m) mkfifo (p, m)
779 #define MSYNC(s, l, f) msync (s, l, f)
780 #define MUNMAP(s, l) munmap (s, l)
781 #define STRERROR(i) strerror (i)
782 #define RANDOM() random ()
783 #define SRANDOM(s) srandom (s)
784 #define READLINK(p, b, s) readlink (p, b, s)
785 #define LSTAT(p, b) lstat (p, b)
786 #define LSTAT64(p, b) lstat64 (p, b)
787 #define PRINTF printf
788 #define FPRINTF fprintf
789 #define VPRINTF(f, a) vprintf (f, a)
790 #define VFPRINTF(s, f, a) vfprintf (s, f, a)
791 #define VSPRINTF(d, f, a) vsprintf (d, f, a)
792 #define VSNPRINTF(str, size, fmt, a) vsnprintf (str, size, fmt, a)
793 #define _REAL_SNPRINTF snprintf
794 #define SPRINTF sprintf
795 #define VSSCANF(s, f, a) vsscanf (s, f, a)
796 #define SSCANF sscanf
797 #define VFSCANF(s, f, a) vfscanf (s, f, a)
798 #define VSCANF(f, a) vscanf (f, a)
799 #define SCANF scanf
800 #define FSCANF fscanf
801 #define WAITPID(p, s, o) waitpid (p, s, o)
802 #define ACCEPT(s, a, l) accept (s, a, l)
803 #define BIND(s, n, l) bind (s, n, l)
804 #define CONNECT(s, n, l) connect (s, n, l)
805 #define GETPEERNAME(s, n, l) getpeername (s, n, l)
806 #define GETSOCKNAME(s, n, l) getsockname (s, n, l)
807 #define GETSOCKOPT(s, l, o, v, p) getsockopt (s, l, o, v, p)
808 #define LISTEN(s, b) listen (s, b)
809 #define RECV(s, b, l, f) recv (s, b, l, f)
810 #define RECVFROM(s, b, l, f, r, o) recvfrom (s, b, l, f, r, o)
811 #define SELECT(n, r, w, e, t) select (n, r, w, e, t)
812 #define SEND(s, b, l, f) send (s, b, l, f)
813 #define SENDTO(s, b, l, f, o, n) sendto (s, b, l, f, o, n)
814 #define SETSOCKOPT(s, l, o, v, n) setsockopt (s, l, o, v, n)
815 #define SHUTDOWN(s, h) shutdown (s, h)
816 #define SOCKET(a, t, p) socket (a, t, p)
817 #define SOCKETPAIR(a, t, p, v) socketpair (a, t, p, v)
818 #define GETHOSTBYADDR(a, l, t) gethostbyaddr (a, l, t)
819 #define GETHOSTBYNAME(n) gethostbyname (n)
820 #define GETTIMEOFDAY(t, n) gettimeofday (t, n)
821 #define INSQUE(e, p) insque (e, p)
822 #define REMQUE(e) remque (e)
823 #define HSEARCH(i, a) hsearch (i, a)
824 #define HCREATE(n) hcreate (n)
825 #define HDESTROY() hdestroy ()
826 #define HSEARCH_R(i, a, r, h) hsearch_r (i, a, r, h)
827 #define HCREATE_R(n, h) hcreate_r (n, h)
828 #define HDESTROY_R(h) hdestroy_r (h)
829 #define TSEARCH(k, r, c) tsearch (k, r, c)
830 #define TFIND(k, r, c) tfind (k, r, c)
831 #define TDELETE(k, r, c) tdelete (k, r, c)
832 #define TWALK(r, a) twalk (r, a)
833 #define TDESTROY(r, f) tdestroy (r, f)
834 #define LFIND(k, b, n, s, c) lfind (k, b, n, s, c)
835 #define LSEARCH(k, b, n, s, c) lsearch (k, b, n, s, c)
836 #define STRUCT_STAT64 struct stat64
837#else
838 #define DIR_SEPARATOR '\\'
839 #define DIR_SEPARATOR_STR "\\"
840 #define PATH_SEPARATOR ';'
841 #define PATH_SEPARATOR_STR ";"
842 #define NEWLINE "\r\n"
843
844#ifdef ENABLE_NLS
845 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain (d, n)
846#endif
847 #define CREAT(p, m) _win_creat (p, m)
848 #define PLIBC_CTIME(c) _win_ctime (c)
849 #define CTIME_R(c, b) _win_ctime_r (c, b)
850 #define FOPEN(f, m) _win_fopen (f, m)
851 #define FCLOSE(f) _win_fclose (f)
852 #define FTRUNCATE(f, l) _win_ftruncate (f, l)
853 #define TRUNCATE(f, l) _win_truncate (f, l)
854 #define OPENDIR(d) _win_opendir (d)
855 #define CLOSEDIR(d) _win_closedir (d)
856 #define READDIR(d) _win_readdir (d)
857 #define OPEN _win_open
858 #define CHDIR(d) _win_chdir (d)
859 #define CLOSE(f) _win_close (f)
860 #define PLIBC_KILL(p, s) _win_kill (p, s)
861 #define LSEEK(f, o, w) lseek (f, o, w)
862 #define FSTAT(h, b) _win_fstat (h, b)
863 #define RMDIR(f) _win_rmdir (f)
864 #define ACCESS(p, m) _win_access (p, m)
865 #define CHMOD(f, p) _win_chmod (f, p)
866 #define PIPE(h) _win_pipe (h)
867 #define RANDOM() _win_random ()
868 #define SRANDOM(s) _win_srandom (s)
869 #define REMOVE(p) _win_remove (p)
870 #define RENAME(o, n) _win_rename (o, n)
871 #define STAT(p, b) _win_stat (p, b)
872 #define STAT64(p, b) _win_stati64 (p, b)
873 #define SYSCONF(n) _win_sysconf (n)
874 #define UNLINK(f) _win_unlink (f)
875 #define WRITE(f, b, n) _win_write (f, b, n)
876 #define READ(f, b, n) _win_read (f, b, n)
877 #define GN_FREAD(b, s, c, f) _win_fread (b, s, c, f)
878 #define GN_FWRITE(b, s, c, f) _win_fwrite (b, s, c, f)
879 #define SYMLINK(a, b) _win_symlink (a, b)
880 #define MMAP(s, l, p, f, d, o) _win_mmap (s, l, p, f, d, o)
881 #define MKFIFO(p, m) _win_mkfifo (p, m)
882 #define MSYNC(s, l, f) _win_msync (s, l, f)
883 #define MUNMAP(s, l) _win_munmap (s, l)
884 #define STRERROR(i) _win_strerror (i)
885 #define READLINK(p, b, s) _win_readlink (p, b, s)
886 #define LSTAT(p, b) _win_lstat (p, b)
887 #define LSTAT64(p, b) _win_lstati64 (p, b)
888 #define PRINTF printf
889 #define FPRINTF fprintf
890 #define VPRINTF(f, a) vprintf (f, a)
891 #define VFPRINTF(s, f, a) vfprintf (s, f, a)
892 #define VSPRINTF(d, f, a) vsprintf (d, f, a)
893 #define VSNPRINTF(str, size, fmt, a) vsnprintf (str, size, fmt, a)
894 #define _REAL_SNPRINTF snprintf
895 #define SPRINTF sprintf
896 #define VSSCANF(s, f, a) vsscanf (s, f, a)
897 #define SSCANF sscanf
898 #define VFSCANF(s, f, a) vfscanf (s, f, a)
899 #define VSCANF(f, a) vscanf (f, a)
900 #define SCANF scanf
901 #define FSCANF fscanf
902 #define WAITPID(p, s, o) _win_waitpid (p, s, o)
903 #define ACCEPT(s, a, l) _win_accept (s, a, l)
904 #define BIND(s, n, l) _win_bind (s, n, l)
905 #define CONNECT(s, n, l) _win_connect (s, n, l)
906 #define GETPEERNAME(s, n, l) _win_getpeername (s, n, l)
907 #define GETSOCKNAME(s, n, l) _win_getsockname (s, n, l)
908 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt (s, l, o, v, p)
909 #define LISTEN(s, b) _win_listen (s, b)
910 #define RECV(s, b, l, f) _win_recv (s, b, l, f)
911 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom (s, b, l, f, r, o)
912 #define SELECT(n, r, w, e, t) _win_select (n, r, w, e, t)
913 #define SEND(s, b, l, f) _win_send (s, b, l, f)
914 #define SENDTO(s, b, l, f, o, n) _win_sendto (s, b, l, f, o, n)
915 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt (s, l, o, v, n)
916 #define SHUTDOWN(s, h) _win_shutdown (s, h)
917 #define SOCKET(a, t, p) _win_socket (a, t, p)
918 #define SOCKETPAIR(a, t, p, v) _win_socketpair (a, t, p, v)
919 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr (a, l, t)
920 #define GETHOSTBYNAME(n) _win_gethostbyname (n)
921 #define GETTIMEOFDAY(t, n) gettimeofday (t, n)
922 #define INSQUE(e, p) _win_insque (e, p)
923 #define REMQUE(e) _win_remque (e)
924 #define HSEARCH(i, a) _win_hsearch (i, a)
925 #define HCREATE(n) _win_hcreate (n)
926 #define HDESTROY() _win_hdestroy ()
927 #define HSEARCH_R(i, a, r, h) _win_hsearch_r (i, a, r, h)
928 #define HCREATE_R(n, h) _win_hcreate_r (n, h)
929 #define HDESTROY_R(h) _win_hdestroy_r (h)
930 #define TSEARCH(k, r, c) _win_tsearch (k, r, c)
931 #define TFIND(k, r, c) _win_tfind (k, r, c)
932 #define TDELETE(k, r, c) _win_tdelete (k, r, c)
933 #define TWALK(r, a) _win_twalk (r, a)
934 #define TDESTROY(r, f) _win_tdestroy (r, f)
935 #define LFIND(k, b, n, s, c) _win_lfind (k, b, n, s, c)
936 #define LSEARCH(k, b, n, s, c) _win_lsearch (k, b, n, s, c)
937 #define STRUCT_STAT64 struct _stati64
938#endif
939
940/* search.h */
941
942/* Prototype structure for a linked-list data structure.
943 This is the type used by the `insque' and `remque' functions. */
944
945struct PLIBC_SEARCH_QELEM
946{
947 struct qelem *q_forw;
948 struct qelem *q_back;
949 char q_data[1];
950};
951
952
953/* Insert ELEM into a doubly-linked list, after PREV. */
954void _win_insque (void *__elem, void *__prev);
955
956/* Unlink ELEM from the doubly-linked list that it is in. */
957void _win_remque (void *__elem);
958
959
960/* For use with hsearch(3). */
961typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
962
963typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
964
965/* Action which shall be performed in the call the hsearch. */
966typedef enum
967{
968 PLIBC_SEARCH_FIND,
969 PLIBC_SEARCH_ENTER
970}
971PLIBC_SEARCH_ACTION;
972
973typedef struct PLIBC_SEARCH_entry
974{
975 char *key;
976 void *data;
977}
978PLIBC_SEARCH_ENTRY;
979
980/* The reentrant version has no static variables to maintain the state.
981 Instead the interface of all functions is extended to take an argument
982 which describes the current status. */
983typedef struct _PLIBC_SEARCH_ENTRY
984{
985 unsigned int used;
986 PLIBC_SEARCH_ENTRY entry;
987}
988_PLIBC_SEARCH_ENTRY;
989
990
991/* Family of hash table handling functions. The functions also
992 have reentrant counterparts ending with _r. The non-reentrant
993 functions all work on a signle internal hashing table. */
994
995/* Search for entry matching ITEM.key in internal hash table. If
996 ACTION is `FIND' return found entry or signal error by returning
997 NULL. If ACTION is `ENTER' replace existing data (if any) with
998 ITEM.data. */
999PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION
1000 __action);
1001
1002/* Create a new hashing table which will at most contain NEL elements. */
1003int _win_hcreate (size_t __nel);
1004
1005/* Destroy current internal hashing table. */
1006void _win_hdestroy (void);
1007
1008/* Data type for reentrant functions. */
1009struct PLIBC_SEARCH_hsearch_data
1010{
1011 struct _PLIBC_SEARCH_ENTRY *table;
1012 unsigned int size;
1013 unsigned int filled;
1014};
1015
1016/* Reentrant versions which can handle multiple hashing tables at the
1017 same time. */
1018int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action,
1019 PLIBC_SEARCH_ENTRY **__retval,
1020 struct PLIBC_SEARCH_hsearch_data *__htab);
1021
1022int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
1023
1024void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
1025
1026
1027/* The tsearch routines are very interesting. They make many
1028 assumptions about the compiler. It assumes that the first field
1029 in node must be the "key" field, which points to the datum.
1030 Everything depends on that. */
1031/* For tsearch */
1032typedef enum
1033{
1034 PLIBC_SEARCH_preorder,
1035 PLIBC_SEARCH_postorder,
1036 PLIBC_SEARCH_endorder,
1037 PLIBC_SEARCH_leaf
1038}
1039PLIBC_SEARCH_VISIT;
1040
1041/* Search for an entry matching the given KEY in the tree pointed to
1042 by *ROOTP and insert a new element if not found. */
1043void *_win_tsearch (__const void *__key, void **__rootp,
1044 PLIBC_SEARCH__compar_fn_t __compar);
1045
1046/* Search for an entry matching the given KEY in the tree pointed to
1047 by *ROOTP. If no matching entry is available return NULL. */
1048void *_win_tfind (__const void *__key, void *__const *__rootp,
1049 PLIBC_SEARCH__compar_fn_t __compar);
1050
1051/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
1052void *_win_tdelete (__const void *__restrict __key,
1053 void **__restrict __rootp,
1054 PLIBC_SEARCH__compar_fn_t __compar);
1055
1056typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep,
1057 PLIBC_SEARCH_VISIT __value,
1058 int __level);
1059
1060/* Walk through the whole tree and call the ACTION callback for every node
1061 or leaf. */
1062void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
1063
1064/* Callback type for function to free a tree node. If the keys are atomic
1065 data this function should do nothing. */
1066typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
1067
1068/* Destroy the whole tree, call FREEFCT for each node or leaf. */
1069void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
1070
1071
1072/* Perform linear search for KEY by comparing by COMPAR in an array
1073 [BASE,BASE+NMEMB*SIZE). */
1074void *_win_lfind (__const void *__key, __const void *__base,
1075 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t
1076 __compar);
1077
1078/* Perform linear search for KEY by comparing by COMPAR function in
1079 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
1080void *_win_lsearch (__const void *__key, void *__base,
1081 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t
1082 __compar);
1083
1084
1085#ifdef __cplusplus
1086}
1087#endif
1088
1089
1090#endif // _PLIBC_H_
1091
1092/* end of plibc.h */
diff --git a/src/plugins/test_lib.c b/src/plugins/test_lib.c
index 97d4dc5..8bd6d4e 100644
--- a/src/plugins/test_lib.c
+++ b/src/plugins/test_lib.c
@@ -26,6 +26,7 @@
26#include "test_lib.h" 26#include "test_lib.h"
27#include <sys/types.h> 27#include <sys/types.h>
28#include <regex.h> 28#include <regex.h>
29#include <signal.h>
29 30
30/** 31/**
31 * Function that libextractor calls for each 32 * Function that libextractor calls for each
@@ -174,6 +175,33 @@ run (const char *plugin_name,
174} 175}
175 176
176 177
178#ifndef WINDOWS
179/**
180 * Install a signal handler to ignore SIGPIPE.
181 */
182static void
183ignore_sigpipe ()
184{
185 struct sigaction oldsig;
186 struct sigaction sig;
187
188 memset (&sig, 0, sizeof (struct sigaction));
189 sig.sa_handler = SIG_IGN;
190 sigemptyset (&sig.sa_mask);
191#ifdef SA_INTERRUPT
192 sig.sa_flags = SA_INTERRUPT; /* SunOS */
193#else
194 sig.sa_flags = SA_RESTART;
195#endif
196 if (0 != sigaction (SIGPIPE, &sig, &oldsig))
197 fprintf (stderr,
198 "Failed to install SIGPIPE handler: %s\n", strerror (errno));
199}
200
201
202#endif
203
204
177/** 205/**
178 * Main function to be called to test a plugin. 206 * Main function to be called to test a plugin.
179 * 207 *
@@ -191,7 +219,10 @@ ET_main (const char *plugin_name,
191 /* change environment to find plugins which may not yet be 219 /* change environment to find plugins which may not yet be
192 not installed but should be in the current directory (or .libs) 220 not installed but should be in the current directory (or .libs)
193 on 'make check' */ 221 on 'make check' */
194 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 222#ifndef WINDOWS
223 ignore_sigpipe ();
224#endif
225 if (0 != putenv ("LIBEXTRACTOR_PREFIX=./.libs/"))
195 fprintf (stderr, 226 fprintf (stderr,
196 "Failed to update my environment, plugin loading may fail: %s\n", 227 "Failed to update my environment, plugin loading may fail: %s\n",
197 strerror (errno)); 228 strerror (errno));