From: VMware, Inc <> Date: Wed, 24 Feb 2010 21:03:06 +0000 (-0800) Subject: Revised version of cs 979736 X-Git-Tag: 2010.02.23-236320~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5350afdc657686613d0dd5badeaaf4dee47c4862;p=thirdparty%2Fopen-vm-tools.git Revised version of cs 979736 cs 979736 included changes to lib/string to call GetReturnAddress() that caused the linker to build differently. cs 979736 was subsequently backed out for pr 483076. This is the same change without the GetReturnAddress() calls. This change should not introduce any functional differences whatsoever; it merely introduces a new library function in lib/string that is currently not called. The original description of cs 979736 is: Add Str_Strerror, a thread safe version of strerror strerror is not thread safe, it reuses the memory for the error string on every call. strerror_r is thread safe, but requires callers to manage their buffers. Add a new Str_Strerror function that uses thread local storage to keep the error string. This function is only present on GLIBC_VERSION_23 and later. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/str.h b/open-vm-tools/lib/include/str.h index 81be1566d..20dbfbca8 100644 --- a/open-vm-tools/lib/include/str.h +++ b/open-vm-tools/lib/include/str.h @@ -98,6 +98,9 @@ EXTERN char *Str_Strnstr(const char *src, const char *sub, size_t n); EXTERN char *Str_Strcpy(char *dst, const char *src, size_t maxLen); EXTERN char *Str_Strcat(char *dst, const char *src, size_t maxLen); EXTERN char *Str_Strncat(char *buf, size_t bufSize, const char *src, size_t n); +#if defined(GLIBC_VERSION_23) +EXTERN const char *Str_Strerror(int errnum); +#endif EXTERN char *Str_Asprintf(size_t *length, const char *format, ...) PRINTF_DECL(2, 3); diff --git a/open-vm-tools/lib/string/str.c b/open-vm-tools/lib/string/str.c index 801d1dadd..2b47f7c83 100644 --- a/open-vm-tools/lib/string/str.c +++ b/open-vm-tools/lib/string/str.c @@ -48,6 +48,9 @@ #include "bsd_output.h" #endif #include "codeset.h" +#if defined(GLIBC_VERSION_23) +#define MAX_ERRSTR_SIZE 128 +#endif #if defined _WIN32 && !defined HAS_BSD_PRINTF #define vsnprintf _vsnprintf @@ -439,6 +442,42 @@ Str_Strncat(char *buf, // IN-OUT return strncat(buf, src, n); } +#if defined(GLIBC_VERSION_23) +/* + *---------------------------------------------------------------------- + * + * Str_Strerror -- + * + * User level wrapper for strerror that is thread safe. + * + * Results: + * Same as strerror. + * + * Side effects: + * Allocates per-thread strerror string. + * + *---------------------------------------------------------------------- + */ + +const char * +Str_Strerror(int errnum) // IN: errno value +{ + uint32 *stack; + char *ret; + static __thread char strerrorString[MAX_ERRSTR_SIZE]; + + stack = (uint32 *)&errnum; + + ret = strerror_r(errnum, strerrorString, MAX_ERRSTR_SIZE); + + if (!ret) { + Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]); + } + + return ret; +} +#endif + /* *-----------------------------------------------------------------------------