chiark / gitweb /
Import gnupg2_2.1.17.orig.tar.bz2
[gnupg2.git] / common / mischelp.h
1 /* mischelp.h - Miscellaneous helper macros and functions
2  * Copyright (C) 1999, 2000, 2001, 2002, 2003,
3  *               2006, 2007, 2009  Free Software Foundation, Inc.
4  *
5  * This file is part of GnuPG.
6  *
7  * GnuPG is free software; you can redistribute it and/or modify it
8  * under the terms of either
9  *
10  *   - the GNU Lesser General Public License as published by the Free
11  *     Software Foundation; either version 3 of the License, or (at
12  *     your option) any later version.
13  *
14  * or
15  *
16  *   - the GNU General Public License as published by the Free
17  *     Software Foundation; either version 2 of the License, or (at
18  *     your option) any later version.
19  *
20  * or both in parallel, as here.
21  *
22  * GnuPG is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * General Public License for more details.
26  *
27  * You should have received a copies of the GNU General Public License
28  * and the GNU Lesser General Public License along with this program;
29  * if not, see <https://www.gnu.org/licenses/>.
30  */
31
32 #ifndef GNUPG_COMMON_MISCHELP_H
33 #define GNUPG_COMMON_MISCHELP_H
34
35
36 /* Check whether the files NAME1 and NAME2 are identical.  This is for
37    example achieved by comparing the inode numbers of the files.  */
38 int same_file_p (const char *name1, const char *name2);
39
40
41 #ifndef HAVE_TIMEGM
42 #include <time.h>
43 time_t timegm (struct tm *tm);
44 #endif /*!HAVE_TIMEGM*/
45
46
47 #define DIM(v)               (sizeof(v)/sizeof((v)[0]))
48 #define DIMof(type,member)   DIM(((type *)0)->member)
49
50 /* To avoid that a compiler optimizes certain memset calls away, these
51    macros may be used instead. */
52 #define wipememory2(_ptr,_set,_len) do { \
53               volatile char *_vptr=(volatile char *)(_ptr); \
54               size_t _vlen=(_len); \
55               while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
56                   } while(0)
57 #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
58
59
60 /* Include hacks which are mainly required for Slowaris.  */
61 #ifdef GNUPG_COMMON_NEED_AFLOCAL
62 #ifndef HAVE_W32_SYSTEM
63 # include <sys/socket.h>
64 # include <sys/un.h>
65 #else
66 # ifdef HAVE_WINSOCK2_H
67 #  include <winsock2.h>
68 # endif
69 # include <windows.h>
70 #endif
71
72 #ifndef PF_LOCAL
73 # ifdef PF_UNIX
74 #  define PF_LOCAL PF_UNIX
75 # else
76 #  define PF_LOCAL AF_UNIX
77 # endif
78 #endif /*PF_LOCAL*/
79 #ifndef AF_LOCAL
80 # define AF_LOCAL AF_UNIX
81 #endif /*AF_UNIX*/
82
83 /* We used to avoid this macro in GnuPG and inlined the AF_LOCAL name
84    length computation directly with the little twist of adding 1 extra
85    byte.  It seems that this was needed once on an old HP/UX box and
86    there are also rumours that 4.3 Reno and DEC systems need it.  This
87    one-off buglet did not harm any current system until it came to Mac
88    OS X where the kernel (as of May 2009) exhibited a strange bug: The
89    systems basically froze in the connect call if the passed name
90    contained an invalid directory part.  Ignore the old Unices.  */
91 #ifndef SUN_LEN
92 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
93                        + strlen ((ptr)->sun_path))
94 #endif /*SUN_LEN*/
95 #endif /*GNUPG_COMMON_NEED_AFLOCAL*/
96
97
98 #endif /*GNUPG_COMMON_MISCHELP_H*/