]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Simplify usage of strerror_r
authorGreg Hudson <ghudson@mit.edu>
Sat, 5 Jul 2014 14:23:11 +0000 (10:23 -0400)
committerGreg Hudson <ghudson@mit.edu>
Tue, 8 Jul 2014 23:19:24 +0000 (19:19 -0400)
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
src/plugins/kdb/ldap/libkdb_ldap/ldap_service_stash.c
src/util/et/error_message.c
src/util/support/errors.c
src/util/support/plugins.c

index 105a2cdb7f4d23e0cae11e4d0ff0288e92766fc0..5fbe573a117b25409dc102c75a247bb7c992e070 100644 (file)
@@ -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);
index 36e6d597eb95a24a6b205eaf39c836cd0e92530d..fc000497a30f4ab60ed6d43c89df1c2bf7332e8d 100644 (file)
@@ -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;
index fb72396ce2dee575c70c32af3071e9c047d38db2..c4fa5693b129f71ca111d10efac83cff38c0736d 100644 (file)
 #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);
index 74093a56aa5d654f3ea4c6f20360c6790511381b..4b1cfa0622f25b218ddb96d8744466682a3e9c7f 100644 (file)
@@ -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);
index ca4b1285821414aaa4a8c688eae52a10bcaab447..82ef97e57c76decd0f3be4fc2c1ea7a3b3bd83cd 100644 (file)
@@ -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)
 {