Renamed __init__dlfcn() to __init_dlfcn(), moved prototype to libroot_private.h header.

Made it less vulnerable to thread-safety issues; it could occassionally return an
error when there was an error in a concurrent dlfcn function.
Renamed global static variables to have the "s" prefix.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9305 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-10-12 16:33:45 +00:00
parent 320f1cc118
commit 0214622f56

View File

@ -1,43 +1,52 @@
/* /*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. ** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Copyright 2002, Manuel J. Petit. All rights reserved. ** Copyright 2002, Manuel J. Petit. All rights reserved.
** Distributed under the terms of the NewOS License. ** Distributed under the terms of the NewOS License.
*/ */
#include <libroot_private.h>
#include <user_runtime.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <string.h> #include <string.h>
#include "user_runtime.h"
void __init__dlfcn(struct uspace_program_args const *); static struct rld_export const *sRuntimeLinker;
static status_t sStatus;
static struct rld_export const *gRuntimeLinker;
static status_t gStatus;
// Note, this is not thread-safe // Note, this is not thread-safe
void * void *
dlopen(char const *name, int mode) dlopen(char const *name, int mode)
{ {
status_t status;
if (name == NULL) if (name == NULL)
name = MAGIC_APP_NAME; name = MAGIC_APP_NAME;
gStatus = gRuntimeLinker->load_add_on(name, mode); status = sRuntimeLinker->load_add_on(name, mode);
if (gStatus < B_OK) sStatus = status;
if (status < B_OK)
return NULL; return NULL;
return (void *)gStatus; return (void *)status;
} }
void * void *
dlsym(void *handle, char const *name) dlsym(void *handle, char const *name)
{ {
status_t status;
void *location; void *location;
gStatus = gRuntimeLinker->get_image_symbol((image_id)handle, name, B_SYMBOL_TYPE_ANY, &location); status = sRuntimeLinker->get_image_symbol((image_id)handle, name, B_SYMBOL_TYPE_ANY, &location);
if (gStatus < B_OK) sStatus = status;
if (status < B_OK)
return NULL; return NULL;
return location; return location;
@ -47,22 +56,22 @@ dlsym(void *handle, char const *name)
int int
dlclose(void *handle) dlclose(void *handle)
{ {
return gRuntimeLinker->unload_add_on((image_id)handle); return sRuntimeLinker->unload_add_on((image_id)handle);
} }
char * char *
dlerror(void) dlerror(void)
{ {
if (gStatus < B_OK) if (sStatus < B_OK)
return strerror(gStatus); return strerror(sStatus);
return NULL; return NULL;
} }
void void
__init__dlfcn(struct uspace_program_args const *args) __init_dlfcn(const struct uspace_program_args *args)
{ {
gRuntimeLinker = args->rld_export; sRuntimeLinker = args->rld_export;
} }