From 92ff7f21ad0b167f8d742a9d7b5f93704a57619c Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Thu, 24 Apr 2008 02:02:49 +0000 Subject: Major coding style cleanup. Updated all shared code from my other projects. The configure option requesting AFS kaserver support (and thus building kasetkey) is now --with-kaserver instead of --with-afs. If KRB5_CONFIG was explicitly set in the environment, don't use a different krb5-config based on --with-krb4 or --with-krb5. If krb5-config isn't executable, don't use it. This allows one to force library probing by setting KRB5_CONFIG to point to a nonexistent file. Sanity-check the results of krb5-config before proceeding and error out in configure if they don't work. Stop setting Stanford-specific compile-time defaults for the wallet server and port. --- portable/asprintf.c | 28 +++++++------ portable/dummy.c | 23 ++++++----- portable/snprintf.c | 32 ++++++++------- portable/stdbool.h | 43 ++++++++++++++++++++ portable/strlcat.c | 2 +- portable/strlcpy.c | 2 +- portable/system.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 199 insertions(+), 42 deletions(-) create mode 100644 portable/stdbool.h create mode 100644 portable/system.h (limited to 'portable') diff --git a/portable/asprintf.c b/portable/asprintf.c index 56a69c4..9cae827 100644 --- a/portable/asprintf.c +++ b/portable/asprintf.c @@ -1,19 +1,21 @@ -/* $Id$ -** -** Replacement for a missing asprintf and vasprintf. -** -** Written by Russ Allbery -** This work is hereby placed in the public domain by its author. -** -** Provides the same functionality as the standard GNU library routines -** asprintf and vasprintf for those platforms that don't have them. -*/ +/* $Id$ + * + * Replacement for a missing asprintf and vasprintf. + * + * Provides the same functionality as the standard GNU library routines + * asprintf and vasprintf for those platforms that don't have them. + * + * Written by Russ Allbery + * This work is hereby placed in the public domain by its author. + */ #include -#include +#include -/* If we're running the test suite, rename the functions to avoid conflicts - with the system versions. */ +/* + * If we're running the test suite, rename the functions to avoid conflicts + * with the system versions. + */ #if TESTING # define asprintf test_asprintf # define vasprintf test_vasprintf diff --git a/portable/dummy.c b/portable/dummy.c index e5a6224..66341c3 100644 --- a/portable/dummy.c +++ b/portable/dummy.c @@ -1,15 +1,14 @@ -/* $Id$ -** -** Dummy symbol to prevent an empty library. -** -** Written by Russ Allbery -** This work is hereby placed in the public domain by its author. -** -** On platforms that already have all of the functions that libportable would -** supply, Automake builds an empty library and then calls ar with -** nonsensical arguments. Ensure that libportable always contains at least -** one symbol. -*/ +/* $Id$ + * + * Dummy symbol to prevent an empty library. + * + * On platforms that already have all of the functions that libportable would + * supply, Automake builds an empty library and then calls ar with nonsensical + * arguments. Ensure that libportable always contains at least one symbol. + * + * Written by Russ Allbery + * This work is hereby placed in the public domain by its author. + */ /* Prototype to avoid gcc warnings. */ int portable_dummy(void); diff --git a/portable/snprintf.c b/portable/snprintf.c index bef3da7..3c39de8 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -1,18 +1,20 @@ -/* $Id$ -** -** Replacement for a missing snprintf or vsnprintf. -** -** The following implementation of snprintf was taken mostly verbatim from -** ; it is the version of snprintf -** used in Mutt. -** -** Please do not reformat or otherwise change this file more than -** necessary so that later merges with the original source are easy. -** Bug fixes and improvements should be sent back to the original author. -*/ - -/* If we're running the test suite, rename snprintf and vsnprintf to avoid - conflicts with the system version. */ +/* $Id$ + * + * Replacement for a missing snprintf or vsnprintf. + * + * The following implementation of snprintf was taken mostly verbatim from + * ; it is the version of snprintf + * used in Mutt. + * + * Please do not reformat or otherwise change this file more than necessary so + * that later merges with the original source are easy. Bug fixes and + * improvements should be sent back to the original author. + */ + +/* + * If we're running the test suite, rename snprintf and vsnprintf to avoid + * conflicts with the system version. + */ #if TESTING # define snprintf test_snprintf # define vsnprintf test_vsnprintf diff --git a/portable/stdbool.h b/portable/stdbool.h new file mode 100644 index 0000000..61dd8a1 --- /dev/null +++ b/portable/stdbool.h @@ -0,0 +1,43 @@ +/* $Id$ + * + * Portability wrapper around . + * + * Provides the bool and _Bool types and the true and false constants, + * following the C99 specification, on hosts that don't have stdbool.h. This + * logic is based heavily on the example in the Autoconf manual. + * + * Written by Russ Allbery + * This work is hereby placed in the public domain by its author. + */ + +#ifndef PORTABLE_STDBOOL_H +#define PORTABLE_STDBOOL_H 1 + +#if HAVE_STDBOOL_H +# include +#else +# if !HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# elif _WIN32 +# include +# define bool BOOL +# else +typedef unsigned char _Bool; +# define bool _Bool +# endif +# endif +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +#endif + +/* + * If we define bool and don't tell Perl, it will try to define its own and + * fail. Only of interest for programs that also include Perl headers. + */ +#ifndef HAS_BOOL +# define HAS_BOOL 1 +#endif + +#endif /* !PORTABLE_STDBOOL_H */ diff --git a/portable/strlcat.c b/portable/strlcat.c index 971a348..4816f90 100644 --- a/portable/strlcat.c +++ b/portable/strlcat.c @@ -15,7 +15,7 @@ */ #include -#include +#include /* * If we're running the test suite, rename strlcat to avoid conflicts with diff --git a/portable/strlcpy.c b/portable/strlcpy.c index 1dd49a3..d281645 100644 --- a/portable/strlcpy.c +++ b/portable/strlcpy.c @@ -14,7 +14,7 @@ */ #include -#include +#include /* * If we're running the test suite, rename strlcpy to avoid conflicts with diff --git a/portable/system.h b/portable/system.h new file mode 100644 index 0000000..1408ba7 --- /dev/null +++ b/portable/system.h @@ -0,0 +1,111 @@ +/* $Id$ + * + * Declarations of routines and variables in the C library. Including this + * file is the equivalent of including all of the following headers, portably: + * + * #include + * #include + * #include + * #include + * #include + * #include + * #include + * #include + * #include + * + * Missing functions are provided via #define or prototyped if available. + * Also provides some standard #defines. + * + * Written by Russ Allbery + * This work is hereby placed in the public domain by its author. + */ + +#ifndef PORTABLE_SYSTEM_H +#define PORTABLE_SYSTEM_H 1 + +/* Make sure we have our configuration information. */ +#include + +/* BEGIN_DECL and __attribute__. */ +#include + +/* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */ +#include +#include +#include +#include +#include +#include +#if HAVE_INTTYPES_H +# include +#endif +#if HAVE_STDINT_H +# include +#endif +#if HAVE_UNISTD_H +# include +#endif + +/* SCO OpenServer gets int32_t from here. */ +#if HAVE_SYS_BITYPES_H +# include +#endif + +/* Get the bool type. */ +#include + +BEGIN_DECLS + +/* + * Provide prototypes for functions not declared in system headers. Use the + * HAVE_DECL macros for those functions that may be prototyped but + * implemented incorrectly or implemented without a prototype. + */ +#if !HAVE_ASPRINTF +extern int asprintf(char **, const char *, ...); +extern int vasprintf(char **, const char *, va_list); +#endif +#if !HAVE_DECL_SNPRINTF +extern int snprintf(char *, size_t, const char *, ...) + __attribute__((__format__(printf, 3, 4))); +#endif +#if !HAVE_DECL_VSNPRINTF +extern int vsnprintf(char *, size_t, const char *, va_list); +#endif +#if !HAVE_STRLCAT +extern size_t strlcat(char *, const char *, size_t); +#endif +#if !HAVE_STRLCPY +extern size_t strlcpy(char *, const char *, size_t); +#endif + +END_DECLS + +/* Windows provides snprintf under a different name. */ +#ifdef _WIN32 +# define snprintf _snprintf +#endif + +/* + * POSIX requires that these be defined in . If one of them has + * been defined, all the rest almost certainly have. + */ +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +# define STDOUT_FILENO 1 +# define STDERR_FILENO 2 +#endif + +/* + * C99 requires va_copy. Older versions of GCC provide __va_copy. Per the + * Autoconf manual, memcpy is a generally portable fallback. + */ +#ifndef va_copy +# ifdef __va_copy +# define va_copy(d, s) __va_copy((d), (s)) +# else +# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) +# endif +#endif + +#endif /* !PORTABLE_SYSTEM_H */ -- cgit v1.2.3