diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-10-28 19:13:50 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-10-28 19:13:50 +0000 |
commit | a67c21f093202f142438689d3f7cfbdf4ea82eea (patch) | |
tree | 5c3295037f033904bc11ab8b3adae5b7331101e9 /src/pulsecore/authkey-prop.c | |
parent | 6687dd013169fd8436aa1b45ccdacff074a40d05 (diff) |
merge 'lennart' branch back into trunk.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulsecore/authkey-prop.c')
-rw-r--r-- | src/pulsecore/authkey-prop.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/pulsecore/authkey-prop.c b/src/pulsecore/authkey-prop.c index 3b8304b2..54154500 100644 --- a/src/pulsecore/authkey-prop.c +++ b/src/pulsecore/authkey-prop.c @@ -21,44 +21,56 @@ USA. ***/ -#include <assert.h> +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + #include <string.h> #include <pulse/xmalloc.h> #include <pulsecore/props.h> +#include <pulsecore/macro.h> #include <pulsecore/log.h> +#include <pulsecore/refcnt.h> #include "authkey-prop.h" struct authkey_data { - int ref; + PA_REFCNT_DECLARE; size_t length; }; int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) { struct authkey_data *a; - assert(c && name && data && len > 0); + + pa_assert(c); + pa_assert(name); + pa_assert(data); + pa_assert(len > 0); if (!(a = pa_property_get(c, name))) return -1; - assert(a->length == len); - memcpy(data, a+1, len); + pa_assert(a->length == len); + memcpy(data, (uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), len); + return 0; } int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) { struct authkey_data *a; - assert(c && name); + + pa_assert(c); + pa_assert(name); if (pa_property_get(c, name)) return -1; - a = pa_xmalloc(sizeof(struct authkey_data) + len); - a->ref = 1; + a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len); + PA_REFCNT_INIT(a); a->length = len; - memcpy(a+1, data, len); + memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len); pa_property_set(c, name, a); @@ -67,22 +79,27 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l void pa_authkey_prop_ref(pa_core *c, const char *name) { struct authkey_data *a; - assert(c && name); - a = pa_property_get(c, name); - assert(a && a->ref >= 1); + pa_assert(c); + pa_assert(name); - a->ref++; + a = pa_property_get(c, name); + pa_assert(a); + pa_assert(PA_REFCNT_VALUE(a) >= 1); + PA_REFCNT_INC(a); } void pa_authkey_prop_unref(pa_core *c, const char *name) { struct authkey_data *a; - assert(c && name); + + pa_assert(c); + pa_assert(name); a = pa_property_get(c, name); - assert(a && a->ref >= 1); + pa_assert(a); + pa_assert(PA_REFCNT_VALUE(a) >= 1); - if (!(--a->ref)) { + if (PA_REFCNT_DEC(a) <= 0) { pa_property_remove(c, name); pa_xfree(a); } |