diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-28 09:08:53 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-28 09:26:38 -0700 |
commit | 84220fa7dce80a7f985e145900489f1f345f8967 (patch) | |
tree | 274648a02e185816a0f8680f511893416215580b | |
parent | 624f46bdf8b7fbcd37823b45a4ac7b4422c559a1 (diff) |
Add function initd_clear_rc and refactor with initd_set_rc
Added the initd_clear_rc function as the complement to initd_set_rc.
It clears level bits from an rc type in the initd. Refactored the rc_t
evaluation into a separate function, initd_get_rc_from_key.
-rw-r--r-- | lib/initd.c | 59 | ||||
-rw-r--r-- | lib/initd.h | 5 |
2 files changed, 49 insertions, 15 deletions
diff --git a/lib/initd.c b/lib/initd.c index 7fce001..12b3e69 100644 --- a/lib/initd.c +++ b/lib/initd.c @@ -8,6 +8,9 @@ #include "initd.h" #include "str.h" +static initd_rc_t *initd_get_rc_from_key(const initd_t *ip, + initd_key_t key); + initd_t *initd_new(const char *name) { initd_t *ip = malloc(sizeof(initd_t)); if (!ip) @@ -100,32 +103,60 @@ out: return dest; } -void initd_set_rc(initd_t *ip, initd_key_t key, initd_rc_t level) +/* Set the bits of the rc mask in the specified key */ +void initd_set_rc(const initd_t *ip, initd_key_t key, initd_rc_t level) { + initd_rc_t *rc; + if (!ip) return; + rc = initd_get_rc_from_key(ip, key); + if (!rc) + return; + + /* Set the level bits */ + *rc |= level; +} + +/* Clear the bits of the rc mask in the specified key */ +void initd_clear_rc(const initd_t *ip, initd_key_t key, initd_rc_t level) +{ + initd_rc_t *rc; + + if (!ip) + return; + + rc = initd_get_rc_from_key(ip, key); + if (!rc) + return; + + /* Clear the level bits */ + *rc &= ~(level); +} + +/* Map a key type to an rc type for an initd_t */ +static initd_rc_t *initd_get_rc_from_key(const initd_t *ip, + initd_key_t key) +{ + if (!ip) + return NULL; + switch (key) { case KEY_ASTART: - ip->astart |= level; - break; + return (initd_rc_t *) &ip->astart; case KEY_ASTOP: - ip->astop |= level; - break; + return (initd_rc_t *) &ip->astop; case KEY_CSTART: - ip->cstart |= level; - break; + return (initd_rc_t *) &ip->cstart; case KEY_CSTOP: - ip->cstop |= level; - break; + return (initd_rc_t *) &ip->cstop; case KEY_DSTART: - ip->dstart |= level; - break; + return (initd_rc_t *) &ip->dstart; case KEY_DSTOP: - ip->dstop |= level; - break; + return (initd_rc_t *) &ip->dstop; default: - break; + return NULL; } } diff --git a/lib/initd.h b/lib/initd.h index e6b8e23..273f289 100644 --- a/lib/initd.h +++ b/lib/initd.h @@ -26,7 +26,10 @@ extern initd_t *initd_parse(const char *path); #define initd_add_sstop(ip, name) dep_add(ip->sstop, name) #define initd_add_astart_links(ip, name) strarg_add(ip->astart_links, name) #define initd_add_astop_links(ip, name) strarg_add(ip->astop_links, name) -extern void initd_set_rc(initd_t *ip, initd_key_t key, initd_rc_t level); +extern void initd_set_rc(const initd_t *ip, initd_key_t key, + initd_rc_t level); +extern void initd_clear_rc(const initd_t *ip, initd_key_t key, + initd_rc_t level); extern void initd_set_sdesc(initd_t *ip, const char *sdesc); extern void initd_set_desc(initd_t *ip, const char *desc); extern void initd_add_desc(initd_t *ip, const char *ext); |