Imported Upstream version 2.2.12
[platform/upstream/gpg2.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 and/or modify this
8  * part of GnuPG 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,
51    wipememory function may be used instead.  */
52 void wipememory(void *ptr, size_t len);
53
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>
58 # include <sys/un.h>
59 #else
60 # ifdef HAVE_WINSOCK2_H
61 #  include <winsock2.h>
62 # endif
63 # include <windows.h>
64 #endif
65
66 #ifndef PF_LOCAL
67 # ifdef PF_UNIX
68 #  define PF_LOCAL PF_UNIX
69 # else
70 #  define PF_LOCAL AF_UNIX
71 # endif
72 #endif /*PF_LOCAL*/
73 #ifndef AF_LOCAL
74 # define AF_LOCAL AF_UNIX
75 #endif /*AF_UNIX*/
76
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.  */
85 #ifndef SUN_LEN
86 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
87                        + strlen ((ptr)->sun_path))
88 #endif /*SUN_LEN*/
89 #endif /*GNUPG_COMMON_NEED_AFLOCAL*/
90
91
92 #endif /*GNUPG_COMMON_MISCHELP_H*/