aboutsummaryrefslogtreecommitdiff
path: root/portable
diff options
context:
space:
mode:
Diffstat (limited to 'portable')
-rw-r--r--portable/asprintf.c18
-rw-r--r--portable/dummy.c20
-rw-r--r--portable/krb5-extra.c23
-rw-r--r--portable/krb5-profile.c237
-rw-r--r--portable/krb5.h39
-rw-r--r--portable/macros.h18
-rw-r--r--portable/mkstemp.c17
-rw-r--r--portable/reallocarray.c24
-rw-r--r--portable/setenv.c18
-rw-r--r--portable/snprintf.c117
-rw-r--r--portable/stdbool.h17
-rw-r--r--portable/system.h35
-rw-r--r--portable/uio.h17
13 files changed, 453 insertions, 147 deletions
diff --git a/portable/asprintf.c b/portable/asprintf.c
index 9693842..aef3639 100644
--- a/portable/asprintf.c
+++ b/portable/asprintf.c
@@ -5,17 +5,19 @@
* asprintf and vasprintf for those platforms that don't have them.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006, 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008-2009, 2011, 2013
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
diff --git a/portable/dummy.c b/portable/dummy.c
index 890bc0c..121a734 100644
--- a/portable/dummy.c
+++ b/portable/dummy.c
@@ -6,23 +6,25 @@
* arguments. Ensure that libportable always contains at least one symbol.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2011, 2013
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <portable/macros.h>
/* Prototype to avoid gcc warnings and set visibility. */
-int portable_dummy(void) __attribute__((__visibility__("hidden")));
+int portable_dummy(void) __attribute__((__const__, __visibility__("hidden")));
int
portable_dummy(void)
diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c
index c8309a4..9de8e65 100644
--- a/portable/krb5-extra.c
+++ b/portable/krb5-extra.c
@@ -7,17 +7,19 @@
* Kerberos libraries are fully capable, this file will be skipped.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015-2016, 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2010-2012, 2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
@@ -49,7 +51,10 @@
* This string is returned for unknown error messages. We use a static
* variable so that we can be sure not to free it.
*/
+#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) \
+ || !defined(HAVE_KRB5_FREE_ERROR_MESSAGE)
static const char error_unknown[] = "unknown error";
+#endif
#ifndef HAVE_KRB5_GET_ERROR_MESSAGE
@@ -62,7 +67,7 @@ static const char error_unknown[] = "unknown error";
const char *
krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED)
{
- const char *msg = NULL;
+ const char *msg;
# if defined(HAVE_KRB5_GET_ERROR_STRING)
msg = krb5_get_error_string(ctx);
diff --git a/portable/krb5-profile.c b/portable/krb5-profile.c
new file mode 100644
index 0000000..f4d4652
--- /dev/null
+++ b/portable/krb5-profile.c
@@ -0,0 +1,237 @@
+/*
+ * Kerberos compatibility functions for AIX's NAS libraries.
+ *
+ * AIX for some reason doesn't provide the krb5_appdefault_* functions, but
+ * does provide the underlying profile library functions (as a separate
+ * libk5profile with a separate k5profile.h header file).
+ *
+ * This file is therefore (apart from the includes, opening and closing
+ * comments, and the spots marked with an rra-c-util comment) a verbatim copy
+ * of src/lib/krb5/krb/appdefault.c from MIT Kerberos 1.4.4.
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Copyright 1985-2005 by the Massachusetts Institute of Technology.
+ * For license information, see the end of this file.
+ */
+
+#include <config.h>
+
+#include <krb5.h>
+#ifdef HAVE_K5PROFILE_H
+# include <k5profile.h>
+#endif
+#ifdef HAVE_PROFILE_H
+# include <profile.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+
+ /*xxx Duplicating this is annoying; try to work on a better way.*/
+static const char *const conf_yes[] = {
+ "y", "yes", "true", "t", "1", "on",
+ 0,
+};
+
+static const char *const conf_no[] = {
+ "n", "no", "false", "nil", "0", "off",
+ 0,
+};
+
+static int conf_boolean(char *s)
+{
+ const char * const *p;
+ for(p=conf_yes; *p; p++) {
+ if (!strcasecmp(*p,s))
+ return 1;
+ }
+ for(p=conf_no; *p; p++) {
+ if (!strcasecmp(*p,s))
+ return 0;
+ }
+ /* Default to "no" */
+ return 0;
+}
+
+static krb5_error_code appdefault_get(krb5_context context, const char *appname, const krb5_data *realm, const char *option, char **ret_value)
+{
+ profile_t profile;
+ const char *names[5];
+ char **nameval = NULL;
+ krb5_error_code retval;
+ const char * realmstr = realm?realm->data:NULL;
+
+ /*
+ * rra-c-util: The magic values are internal, so a magic check for the
+ * context struct was removed here. Call krb5_get_profile if it's
+ * available since the krb5_context struct may be opaque.
+ */
+ if (!context)
+ return KV5M_CONTEXT;
+
+#ifdef HAVE_KRB5_GET_PROFILE
+ krb5_get_profile(context, &profile);
+#else
+ profile = context->profile;
+#endif
+
+ /*
+ * Try number one:
+ *
+ * [appdefaults]
+ * app = {
+ * SOME.REALM = {
+ * option = <boolean>
+ * }
+ * }
+ */
+
+ names[0] = "appdefaults";
+ names[1] = appname;
+
+ if (realmstr) {
+ names[2] = realmstr;
+ names[3] = option;
+ names[4] = 0;
+ retval = profile_get_values(profile, names, &nameval);
+ if (retval == 0 && nameval && nameval[0]) {
+ *ret_value = strdup(nameval[0]);
+ goto goodbye;
+ }
+ }
+
+ /*
+ * Try number two:
+ *
+ * [appdefaults]
+ * app = {
+ * option = <boolean>
+ * }
+ */
+
+ names[2] = option;
+ names[3] = 0;
+ retval = profile_get_values(profile, names, &nameval);
+ if (retval == 0 && nameval && nameval[0]) {
+ *ret_value = strdup(nameval[0]);
+ goto goodbye;
+ }
+
+ /*
+ * Try number three:
+ *
+ * [appdefaults]
+ * realm = {
+ * option = <boolean>
+ */
+
+ if (realmstr) {
+ names[1] = realmstr;
+ names[2] = option;
+ names[3] = 0;
+ retval = profile_get_values(profile, names, &nameval);
+ if (retval == 0 && nameval && nameval[0]) {
+ *ret_value = strdup(nameval[0]);
+ goto goodbye;
+ }
+ }
+
+ /*
+ * Try number four:
+ *
+ * [appdefaults]
+ * option = <boolean>
+ */
+
+ names[1] = option;
+ names[2] = 0;
+ retval = profile_get_values(profile, names, &nameval);
+ if (retval == 0 && nameval && nameval[0]) {
+ *ret_value = strdup(nameval[0]);
+ } else {
+ return retval;
+ }
+
+goodbye:
+ if (nameval) {
+ char **cpp;
+ for (cpp = nameval; *cpp; cpp++)
+ free(*cpp);
+ free(nameval);
+ }
+ return 0;
+}
+
+void KRB5_CALLCONV
+krb5_appdefault_boolean(krb5_context context, const char *appname, const krb5_data *realm, const char *option, int default_value, int *ret_value)
+{
+ char *string = NULL;
+ krb5_error_code retval;
+
+ retval = appdefault_get(context, appname, realm, option, &string);
+
+ if (! retval && string) {
+ *ret_value = conf_boolean(string);
+ free(string);
+ } else
+ *ret_value = default_value;
+}
+
+void KRB5_CALLCONV
+krb5_appdefault_string(krb5_context context, const char *appname, const krb5_data *realm, const char *option, const char *default_value, char **ret_value)
+{
+ krb5_error_code retval;
+ char *string;
+
+ retval = appdefault_get(context, appname, realm, option, &string);
+
+ if (! retval && string) {
+ *ret_value = string;
+ } else {
+ *ret_value = strdup(default_value);
+ }
+}
+
+/*
+ * Copyright (C) 1985-2005 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original MIT software.
+ * M.I.T. makes no representations about the suitability of this software
+ * for any purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Individual source code files are copyright MIT, Cygnus Support,
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
+ *
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology
+ * (MIT). No commercial use of these trademarks may be made without
+ * prior written permission of MIT.
+ *
+ * "Commercial use" means use of a name in a product or other for-profit
+ * manner. It does NOT prevent a commercial firm from referring to the
+ * MIT trademarks in order to convey information (although in doing so,
+ * recognition of their trademark status should be given).
+ *
+ * There is no SPDX-License-Identifier registered for this license.
+ */
diff --git a/portable/krb5.h b/portable/krb5.h
index 34f960e..d8884a7 100644
--- a/portable/krb5.h
+++ b/portable/krb5.h
@@ -17,17 +17,19 @@
* krb5_free_unparsed_name() for both APIs since it's the most specific call.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015, 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2010-2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#ifndef PORTABLE_KRB5_H
@@ -57,6 +59,27 @@ BEGIN_DECLS
#pragma GCC visibility push(hidden)
/*
+ * AIX included Kerberos includes the profile library but not the
+ * krb5_appdefault functions, so we provide replacements that we have to
+ * prototype.
+ */
+#ifndef HAVE_KRB5_APPDEFAULT_STRING
+void krb5_appdefault_boolean(krb5_context, const char *, const krb5_data *,
+ const char *, int, int *);
+void krb5_appdefault_string(krb5_context, const char *, const krb5_data *,
+ const char *, const char *, char **);
+#endif
+
+/*
+ * MIT-specific. The Heimdal documentation says to use free(), but that
+ * doesn't actually make sense since the memory is allocated inside the
+ * Kerberos library. Use krb5_xfree instead.
+ */
+#ifndef HAVE_KRB5_FREE_DEFAULT_REALM
+# define krb5_free_default_realm(c, r) krb5_xfree(r)
+#endif
+
+/*
* krb5_{get,free}_error_message are the preferred APIs for both current MIT
* and current Heimdal, but there are tons of older APIs we may have to fall
* back on for earlier versions.
diff --git a/portable/macros.h b/portable/macros.h
index d4cc2cc..586b07e 100644
--- a/portable/macros.h
+++ b/portable/macros.h
@@ -2,17 +2,19 @@
* Portability macros used in include files.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2011-2012
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#ifndef PORTABLE_MACROS_H
diff --git a/portable/mkstemp.c b/portable/mkstemp.c
index 7c733a4..9e3bba1 100644
--- a/portable/mkstemp.c
+++ b/portable/mkstemp.c
@@ -5,17 +5,18 @@
* systems that don't have it.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009, 2011, 2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
diff --git a/portable/reallocarray.c b/portable/reallocarray.c
index e9404e9..3c6ea37 100644
--- a/portable/reallocarray.c
+++ b/portable/reallocarray.c
@@ -7,17 +7,19 @@
* and checks for overflow so that the caller doesn't need to.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
@@ -52,5 +54,11 @@ reallocarray(void *ptr, size_t nmemb, size_t size)
errno = ENOMEM;
return NULL;
}
+
+ /* Avoid a zero-size allocation. */
+ if (nmemb == 0 || size == 0) {
+ nmemb = 1;
+ size = 1;
+ }
return realloc(ptr, nmemb * size);
}
diff --git a/portable/setenv.c b/portable/setenv.c
index f1f6db4..afa8930 100644
--- a/portable/setenv.c
+++ b/portable/setenv.c
@@ -5,17 +5,19 @@
* those platforms that don't have it.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2000, 2014 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2011-2012, 2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
diff --git a/portable/snprintf.c b/portable/snprintf.c
index 9818acd..a42ef3b 100644
--- a/portable/snprintf.c
+++ b/portable/snprintf.c
@@ -11,7 +11,7 @@
* improvements should be sent back to the original author.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*/
/*
@@ -25,11 +25,18 @@
# define vsnprintf test_vsnprintf
#endif
+/* Specific to rra-c-util, but only when debugging is enabled. */
+#ifdef DEBUG_SNPRINTF
+# include <util/messages.h>
+#endif
+
/*
* Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell (papowell@astart.com)
* It may be used for any purpose as long as this notice remains intact
* on all source code distributions
+ *
+ * There is no SPDX-License-Identifier registered for this license.
*/
/**************************************************************
@@ -79,11 +86,24 @@
* Russ Allbery <eagle@eyrie.org> 2000-08-26
* fixed return value to comply with C99
* fixed handling of snprintf(NULL, ...)
+ * added explicit casts for double to long long int conversion
+ * fixed various warnings with GCC 7
+ * fixed various warnings with Clang
*
- * Hrvoje Niksic <hniksic@arsdigita.com> 2000-11-04
+ * Hrvoje Niksic <hniksic@xemacs.org> 2000-11-04
+ * include <config.h> instead of "config.h".
+ * moved TEST_SNPRINTF stuff out of HAVE_SNPRINTF ifdef.
* include <stdio.h> for NULL.
- * added support for long long.
+ * added support and test cases for long long.
* don't declare argument types to (v)snprintf if stdarg is not used.
+ * use int instead of short int as 2nd arg to va_arg.
+ *
+ * alexk (INN) 2002-08-21
+ * use LLONG in fmtfp to handle more characters during floating
+ * point conversion.
+ *
+ * herb (Samba) 2002-12-19
+ * actually print args for %g and %e
*
* Hrvoje Niksic <hniksic@xemacs.org> 2005-04-15
* use the PARAMS macro to handle prototypes.
@@ -109,11 +129,6 @@
/* varargs declarations: */
#include <stdarg.h>
-#define HAVE_STDARGS /* let's hope that works everywhere (mj) */
-#define VA_LOCAL_DECL va_list ap
-#define VA_START(f) va_start(ap, f)
-#define VA_SHIFT(v,t) ; /* no-op for ANSI */
-#define VA_END va_end(ap)
/* Assume all compilers support long double, per Autoconf documentation. */
#define LDOUBLE long double
@@ -180,7 +195,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
char *strvalue;
int min;
int max;
- int state;
+ unsigned int state;
int flags;
int cflags;
int total;
@@ -351,6 +366,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
break;
case 'X':
flags |= DP_F_UP;
+ /* fallthrough */
case 'x':
flags |= DP_F_UNSIGNED;
if (cflags == DP_C_SHORT)
@@ -367,33 +383,36 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
else
- fvalue = va_arg (args, double);
+ fvalue = (LDOUBLE) va_arg (args, double);
total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
break;
case 'E':
flags |= DP_F_UP;
+ /* fallthrough */
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
else
- fvalue = va_arg (args, double);
+ fvalue = (LDOUBLE) va_arg (args, double);
total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
break;
case 'G':
flags |= DP_F_UP;
+ /* fallthrough */
case 'g':
flags |= DP_F_FP_G;
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
else
- fvalue = va_arg (args, double);
+ fvalue = (LDOUBLE) va_arg (args, double);
if (max == 0)
/* C99 says: if precision [for %g] is zero, it is taken as one */
max = 1;
total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
break;
case 'c':
- total += dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
+ total += dopr_outch (buffer, &currlen, maxlen,
+ (char) va_arg (args, int));
break;
case 's':
strvalue = va_arg (args, char *);
@@ -409,7 +428,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
{
short int *num;
num = va_arg (args, short int *);
- *num = currlen;
+ *num = (short) currlen;
}
else if (cflags == DP_C_LONG)
{
@@ -427,7 +446,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
{
int *num;
num = va_arg (args, int *);
- *num = currlen;
+ *num = (int) currlen;
}
break;
case '%':
@@ -476,7 +495,7 @@ static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
}
if (max < 0)
- strln = strlen (value);
+ strln = (int) strlen (value);
else
/* When precision is specified, don't read VALUE past precision. */
/*strln = strnlen (value, max);*/
@@ -510,7 +529,7 @@ static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
LLONG value, int base, int min, int max, int flags)
{
- int signvalue = 0;
+ char signvalue = 0;
unsigned LLONG uvalue;
char convert[24];
unsigned int place = 0;
@@ -564,8 +583,8 @@ static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
spadlen = -spadlen; /* Left Justifty */
#ifdef DEBUG_SNPRINTF
- dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
- zpadlen, spadlen, min, max, place));
+ debug ("zpad: %d, spad: %d, min: %d, max: %d, place: %u\n",
+ zpadlen, spadlen, min, max, place);
#endif
/* Spaces */
@@ -612,7 +631,7 @@ static LDOUBLE abs_val (LDOUBLE value)
return result;
}
-static LDOUBLE pow10_int (int exp)
+static LLONG pow10_int (unsigned int exp)
{
LDOUBLE result = 1;
@@ -622,32 +641,40 @@ static LDOUBLE pow10_int (int exp)
exp--;
}
- return result;
+ return (LLONG) result;
}
static LLONG round_int (LDOUBLE value)
{
LLONG intpart;
- intpart = value;
+ intpart = (LLONG) value;
value = value - intpart;
- if (value >= 0.5)
+ if (value >= (LDOUBLE) 0.5)
intpart++;
return intpart;
}
+/*
+ * GCC 7.1 issues this warning at the point of the function definition header
+ * (not in any actual code), and I can't figure out what's triggering it since
+ * the comparison form doesn't appear anywhere in this code. Since this is
+ * rarely-used portability code, suppress the warning.
+ */
+#pragma GCC diagnostic ignored "-Wstrict-overflow"
+
static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags)
{
- int signvalue = 0;
+ char signvalue = 0;
LDOUBLE ufvalue;
char iconvert[24];
char fconvert[24];
size_t iplace = 0;
size_t fplace = 0;
- int padlen = 0; /* amount to pad */
- int zpadlen = 0;
+ long padlen = 0; /* amount to pad */
+ long zpadlen = 0;
int total = 0;
LLONG intpart;
LLONG fracpart;
@@ -678,7 +705,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
#endif
- intpart = ufvalue;
+ intpart = (LLONG) ufvalue;
/* With %g precision is the number of significant digits, which
includes the digits in intpart. */
@@ -699,7 +726,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
fractional digit. */
LDOUBLE temp;
if (ufvalue > 0)
- for (temp = ufvalue; temp < 0.1; temp *= 10)
+ for (temp = ufvalue; temp < (LDOUBLE) 0.1; temp *= 10)
++max;
}
}
@@ -746,12 +773,16 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
}
#ifdef DEBUG_SNPRINTF
- dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart));
+# ifdef HAVE_LONG_LONG_INT
+ debug ("fmtfp: %Lf =? %lld.%lld\n", fvalue, intpart, fracpart);
+# else
+ debug ("fmtfp: %Lf =? %ld.%ld\n", fvalue, intpart, fracpart);
+# endif
#endif
/* Convert integer part */
do {
- iconvert[iplace++] = '0' + intpart % 10;
+ iconvert[iplace++] = (char) ('0' + (intpart % 10));
intpart = (intpart / 10);
} while(intpart && (iplace < sizeof(iconvert)));
if (iplace == sizeof(iconvert)) iplace--;
@@ -759,7 +790,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
/* Convert fractional part */
do {
- fconvert[fplace++] = '0' + fracpart % 10;
+ fconvert[fplace++] = (char) ('0' + (fracpart % 10));
fracpart = (fracpart / 10);
} while(fracpart && (fplace < sizeof(fconvert)));
while (leadingfrac0s-- > 0 && fplace < sizeof(fconvert))
@@ -847,27 +878,14 @@ int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
return dopr(str, count, fmt, args);
}
-/* VARARGS3 */
-#ifdef HAVE_STDARGS
-int snprintf (char *str,size_t count,const char *fmt,...)
-#else
-int snprintf (va_alist) va_dcl
-#endif
+int snprintf (char *str, size_t count, const char *fmt,...)
{
-#ifndef HAVE_STDARGS
- char *str;
- size_t count;
- char *fmt;
-#endif
- VA_LOCAL_DECL;
+ va_list ap;
int total;
- VA_START (fmt);
- VA_SHIFT (str, char *);
- VA_SHIFT (count, size_t );
- VA_SHIFT (fmt, char *);
+ va_start(ap, fmt);
total = vsnprintf(str, count, fmt, ap);
- VA_END;
+ va_end(ap);
return total;
}
@@ -944,5 +962,6 @@ int main (void)
num++;
}
printf ("%d tests failed out of %d.\n", fail, num);
+ return 0;
}
-#endif /* SNPRINTF_TEST */
+#endif /* TEST_SNPRINTF */
diff --git a/portable/stdbool.h b/portable/stdbool.h
index 14d011b..3efe4c9 100644
--- a/portable/stdbool.h
+++ b/portable/stdbool.h
@@ -6,17 +6,18 @@
* logic is based heavily on the example in the Autoconf manual.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2011
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#ifndef PORTABLE_STDBOOL_H
diff --git a/portable/system.h b/portable/system.h
index 581e46c..6fe4928 100644
--- a/portable/system.h
+++ b/portable/system.h
@@ -22,17 +22,19 @@
* the portable helper library. Also provides some standard #defines.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014, 2016, 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006-2011, 2013-2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#ifndef PORTABLE_SYSTEM_H
@@ -73,6 +75,11 @@
/* Get the bool type. */
#include <portable/stdbool.h>
+/* In case uint32_t and associated limits weren't defined. */
+#ifndef UINT32_MAX
+# define UINT32_MAX 4294967295UL
+#endif
+
/* Windows provides snprintf under a different name. */
#ifdef _WIN32
# define snprintf _snprintf
@@ -118,14 +125,16 @@ BEGIN_DECLS
#if !HAVE_ASPRINTF
extern int asprintf(char **, const char *, ...)
__attribute__((__format__(printf, 2, 3)));
-extern int vasprintf(char **, const char *, va_list);
+extern int vasprintf(char **, const char *, va_list)
+ __attribute__((__format__(printf, 2, 0)));
#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);
+extern int vsnprintf(char *, size_t, const char *, va_list)
+ __attribute__((__format__(printf, 3, 0)));
#endif
#if !HAVE_MKSTEMP
extern int mkstemp(char *);
@@ -136,12 +145,6 @@ extern void *reallocarray(void *, size_t, size_t);
#if !HAVE_SETENV
extern int setenv(const char *, const char *, int);
#endif
-#if !HAVE_DECL_STRLCAT
-extern size_t strlcat(char *, const char *, size_t);
-#endif
-#if !HAVE_DECL_STRLCPY
-extern size_t strlcpy(char *, const char *, size_t);
-#endif
/* Undo default visibility change. */
#pragma GCC visibility pop
diff --git a/portable/uio.h b/portable/uio.h
index 2192f8c..8635d18 100644
--- a/portable/uio.h
+++ b/portable/uio.h
@@ -6,17 +6,18 @@
* functions are not provided or prototyped here.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2011
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#ifndef PORTABLE_UIO_H