summaryrefslogtreecommitdiff
path: root/portable
diff options
context:
space:
mode:
Diffstat (limited to 'portable')
-rw-r--r--portable/asprintf.c6
-rw-r--r--portable/krb5-extra.c3
-rw-r--r--portable/krb5.h4
-rw-r--r--portable/macros.h3
-rw-r--r--portable/mkstemp.c5
-rw-r--r--portable/reallocarray.c8
-rw-r--r--portable/setenv.c24
-rw-r--r--portable/snprintf.c2
-rw-r--r--portable/strlcat.c51
-rw-r--r--portable/strlcpy.c49
-rw-r--r--portable/system.h4
11 files changed, 34 insertions, 125 deletions
diff --git a/portable/asprintf.c b/portable/asprintf.c
index eb2b713..9693842 100644
--- a/portable/asprintf.c
+++ b/portable/asprintf.c
@@ -19,6 +19,7 @@
*/
#include <config.h>
+#include <portable/macros.h>
#include <portable/system.h>
#include <errno.h>
@@ -28,11 +29,14 @@
* with the system versions.
*/
#if TESTING
+# undef asprintf
+# undef vasprintf
# define asprintf test_asprintf
# define vasprintf test_vasprintf
int test_asprintf(char **, const char *, ...)
__attribute__((__format__(printf, 2, 3)));
-int test_vasprintf(char **, const char *, va_list);
+int test_vasprintf(char **, const char *, va_list)
+ __attribute__((__format__(printf, 2, 0)));
#endif
diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c
index b1c8b8d..c8309a4 100644
--- a/portable/krb5-extra.c
+++ b/portable/krb5-extra.c
@@ -22,6 +22,7 @@
#include <config.h>
#include <portable/krb5.h>
+#include <portable/macros.h>
#include <portable/system.h>
#include <errno.h>
@@ -33,6 +34,8 @@
# include <ibm_svc/krb5_svc.h>
# elif defined(HAVE_ET_COM_ERR_H)
# include <et/com_err.h>
+# elif defined(HAVE_KERBEROSV5_COM_ERR_H)
+# include <kerberosv5/com_err.h>
# else
# include <com_err.h>
# endif
diff --git a/portable/krb5.h b/portable/krb5.h
index 6dfffd5..34f960e 100644
--- a/portable/krb5.h
+++ b/portable/krb5.h
@@ -42,8 +42,10 @@
#endif
#include <portable/macros.h>
-#ifdef HAVE_KRB5_H
+#if defined(HAVE_KRB5_H)
# include <krb5.h>
+#elif defined(HAVE_KERBEROSV5_KRB5_H)
+# include <kerberosv5/krb5.h>
#else
# include <krb5/krb5.h>
#endif
diff --git a/portable/macros.h b/portable/macros.h
index b5093f5..d4cc2cc 100644
--- a/portable/macros.h
+++ b/portable/macros.h
@@ -37,7 +37,8 @@
* variadic macro support.
*/
#if !defined(__attribute__) && !defined(__alloc_size__)
-# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \
+ && !defined(__clang__)
# define __alloc_size__(spec, args...) /* empty */
# endif
#endif
diff --git a/portable/mkstemp.c b/portable/mkstemp.c
index 2cbfe08..7c733a4 100644
--- a/portable/mkstemp.c
+++ b/portable/mkstemp.c
@@ -23,7 +23,10 @@
#include <errno.h>
#include <fcntl.h>
-#include <sys/time.h>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <time.h>
/*
* If we're running the test suite, rename mkstemp to avoid conflicts with the
diff --git a/portable/reallocarray.c b/portable/reallocarray.c
index 7d40a7a..e9404e9 100644
--- a/portable/reallocarray.c
+++ b/portable/reallocarray.c
@@ -1,10 +1,10 @@
/*
* Replacement for a missing reallocarray.
*
- * Provides the same functionality as the OpenBSD library function reallocrray
- * for those systems that don't have it. This function is the same as
- * realloc, but takes the size arguments in the same form as calloc and checks
- * for overflow so that the caller doesn't need to.
+ * Provides the same functionality as the OpenBSD library function
+ * reallocarray for those systems that don't have it. This function is the
+ * same as realloc, but takes the size arguments in the same form as calloc
+ * 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/>.
diff --git a/portable/setenv.c b/portable/setenv.c
index 472282a..f1f6db4 100644
--- a/portable/setenv.c
+++ b/portable/setenv.c
@@ -26,6 +26,7 @@
* the system version.
*/
#if TESTING
+# undef setenv
# define setenv test_setenv
int test_setenv(const char *, const char *, int);
#endif
@@ -34,29 +35,22 @@ int
setenv(const char *name, const char *value, int overwrite)
{
char *envstring;
- size_t size;
+ /* Do nothing if not overwriting and the variable is already set. */
if (!overwrite && getenv(name) != NULL)
return 0;
/*
- * Allocate memory for the environment string. We intentionally don't use
- * the xmalloc family of allocation routines here, since the intention is
- * to provide a replacement for the standard library function that sets
- * errno and returns in the event of a memory allocation failure.
- */
- size = strlen(name) + 1 + strlen(value) + 1;
- envstring = malloc(size);
- if (envstring == NULL)
- return -1;
-
- /*
* Build the environment string and add it to the environment using
* putenv. Systems without putenv lose, but XPG4 requires it.
+ *
+ * We intentionally don't use the xmalloc family of allocation routines
+ * here, since the intention is to provide a replacement for the standard
+ * library function that sets errno and returns in the event of a memory
+ * allocation failure.
*/
- strlcpy(envstring, name, size);
- strlcat(envstring, "=", size);
- strlcat(envstring, value, size);
+ if (asprintf(&envstring, "%s=%s", name, value) < 0)
+ return -1;
return putenv(envstring);
/*
diff --git a/portable/snprintf.c b/portable/snprintf.c
index c35ad80..9818acd 100644
--- a/portable/snprintf.c
+++ b/portable/snprintf.c
@@ -19,6 +19,8 @@
* conflicts with the system version.
*/
#if TESTING
+# undef snprintf
+# undef vsnprintf
# define snprintf test_snprintf
# define vsnprintf test_vsnprintf
#endif
diff --git a/portable/strlcat.c b/portable/strlcat.c
deleted file mode 100644
index 9c8686d..0000000
--- a/portable/strlcat.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Replacement for a missing strlcat.
- *
- * Provides the same functionality as the *BSD function strlcat, originally
- * developed by Todd Miller and Theo de Raadt. strlcat works similarly to
- * strncat, except simpler. The result is always nul-terminated even if the
- * source string is longer than the space remaining in the destination string,
- * and the total space required is returned. The third argument is the total
- * space available in the destination buffer, not just the amount of space
- * remaining.
- *
- * 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/>.
- *
- * Written by Russ Allbery <eagle@eyrie.org>
- *
- * 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.
- */
-
-#include <config.h>
-#include <portable/system.h>
-
-/*
- * If we're running the test suite, rename strlcat to avoid conflicts with
- * the system version.
- */
-#if TESTING
-# define strlcat test_strlcat
-size_t test_strlcat(char *, const char *, size_t);
-#endif
-
-size_t
-strlcat(char *dst, const char *src, size_t size)
-{
- size_t used, length, copy;
-
- used = strlen(dst);
- length = strlen(src);
- if (size > 0 && used < size - 1) {
- copy = (length >= size - used) ? size - used - 1 : length;
- memcpy(dst + used, src, copy);
- dst[used + copy] = '\0';
- }
- return used + length;
-}
diff --git a/portable/strlcpy.c b/portable/strlcpy.c
deleted file mode 100644
index 592e3ee..0000000
--- a/portable/strlcpy.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Replacement for a missing strlcpy.
- *
- * Provides the same functionality as the *BSD function strlcpy, originally
- * developed by Todd Miller and Theo de Raadt. strlcpy works similarly to
- * strncpy, except saner and simpler. The result is always nul-terminated
- * even if the source string is longer than the destination string, and the
- * total space required is returned. The destination string is not nul-filled
- * like strncpy does, just nul-terminated.
- *
- * 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/>.
- *
- * Written by Russ Allbery <eagle@eyrie.org>
- *
- * 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.
- */
-
-#include <config.h>
-#include <portable/system.h>
-
-/*
- * If we're running the test suite, rename strlcpy to avoid conflicts with
- * the system version.
- */
-#if TESTING
-# define strlcpy test_strlcpy
-size_t test_strlcpy(char *, const char *, size_t);
-#endif
-
-size_t
-strlcpy(char *dst, const char *src, size_t size)
-{
- size_t length, copy;
-
- length = strlen(src);
- if (size > 0) {
- copy = (length >= size) ? size - 1 : length;
- memcpy(dst, src, copy);
- dst[copy] = '\0';
- }
- return length;
-}
diff --git a/portable/system.h b/portable/system.h
index 544b2de..581e46c 100644
--- a/portable/system.h
+++ b/portable/system.h
@@ -136,10 +136,10 @@ extern void *reallocarray(void *, size_t, size_t);
#if !HAVE_SETENV
extern int setenv(const char *, const char *, int);
#endif
-#if !HAVE_STRLCAT
+#if !HAVE_DECL_STRLCAT
extern size_t strlcat(char *, const char *, size_t);
#endif
-#if !HAVE_STRLCPY
+#if !HAVE_DECL_STRLCPY
extern size_t strlcpy(char *, const char *, size_t);
#endif