From a6275627e47d73afe9eefa789e21d0697a052699 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 18 Jun 2004 22:47:27 +0000 Subject: [PATCH] * Makefile.in ($(OUTPRE)test_et.exe): New target. (check-windows): Build and run test_et.exe. * error_message.c: Include autoconf.h. (HAVE_STRERROR) [_WIN32]: Don't define. (error_message) [_WIN32]: Check for range WSABASEERR+[0,1100) instead of all values under 12000. Use k5_getspecific and k5_setspecific for local buffer. * test_et.c (EXPORT_LIST): Define on Windows. (main): Use add/remove_error_table, not the initialize_ routines. (main) [EXPORT_LIST]: Don't test error_table_name, it's not in the export list. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16481 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/et/ChangeLog | 16 ++++++++++++++++ src/util/et/Makefile.in | 9 +++++++++ src/util/et/error_message.c | 29 ++++++++++++++++++++--------- src/util/et/test_et.c | 20 ++++++++++++++++++-- 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/util/et/ChangeLog b/src/util/et/ChangeLog index 8b36dbef4..72c724676 100644 --- a/src/util/et/ChangeLog +++ b/src/util/et/ChangeLog @@ -1,3 +1,19 @@ +2004-06-18 Ken Raeburn + + * Makefile.in ($(OUTPRE)test_et.exe): New target. + (check-windows): Build and run test_et.exe. + + * error_message.c: Include autoconf.h. + (HAVE_STRERROR) [_WIN32]: Don't define. + (error_message) [_WIN32]: Check for range WSABASEERR+[0,1100) + instead of all values under 12000. Use k5_getspecific and + k5_setspecific for local buffer. + + * test_et.c (EXPORT_LIST): Define on Windows. + (main): Use add/remove_error_table, not the initialize_ routines. + (main) [EXPORT_LIST]: Don't test error_table_name, it's not in the + export list. + 2004-06-04 Ken Raeburn * Makefile.in (LIBBASE): Renamed from LIB. diff --git a/src/util/et/Makefile.in b/src/util/et/Makefile.in index e5d3dfd12..4bbe1ea34 100644 --- a/src/util/et/Makefile.in +++ b/src/util/et/Makefile.in @@ -136,6 +136,10 @@ test_et: test_et.o test1.o test2.o $(COM_ERR_DEPLIB) $(SUPPORT_DEPLIB) t_com_err: t_com_err.o et1.o et2.o $(COM_ERR_DEPLIB) $(SUPPORT_DEPLIB) $(CC_LINK) -o t_com_err t_com_err.o et1.o et2.o -lcom_err $(SUPPORT_LIB) +$(OUTPRE)test_et.exe: $(OUTPRE)test_et.$(OBJEXT) $(OUTPRE)test1.$(OBJEXT) \ + $(OUTPRE)test2.$(OBJEXT) $(CLIB) + link $(EXE_LINKOPTS) -out:$(OUTPRE)test_et$(EXEEXT) $** + all-unix:: compile_et includes includes:: com_err.h @@ -157,6 +161,11 @@ check-unix:: t_com_err test_et $(RUN_SETUP) ./test_et $(RUN_SETUP) ./t_com_err +check-windows:: $(OUTPRE)test_et$(EXEEXT) + set path=$(BUILDTOP)\lib\$(OUTPRE);%path%; + path + $(OUTPRE)test_et$(EXEEXT) + # The real compile_et just isn't portable. (But then again, anything using # lex and yacc isn't portable by definition. :-( ) # diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index 07c1fcd1d..03e8af1b2 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -19,6 +19,7 @@ * provided "as is" without express or implied warranty. */ +#include "autoconf.h" #include #ifdef HAVE_STDLIB_H #include @@ -28,10 +29,6 @@ #include "error_table.h" #include "k5-platform.h" -#if defined(_WIN32) -#define HAVE_STRERROR -#endif - #if !defined(HAVE_STRERROR) && !defined(SYS_ERRLIST_DECLARED) extern char const * const sys_errlist[]; extern const int sys_nerr; @@ -179,10 +176,10 @@ error_message(long code) * WinSock errors exist in the 10000 and 11000 ranges * but might not appear if WinSock is not initialized */ - if (code < 12000) { + if (code >= WSABASEERR && code < WSABASEERR + 1100) { table_num = 0; offset = code; - divisor = 10000; + divisor = WSABASEERR; } #endif #ifdef _WIN32 @@ -200,7 +197,7 @@ error_message(long code) * WinSock errors exist in the 10000 and 11000 ranges * but might not appear if WinSock is not initialized */ - if (code < 12000) { + if (code >= WSABASEERR && code < WSABASEERR + 1100) { table_num = 0; offset = code; divisor = 10000; @@ -208,8 +205,22 @@ error_message(long code) goto oops; } else { - strncpy(buffer, msgbuf, sizeof(buffer)); - buffer[sizeof(buffer)-1] = '\0'; + 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; + } + } + buffer = cp; + strncpy(buffer, msgbuf, ET_EBUFSIZ); + buffer[ET_EBUFSIZ-1] = '\0'; cp = buffer + strlen(buffer) - 1; if (*cp == '\n') *cp-- = '\0'; if (*cp == '\r') *cp-- = '\0'; diff --git a/src/util/et/test_et.c b/src/util/et/test_et.c index 1089c2166..8ef3d725f 100644 --- a/src/util/et/test_et.c +++ b/src/util/et/test_et.c @@ -4,6 +4,10 @@ #include "test1.h" #include "test2.h" +#ifdef _WIN32 +# define EXPORT_LIST +#endif + /* XXX Not part of official public API. */ extern const char *error_table_name (errcode_t); @@ -14,8 +18,10 @@ extern int sys_nerr; int main() { printf("Before initiating error table:\n\n"); +#ifndef EXPORT_LIST printf("Table name '%s'\n", error_table_name(KRB_MK_AP_TGTEXP)); printf("UNIX name '%s'\n", error_table_name(EPERM)); +#endif printf("Msg TGT-expired is '%s'\n", error_message(KRB_MK_AP_TGTEXP)); printf("Msg EPERM is '%s'\n", error_message(EPERM)); printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR)); @@ -29,17 +35,27 @@ int main() printf("With 0: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP)); initialize_krb_error_table(); +#ifndef EXPORT_LIST printf("KRB error table initialized: base %ld (%s), name %s\n", ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb), error_table_name(ERROR_TABLE_BASE_krb)); - initialize_krb_error_table(); +#else + printf("KRB error table initialized: base %ld (%s)\n", + ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb)); +#endif + add_error_table(&et_krb_error_table); printf("With krb: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP)); - initialize_quux_error_table(); + add_error_table(&et_quux_error_table); +#ifndef EXPORT_LIST printf("QUUX error table initialized: base %ld (%s), name %s\n", ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux), error_table_name(ERROR_TABLE_BASE_quux)); +#else + printf("QUUX error table initialized: base %ld (%s)\n", + ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux)); +#endif printf("Msg for TGT-expired is '%s'\n", error_message(KRB_MK_AP_TGTEXP)); -- 2.26.2