1 /* mischelp.h - Miscellaneous helper macros and functions
2 * Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 * 2006, 2007, 2009 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify it
8 * under the terms of either
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.
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.
20 * or both in parallel, as here.
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.
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/>.
32 #ifndef GNUPG_COMMON_MISCHELP_H
33 #define GNUPG_COMMON_MISCHELP_H
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);
43 time_t timegm (struct tm *tm);
44 #endif /*!HAVE_TIMEGM*/
47 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
48 #define DIMof(type,member) DIM(((type *)0)->member)
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--; } \
57 #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
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>
66 # ifdef HAVE_WINSOCK2_H
67 # include <winsock2.h>
74 # define PF_LOCAL PF_UNIX
76 # define PF_LOCAL AF_UNIX
80 # define AF_LOCAL AF_UNIX
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. */
92 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
93 + strlen ((ptr)->sun_path))
95 #endif /*GNUPG_COMMON_NEED_AFLOCAL*/
98 #endif /*GNUPG_COMMON_MISCHELP_H*/