krb5 commit: Simplify usage of strerror_r
Greg Hudson
ghudson at MIT.EDU
Tue Jul 8 20:17:05 EDT 2014
https://github.com/krb5/krb5/commit/6a8da91b691b8f51ac62d8142cd2fa32a69f3d15
commit 6a8da91b691b8f51ac62d8142cd2fa32a69f3d15
Author: Greg Hudson <ghudson at mit.edu>
Date: Sat Jul 5 10:23:11 2014 -0400
Simplify usage of strerror_r
Take advantage of the strerror_r portability wrapper to simplify code
using it. Remove unused macros related to strerror_r in
ldap_service_stash.c and plugins.c.
ticket: 7961
src/lib/krb5/os/trace.c | 9 ++-------
.../kdb/ldap/libkdb_ldap/ldap_service_stash.c | 5 -----
src/util/et/error_message.c | 19 ++-----------------
src/util/support/errors.c | 2 --
src/util/support/plugins.c | 9 ---------
5 files changed, 4 insertions(+), 40 deletions(-)
diff --git a/src/lib/krb5/os/trace.c b/src/lib/krb5/os/trace.c
index 105a2cd..5fbe573 100644
--- a/src/lib/krb5/os/trace.c
+++ b/src/lib/krb5/os/trace.c
@@ -229,14 +229,9 @@ trace_format(krb5_context context, const char *fmt, va_list ap)
subfmt(context, &buf, "{hexlenstr}", d->length, d->data);
} else if (strcmp(tmpbuf, "errno") == 0) {
err = va_arg(ap, int);
- p = NULL;
-#ifdef HAVE_STRERROR_R
+ k5_buf_add_fmt(&buf, "%d", err);
if (strerror_r(err, tmpbuf, sizeof(tmpbuf)) == 0)
- p = tmpbuf;
-#endif
- if (p == NULL)
- p = strerror(err);
- k5_buf_add_fmt(&buf, "%d/%s", err, p);
+ k5_buf_add_fmt(&buf, "/%s", tmpbuf);
} else if (strcmp(tmpbuf, "kerr") == 0) {
kerr = va_arg(ap, krb5_error_code);
p = krb5_get_error_message(context, kerr);
diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_service_stash.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_service_stash.c
index 36e6d59..fc00049 100644
--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_service_stash.c
+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_service_stash.c
@@ -90,11 +90,6 @@ krb5_ldap_readpassword(krb5_context context, krb5_ldap_context *ldap_context,
if (ldap_context->service_password_file)
file = ldap_context->service_password_file;
-#ifndef HAVE_STRERROR_R
-# undef strerror_r
-# define strerror_r(ERRNUM, BUF, SIZE) (strncpy(BUF, strerror(ERRNUM), SIZE), BUF[(SIZE)-1] = 0)
-#endif
-
fptr = fopen(file, "r");
if (fptr == NULL) {
st = errno;
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index fb72396..c4fa569 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -30,11 +30,6 @@
#include "error_table.h"
#include "k5-platform.h"
-#if !defined(HAVE_STRERROR) && !defined(SYS_ERRLIST_DECLARED)
-extern char const * const sys_errlist[];
-extern const int sys_nerr;
-#endif
-
static struct et_list *et_list;
static k5_mutex_t et_list_lock = K5_MUTEX_PARTIAL_INITIALIZER;
static int terminated = 0; /* for debugging shlib fini sequence errors */
@@ -142,20 +137,10 @@ error_message(long code)
/* This could trip if int is 16 bits. */
if ((unsigned long)(int)code != (unsigned long)code)
abort ();
-#ifdef HAVE_STRERROR_R
cp = get_thread_buffer();
- if (cp && strerror_r((int) code, cp, ET_EBUFSIZ) == 0)
+ if (cp && strerror_r(code, cp, ET_EBUFSIZ) == 0)
return cp;
-#endif
-#ifdef HAVE_STRERROR
- cp = strerror((int) code);
- if (cp)
- return cp;
-#elif defined HAVE_SYS_ERRLIST
- if (offset < sys_nerr)
- return(sys_errlist[offset]);
-#endif
- goto oops;
+ return strerror(code);
}
k5_mutex_lock(&et_list_lock);
diff --git a/src/util/support/errors.c b/src/util/support/errors.c
index 74093a5..4b1cfa0 100644
--- a/src/util/support/errors.c
+++ b/src/util/support/errors.c
@@ -84,10 +84,8 @@ k5_get_error(struct errinfo *ep, long code)
lock();
if (fptr == NULL) {
unlock();
-#ifdef HAVE_STRERROR_R
if (strerror_r(code, buf, sizeof(buf)) == 0)
return oom_check(strdup(buf));
-#endif
return oom_check(strdup(strerror(code)));
}
r = fptr(code);
diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c
index ca4b128..82ef97e 100644
--- a/src/util/support/plugins.c
+++ b/src/util/support/plugins.c
@@ -446,15 +446,6 @@ krb5int_close_plugin (struct plugin_file_handle *h)
#endif
#endif
-
-#ifdef HAVE_STRERROR_R
-#define ERRSTR(ERR, BUF) \
- (strerror_r (ERR, BUF, sizeof(BUF)) == 0 ? BUF : strerror (ERR))
-#else
-#define ERRSTR(ERR, BUF) \
- (strerror (ERR))
-#endif
-
static long
krb5int_plugin_file_handle_array_init (struct plugin_file_handle ***harray)
{
More information about the cvs-krb5
mailing list