diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-08-01 19:24:38 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-08-01 19:24:38 +0000 |
commit | 4f2793d41f1043cf04f6761b1da00d8741824087 (patch) | |
tree | 4438801b2a8444e7c83b62c3bd64ae833dc63ee1 /dlfcn/dlerror.c | |
parent | 7730a3b9d420136fc8a001d1ebd6c68cd0c005a3 (diff) | |
download | glibc-4f2793d41f1043cf04f6761b1da00d8741824087.tar glibc-4f2793d41f1043cf04f6761b1da00d8741824087.tar.gz glibc-4f2793d41f1043cf04f6761b1da00d8741824087.tar.bz2 glibc-4f2793d41f1043cf04f6761b1da00d8741824087.zip |
Update.
1999-08-01 Ulrich Drepper <drepper@cygnus.com>
* elf/dl-sym.c (_dl_sym): Always determine module of the caller to
pass it to _dl_lookup_symbol.
* elf/dl-error.c (_dl_signal_error): Optimize string generation a
bit. Reword message.
* dlfcn/dlerror.c: Make code thread-safe.
Diffstat (limited to 'dlfcn/dlerror.c')
-rw-r--r-- | dlfcn/dlerror.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c index c43d511156..b4ffde5fdf 100644 --- a/dlfcn/dlerror.c +++ b/dlfcn/dlerror.c @@ -1,5 +1,5 @@ /* Return error detail for failing <dlfcn.h> functions. - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -27,6 +27,7 @@ struct dl_action_result { int errcode; + int returned; char *errstring; }; static struct dl_action_result last_result; @@ -44,38 +45,41 @@ static void free_key_mem (void *mem); char * dlerror (void) { - static char *buf; + char *buf; struct dl_action_result *result; - if (buf) - { - free (buf); - buf = NULL; - } - /* Get error string. */ result = (struct dl_action_result *) __libc_getspecific (key); if (result == NULL) result = &last_result; - if (! result->errstring) - return NULL; - - if (result->errcode == 0) - buf = result->errstring; + /* Test whether we already returned the string. */ + if (result->returned != 0) + { + /* We can now free the string. */ + if (result->errstring != NULL) + { + free (result->errstring); + result->errstring = NULL; + } + buf = NULL; + } else { - if (__asprintf (&buf, "%s: %s", - result->errstring, strerror (result->errcode)) == -1) - buf = NULL; + buf = result->errstring; + if (result->errcode != 0 + && __asprintf (&buf, "%s: %s", + result->errstring, strerror (result->errcode)) != -1) + { + /* We don't need the error string anymore. */ + free (result->errstring); + result->errstring = buf; + } - /* We don't need the error string anymore. */ - free (result->errstring); + /* Mark the error as returned. */ + result->returned = 1; } - /* Reset the error indicator. */ - result->errstring = NULL; - return buf; } @@ -119,6 +123,9 @@ _dlerror_run (void (*operate) (void *), void *args) result->errcode = _dl_catch_error (&result->errstring, operate, args); + /* If no error we mark that no error string is available. */ + result->returned = result->errstring == NULL; + return result->errstring != NULL; } |