diff options
author | Thomas Graf <tgr@lsx.localdomain> | 2008-05-14 17:49:44 +0200 |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2008-05-14 17:49:44 +0200 |
commit | 8a3efffa5b3fde252675239914118664d36a2c24 (patch) | |
tree | f8efc71b2bd4736f2a56084efea05d7ee191a422 /lib/object.c | |
parent | 85f932552e61c5997c1e83fe386098c94d93c273 (diff) | |
download | android_external_libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.gz android_external_libnl-8a3efffa5b3fde252675239914118664d36a2c24.tar.bz2 android_external_libnl-8a3efffa5b3fde252675239914118664d36a2c24.zip |
Thread-safe error handling
In order for the interface to become more thread safe, the error
handling was revised to no longer depend on a static errno and
error string buffer.
This patch converts all error paths to return a libnl specific
error code which can be translated to a error message using
nl_geterror(int error). The functions nl_error() and
nl_get_errno() are therefore obsolete.
This change required various sets of function prototypes to be
changed in order to return an error code, the most prominent
are:
struct nl_cache *foo_alloc_cache(...);
changed to:
int foo_alloc_cache(..., struct nl_cache **);
struct nl_msg *foo_build_request(...);
changed to:
int foo_build_request(..., struct nl_msg **);
struct foo *foo_parse(...);
changed to:
int foo_parse(..., struct foo **);
This pretty much only leaves trivial allocation functions to
still return a pointer object which can still return NULL to
signal out of memory.
This change is a serious API and ABI breaker, sorry!
Diffstat (limited to 'lib/object.c')
-rw-r--r-- | lib/object.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/object.c b/lib/object.c index 72e4ba4..3771af9 100644 --- a/lib/object.c +++ b/lib/object.c @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> */ /** @@ -47,10 +47,8 @@ struct nl_object *nl_object_alloc(struct nl_object_ops *ops) BUG(); new = calloc(1, ops->oo_size); - if (!new) { - nl_errno(ENOMEM); + if (!new) return NULL; - } new->ce_refcnt = 1; nl_init_list_head(&new->ce_list); @@ -69,17 +67,18 @@ struct nl_object *nl_object_alloc(struct nl_object_ops *ops) * @arg kind name of object type * @return The new object or nULL */ -struct nl_object *nl_object_alloc_name(const char *kind) +int nl_object_alloc_name(const char *kind, struct nl_object **result) { struct nl_cache_ops *ops; ops = nl_cache_ops_lookup(kind); - if (!ops) { - nl_error(ENOENT, "Unable to lookup cache kind \"%s\"", kind); - return NULL; - } + if (!ops) + return -NLE_OPNOTSUPP; + + if (!(*result = nl_object_alloc(ops->co_obj_ops))) + return -NLE_NOMEM; - return nl_object_alloc(ops->co_obj_ops); + return 0; } struct nl_derived_object { |