1 /* gen-posix-lock-obj.c - Build tool to construct the lock object.
2 Copyright (C) 2014 g10 Code GmbH
4 This file is part of libgpg-error.
6 libgpg-error is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License
8 as published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 libgpg-error is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #ifdef HAVE_W32_SYSTEM
25 # error This module may not be build for Windows.
33 #include "posix-lock-obj.h"
35 #define PGM "gen-posix-lock-obj"
37 /* Check that configure did its job. */
38 #if SIZEOF_PTHREAD_MUTEX_T < 4
39 # error sizeof pthread_mutex_t is not known.
42 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
55 if (sizeof mtx != SIZEOF_PTHREAD_MUTEX_T)
57 fprintf (stderr, PGM ": pthread_mutex_t mismatch\n");
61 if (sizeof (dummyobj) != sizeof (_gpgrt_lock_t))
63 fprintf (stderr, PGM ": internal and external lock object mismatch\n");
67 /* To force a probably suitable alignment of the structure we use a
68 union and include a long and a pointer to a long. */
69 printf ("## lock-obj-pub.%s.h\n"
70 "## File created by " PGM " - DO NOT EDIT\n"
71 "## To be included by mkheader into gpg-error.h\n"
77 " volatile char _priv[%d];\n"
83 "#define GPGRT_LOCK_INITIALIZER {%d,{{",
85 SIZEOF_PTHREAD_MUTEX_T,
87 p = (unsigned char *)&mtx;
88 for (i=0; i < sizeof mtx; i++)
91 printf (" \\\n%*s", 36, "");
93 if (i < sizeof mtx - 1)
98 "## Loc" "al Variables:\n"
100 "## buffer-read-only: t\n"
106 fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno));