summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/support/Makefile.in5
-rw-r--r--src/util/support/libkrb5support-fixed.exports1
-rw-r--r--src/util/support/strerror_r.c96
3 files changed, 101 insertions, 1 deletions
diff --git a/src/util/support/Makefile.in b/src/util/support/Makefile.in
index 979b4cd3e..51817621b 100644
--- a/src/util/support/Makefile.in
+++ b/src/util/support/Makefile.in
@@ -72,6 +72,7 @@ STLIBOBJS= \
base64.o \
json.o \
bcmp.o \
+ strerror_r.o \
$(GETTIMEOFDAY_ST_OBJ) \
$(IPC_ST_OBJ) \
$(STRLCPY_ST_OBJ) \
@@ -94,6 +95,7 @@ LIBOBJS= \
$(OUTPRE)base64.$(OBJEXT) \
$(OUTPRE)json.$(OBJEXT) \
$(OUTPRE)bcmp.$(OBJEXT) \
+ $(OUTPRE)strerror_r.$(OBJEXT) \
$(GETTIMEOFDAY_OBJ) \
$(IPC_OBJ) \
$(STRLCPY_OBJ) \
@@ -124,7 +126,8 @@ SRCS=\
$(srcdir)/path.c \
$(srcdir)/base64.c \
$(srcdir)/json.c \
- $(srcdir)/bcmp.c
+ $(srcdir)/bcmp.c \
+ $(srcdir)/strerror_r.c
SHLIB_EXPDEPS =
# Add -lm if dumping thread stats, for sqrt.
diff --git a/src/util/support/libkrb5support-fixed.exports b/src/util/support/libkrb5support-fixed.exports
index 4a76eef88..b5ca0b28c 100644
--- a/src/util/support/libkrb5support-fixed.exports
+++ b/src/util/support/libkrb5support-fixed.exports
@@ -47,6 +47,7 @@ k5_json_string_utf8
k5_path_isabs
k5_path_join
k5_path_split
+k5_strerror_r
krb5int_key_register
krb5int_key_delete
krb5int_getspecific
diff --git a/src/util/support/strerror_r.c b/src/util/support/strerror_r.c
new file mode 100644
index 000000000..e1ca56510
--- /dev/null
+++ b/src/util/support/strerror_r.c
@@ -0,0 +1,96 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* util/support/strerror_r.c - strerror_r compatibility shim */
+/*
+ * Copyright (C) 2014 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <k5-platform.h>
+#undef strerror_r
+
+#if defined(_WIN32)
+
+/* Implement strerror_r in terms of strerror_s. */
+int
+k5_strerror_r(int errnum, char *buf, size_t buflen)
+{
+ int st;
+
+ st = strerror_s(buf, buflen, errnum);
+ if (st != 0) {
+ errno = st;
+ return -1;
+ }
+}
+
+#elif !defined(HAVE_STRERROR_R)
+
+/* Implement strerror_r in terms of strerror (not thread-safe). */
+int
+k5_strerror_r(int errnum, char *buf, size_t buflen)
+{
+ if (strlcpy(buf, strerror(errnum), buflen) >= buflen) {
+ errno = ERANGE;
+ return -1;
+ }
+ return 0;
+}
+
+#elif defined(STRERROR_R_CHAR_P)
+
+/*
+ * Implement the POSIX strerror_r API in terms of the GNU strerror_r, which
+ * returns a pointer to either the caller buffer or a constant string. This is
+ * the default version on glibc systems when _GNU_SOURCE is defined.
+ */
+int
+k5_strerror_r(int errnum, char *buf, size_t buflen)
+{
+ const char *str;
+
+ str = strerror_r(errnum, buf, buflen);
+ if (str != buf) {
+ if (strlcpy(buf, str, buflen) >= buflen) {
+ errno = ERANGE;
+ return -1;
+ }
+ }
+ return 0;
+}
+
+#else
+
+/* Define a stub in terms of the real strerror_r, just to simplify the library
+ * export list. This shouldn't get used. */
+int
+k5_strerror_r(int errnum, char *buf, size_t buflen)
+{
+ return strerror_r(errnum, buf, buflen);
+}
+
+#endif