-#if 1
- static int bufnum = 0;
- static char buf[2][20];
- bufnum = bufnum ? 0 : 1;
- sprintf(buf[bufnum], "0x%X", err);
- return buf[bufnum];
-#else /* !1 */
- if (err >= errSecErrnoBase && err <= errSecErrnoLimit)
- return strerror(err - 100000);
-
-#ifdef MAC_OS_X_VERSION_10_4
- /* AvailabilityMacros.h would only define this if we are on a
- Tiger or later machine. */
- extern const char *cssmErrorString(long);
- return cssmErrorString(err);
-#else /* !defined(MAC_OS_X_VERSION_10_4) */
- extern const char *_ZN8Security15cssmErrorStringEl(long);
- return _ZN8Security15cssmErrorStringEl(err);
-#endif /* MAC_OS_X_VERSION_10_4 */
-#endif /* !1 */
+ static pthread_key_t buffer0key;
+ static pthread_key_t buffer1key;
+ static pthread_key_t switchkey;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ pthread_key_create(&buffer0key, buf_kill);
+ pthread_key_create(&buffer1key, buf_kill);
+ pthread_key_create(&switchkey, buf_kill);
+ });
+
+ uint32_t * switchp = (uint32_t*) pthread_getspecific(switchkey);
+ if(switchp == NULL) {
+ switchp = (uint32_t*) malloc(sizeof(uint32_t));
+ *switchp = 0;
+ pthread_setspecific(switchkey, switchp);
+ }
+
+ char* buf = NULL;
+
+ pthread_key_t current = (*switchp) ? buffer0key : buffer1key;
+ *switchp = !(*switchp);
+
+ buf = pthread_getspecific(current);
+ if(buf == NULL) {
+ buf = (char*) malloc(20);
+ pthread_setspecific(current, buf);
+ }
+
+ snprintf(buf, 20, "0x%X", err);
+ return buf;