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 and/or modify this
8 * part of GnuPG 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,
51 wipememory function may be used instead. */
52 void wipememory(void *ptr, size_t len);
54 /* Include hacks which are mainly required for Slowaris. */
55 #ifdef GNUPG_COMMON_NEED_AFLOCAL
56 #ifndef HAVE_W32_SYSTEM
57 # include <sys/socket.h>
60 # ifdef HAVE_WINSOCK2_H
61 # include <winsock2.h>
68 # define PF_LOCAL PF_UNIX
70 # define PF_LOCAL AF_UNIX
74 # define AF_LOCAL AF_UNIX
77 /* We used to avoid this macro in GnuPG and inlined the AF_LOCAL name
78 length computation directly with the little twist of adding 1 extra
79 byte. It seems that this was needed once on an old HP/UX box and
80 there are also rumours that 4.3 Reno and DEC systems need it. This
81 one-off buglet did not harm any current system until it came to Mac
82 OS X where the kernel (as of May 2009) exhibited a strange bug: The
83 systems basically froze in the connect call if the passed name
84 contained an invalid directory part. Ignore the old Unices. */
86 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
87 + strlen ((ptr)->sun_path))
89 #endif /*GNUPG_COMMON_NEED_AFLOCAL*/
92 #endif /*GNUPG_COMMON_MISCHELP_H*/