* error_table.h (ET_EBUFSIZ): Increase to 1k.
authorKen Raeburn <raeburn@mit.edu>
Tue, 18 Apr 2006 23:28:07 +0000 (23:28 +0000)
committerKen Raeburn <raeburn@mit.edu>
Tue, 18 Apr 2006 23:28:07 +0000 (23:28 +0000)
* error_message.c (get_thread_buffer): New function, split out from
error_message.
(error_message): Call it.  Also try strerror_r with the per-thread buffer, if
both are available, before trying strerror.

ticket: 3620
status: open

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17942 dc483132-0cff-0310-8789-dd5450dbe970

src/util/et/error_message.c
src/util/et/error_table.h

index b7f8947d2926e4add0c4be53841e76e7ae3f9069..62be6a6e7fc6263018007eee95847d4e06520e49 100644 (file)
@@ -91,6 +91,24 @@ void com_err_terminate(void)
 #define dprintf(X) printf X
 #endif
 
+static char *
+get_thread_buffer ()
+{
+    char *cp;
+    cp = k5_getspecific(K5_KEY_COM_ERR);
+    if (cp == NULL) {
+       cp = malloc(ET_EBUFSIZ);
+       if (cp == NULL) {
+           return NULL;
+       }
+       if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
+           free(cp);
+           return NULL;
+       }
+    }
+    return cp;
+}
+
 const char * KRB5_CALLCONV
 error_message(long code)
     /*@modifies internalState@*/
@@ -109,39 +127,36 @@ error_message(long code)
        l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
        offset = l_offset;
        table_num = ((unsigned long)code - l_offset) & ERRCODE_MAX;
-       if (table_num == 0) {
+       if (table_num == 0
 #ifdef __sgi
-       system_error_code:
+           /* Irix 6.5 uses a much bigger table than other UNIX
+              systems I've looked at, but the table is sparse.  The
+              sparse entries start around 500, but sys_nerr is only
+              152.  */
+           || (code > 0 && code <= 1600)
 #endif
+           ) {
                if (code == 0)
                        goto oops;
 
                /* This could trip if int is 16 bits.  */
                if ((unsigned long)(int)code != code)
                    abort ();
+#ifdef HAVE_STRERROR_R
+               cp = get_thread_buffer();
+               if (cp && strerror_r((int) code, cp, ET_EBUFSIZ) == 0)
+                   return cp;
+#endif
 #ifdef HAVE_STRERROR
                cp = strerror((int) code);
                if (cp)
                        return cp;
-               goto oops;
-#else
-#ifdef HAVE_SYS_ERRLIST
+#elif defined HAVE_SYS_ERRLIST
                if (offset < sys_nerr)
                        return(sys_errlist[offset]);
-               else
-                       goto oops;
-#else
+#endif
                goto oops;
-#endif /* HAVE_SYS_ERRLIST */
-#endif /* HAVE_STRERROR */
        }
-#ifdef __sgi
-       /* Irix 6.5 uses a much bigger table than other UNIX systems
-          I've looked at, but the table is sparse.  The sparse
-          entries start around 500, but sys_nerr is only 152.  */
-       if (code > 0 && code <= 1600)
-           goto system_error_code;
-#endif
 
        if (CALL_INIT_FUNCTION(com_err_initialize))
            return 0;
@@ -221,18 +236,9 @@ error_message(long code)
                        goto oops;
                } else {
                        char *buffer;
-                       cp = k5_getspecific(K5_KEY_COM_ERR);
-                       if (cp == NULL) {
-                           cp = malloc(ET_EBUFSIZ);
-                           if (cp == NULL) {
-                           win32_no_specific:
-                               return "Unknown error code";
-                           }
-                           if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
-                               free(cp);
-                               goto win32_no_specific;
-                           }
-                       }
+                       cp = get_thread_buffer();
+                       if (cp == NULL)
+                           return "Unknown error code";
                        buffer = cp;
                        strncpy(buffer, msgbuf, ET_EBUFSIZ);
                        buffer[ET_EBUFSIZ-1] = '\0';
@@ -257,18 +263,9 @@ oops:
        }
 #endif
 
-       cp = k5_getspecific(K5_KEY_COM_ERR);
-       if (cp == NULL) {
-           cp = malloc(ET_EBUFSIZ);
-           if (cp == NULL) {
-           no_specific:
-               return "Unknown error code";
-           }
-           if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
-               free(cp);
-               goto no_specific;
-           }
-       }
+       cp = get_thread_buffer();
+       if (cp == NULL)
+           return "Unknown error code";
        cp1 = cp;
        strcpy(cp, "Unknown code ");
        cp += sizeof("Unknown code ") - 1;
index ea804cf00592ef6bc7eb961e2006e9d3a6306e04..b58502a5888106cf67f925f3976ae6c796858448 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <errno.h>
 
-#define ET_EBUFSIZ 64
+#define ET_EBUFSIZ 1024
 
 struct et_list {
     /*@dependent@*//*@null@*/ struct et_list *next;