]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Revised version of cs 979736
authorVMware, Inc <>
Wed, 24 Feb 2010 21:03:06 +0000 (13:03 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Wed, 24 Feb 2010 21:03:06 +0000 (13:03 -0800)
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 <mvanzin@vmware.com>
open-vm-tools/lib/include/str.h
open-vm-tools/lib/string/str.c

index 81be1566d999255a4d12170abb9dfd3969ddb38c..20dbfbca8596d72aa7755e5c7222875ce64bf4e2 100644 (file)
@@ -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);
index 801d1dadd6e63c73a6d36c626ada00d802aa1c8c..2b47f7c833302d7e51dc1e98b1366751f31dd9b0 100644 (file)
@@ -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
+
 
 /*
  *-----------------------------------------------------------------------------