From: Ken Raeburn Date: Wed, 19 Apr 2006 20:23:46 +0000 (+0000) Subject: * errors.c (krb5int_get_error): Try strerror_r if available before strerror. X-Git-Tag: krb5-1.5-alpha1~68 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d29518ffa3a2100c7c7296ac1afdc7b1202035f1;p=krb5.git * errors.c (krb5int_get_error): Try strerror_r if available before strerror. * plugins.c (ERRSTR): New macro, tries strerror_r and uses strerror only if it fails or isn't available. (krb5int_open_plugin_dir): Use it. ticket: 3620 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17944 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/support/errors.c b/src/util/support/errors.c index 185cb425a..17f412726 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -81,6 +81,23 @@ krb5int_get_error (struct errinfo *ep, long code) lock(); if (fptr == NULL) { unlock(); +#ifdef HAVE_STRERROR_R + if (strerror_r (code, ep->scratch_buf, sizeof(ep->scratch_buf)) == 0) + return ep->scratch_buf; + /* If strerror_r didn't work with the 1K buffer, we can try a + really big one. This seems kind of gratuitous though. */ +#define BIG_ERR_BUFSIZ 8192 + r = malloc(BIG_ERR_BUFSIZ); + if (r) { + if (strerror_r (code, r, BIG_ERR_BUFSIZ) == 0) { + r2 = realloc (r, 1 + strlen(r)); + if (r2) + return r2; + return r; + } + free (r); + } +#endif r = strerror (code); if (r) { if (strlen (r) < sizeof (ep->scratch_buf) diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c index c245a70db..424ec70b3 100644 --- a/src/util/support/plugins.c +++ b/src/util/support/plugins.c @@ -166,6 +166,15 @@ 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 + int32_t KRB5_CALLCONV krb5int_open_plugin_dir (const char *dirname, struct plugin_dir_handle *dirhandle) @@ -181,6 +190,7 @@ krb5int_open_plugin_dir (const char *dirname, int nh; int error = 0; char path[MAXPATHLEN]; + char errbuf[1024]; h = NULL; nh = 0; @@ -188,7 +198,7 @@ krb5int_open_plugin_dir (const char *dirname, dir = opendir(dirname); if (dir == NULL) { error = errno; - Tprintf("-> error %d/%s\n", error, strerror(error)); + Tprintf("-> error %d/%s\n", error, ERRSTR(error, errbuf)); if (error == ENOENT) return 0; return error; @@ -207,7 +217,7 @@ krb5int_open_plugin_dir (const char *dirname, /* Optimization: Linux includes a file type field in the directory structure. */ if (stat(path, &statbuf) < 0) { - Tprintf("stat(%s): %s\n", path, strerror(errno)); + Tprintf("stat(%s): %s\n", path, ERRSTR(errno, errbuf)); continue; } if ((statbuf.st_mode & S_IFMT) != S_IFREG) {