From e5338ba1eda7a5b6fc71208436c17b9942af661a Mon Sep 17 00:00:00 2001 From: robocop Date: Sat, 25 Mar 2006 07:08:00 +0000 Subject: [PATCH] Only strcmp and strncmp have common names across all plartforms. Cater for differences in strcasecmp/stricmp and strncasecmp/strnicmp. --- configure.in | 1 + src/common/utils_proto.h | 38 +++++++++++++++++++++++++++++++ src/include/gen/autoconfig_msvc.h | 2 ++ src/jrd/common.h | 21 ----------------- src/jrd/svc.cpp | 3 ++- src/utilities/gsec/security.epp | 3 ++- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/configure.in b/configure.in index c055181499..676ed11dae 100644 --- a/configure.in +++ b/configure.in @@ -456,6 +456,7 @@ AC_CHECK_FUNCS(time times) AC_SEARCH_LIBS(gethostname,nsl) AC_SEARCH_LIBS(connect,socket) AC_CHECK_FUNCS(strcasecmp stricmp) +AC_CHECK_FUNCS(strncasecmp strnicmp) if test "$ac_cv_func_strcasecmp" = "no" -a "$ac_cv_func_stricmp" = "no"; then dnl EKU: On SINIX-Z strcasecmp is in libresolv. AC_CHECK_LIB(resolv, strcasecmp, diff --git a/src/common/utils_proto.h b/src/common/utils_proto.h index ae0690ebce..db563fc9bc 100644 --- a/src/common/utils_proto.h +++ b/src/common/utils_proto.h @@ -28,8 +28,10 @@ #ifndef INCLUDE_UTILS_PROTO_H #define INCLUDE_UTILS_PROTO_H +#include #include "../common/classes/fb_string.h" + namespace fb_utils { char* exact_name(char* const str); @@ -42,6 +44,42 @@ namespace fb_utils bool readenv(const char* env_name, Firebird::string& env_value); bool readenv(const char* env_name, Firebird::PathName& env_value); int snprintf(char* buffer, size_t count, const char* format...); + +// Warning: Only wrappers: + + // ******************** + // s t r i c m p + // ******************** + // Abstraction of incompatible routine names + // for case insensitive comparison. + inline int stricmp(const char* a, const char* b) + { +#if defined(HAVE_STRCASECMP) + return ::strcasecmp(a, b); +#elif defined(HAVE_STRICMP) + return ::stricmp(a, b); +#else +#error dont know how to compare strings case insensitive on this system +#endif + } + + + // ******************** + // s t r n i c m p + // ******************** + // Abstraction of incompatible routine names + // for counted length and case insensitive comparison. + inline int strnicmp(const char* a, const char* b, size_t count) + { +#if defined(HAVE_STRNCASECMP) + return ::strncasecmp(a, b, count); +#elif defined(HAVE_STRNICMP) + return ::strnicmp(a, b, count); +#else +#error dont know how to compare counted length strings case insensitive on this system +#endif + } + } // namespace fb_utils #endif // INCLUDE_UTILS_PROTO_H diff --git a/src/include/gen/autoconfig_msvc.h b/src/include/gen/autoconfig_msvc.h index 9126ad63ae..a56597de9d 100644 --- a/src/include/gen/autoconfig_msvc.h +++ b/src/include/gen/autoconfig_msvc.h @@ -129,6 +129,8 @@ #undef HAVE_TIMES #undef HAVE_STRCASECMP #define HAVE_STRICMP +#undef HAVE_STRNCASECMP +#define HAVE_STRNICMP #define HAVE_DIRNAME #undef HAVE_SIGACTION #undef HAVE_SETITIMER diff --git a/src/jrd/common.h b/src/jrd/common.h index 77166746bb..3df31f87c6 100644 --- a/src/jrd/common.h +++ b/src/jrd/common.h @@ -1091,26 +1091,5 @@ static const TEXT* FB_LONG_MONTHS_UPPER[] = 0 }; - - -// ====================================== -// BEGIN AUTOCONF ABSTRACTION LAYER -// CVC: It's unacceptable that we pollute all the sources with the -// #ifdef HAVE_ feature. While the function prototypes are -// compatible or the extra params are ignored or we can pass default values, -// we must wrap those functions in FB names. - -#include -inline int fb_stricmp(const char* a, const char* b) -{ -#if defined(HAVE_STRCASECMP) - return strcasecmp(a, b); -#elif defined(HAVE_STRICMP) - return stricmp(a, b); -#else -#error dont know how to compare strings case insensitive on this system -#endif -} - #endif /* JRD_COMMON_H */ diff --git a/src/jrd/svc.cpp b/src/jrd/svc.cpp index 3938eb8ca4..1da4e3cda2 100644 --- a/src/jrd/svc.cpp +++ b/src/jrd/svc.cpp @@ -64,6 +64,7 @@ #include "../common/classes/alloc.h" #include "../common/classes/ClumpletWriter.h" #include "../jrd/ibase.h" +#include "../common/utils_proto.h" #ifdef SERVER_SHUTDOWN #include "../jrd/jrd_proto.h" @@ -518,7 +519,7 @@ Service* SVC_attach(USHORT service_length, } /* Check that the validated user has the authority to access this service */ - if (fb_stricmp(options.spb_user_name.c_str(), SYSDBA_USER_NAME)) + if (fb_utils::stricmp(options.spb_user_name.c_str(), SYSDBA_USER_NAME)) { user_flag = SVC_user_any; } diff --git a/src/utilities/gsec/security.epp b/src/utilities/gsec/security.epp index b3892fd77c..792f772807 100644 --- a/src/utilities/gsec/security.epp +++ b/src/utilities/gsec/security.epp @@ -39,6 +39,7 @@ #include "../common/classes/fb_string.h" #include "../jrd/jrd_pwd.h" #endif +#include "../common/utils_proto.h" DATABASE DB = STATIC FILENAME "security2.fdb"; @@ -257,7 +258,7 @@ SSHORT SECURITY_exec_line(ISC_STATUS* isc_status, found = false; /* Do not allow SYSDBA user to be deleted */ - if (!fb_stricmp(io_user_data->user_name, SYSDBA_USER_NAME)) + if (!fb_utils::stricmp(io_user_data->user_name, SYSDBA_USER_NAME)) ret = GsecMsg23; else { FOR U IN USERS WITH U.USER_NAME EQ io_user_data->user_name