diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-04-14 12:40:23 +0200 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-04-27 10:14:14 +0200 |
commit | e2cc066bcd6302620d9806b6346523670f4e1ef7 (patch) | |
tree | 9ee2e0899460a021be7d7802aa1aa62aac83358b | |
parent | b51ccb5a0e084d7b7e3a3ca4f91fc446d7b2198f (diff) | |
download | libusbg-e2cc066bcd6302620d9806b6346523670f4e1ef7.tar.gz libusbg-e2cc066bcd6302620d9806b6346523670f4e1ef7.tar.bz2 libusbg-e2cc066bcd6302620d9806b6346523670f4e1ef7.zip |
libusbg: Add functions for reading/writing bool values
Some of function attributes on ConfigFS may be simple
boolean values so add common functions for reading
and writing them.
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
-rw-r--r-- | src/usbg.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -26,6 +26,7 @@ #include <sys/stat.h> #include <unistd.h> #include <ctype.h> +#include <stdbool.h> #include "usbg/usbg_internal.h" /** @@ -433,6 +434,21 @@ static int usbg_read_int(const char *path, const char *name, const char *file, #define usbg_read_dec(p, n, f, d) usbg_read_int(p, n, f, 10, d) #define usbg_read_hex(p, n, f, d) usbg_read_int(p, n, f, 16, d) +static int usbg_read_bool(const char *path, const char *name, const char *file, + bool *dest) +{ + int buf; + int ret; + + ret = usbg_read_dec(path, name, file, &buf); + if (ret != USBG_SUCCESS) + goto out; + + *dest = !!buf; +out: + return ret; +} + static int usbg_read_string(const char *path, const char *name, const char *file, char *buf) { @@ -521,6 +537,7 @@ static int usbg_write_int(const char *path, const char *name, const char *file, #define usbg_write_hex(p, n, f, v) usbg_write_int(p, n, f, v, "0x%x\n") #define usbg_write_hex16(p, n, f, v) usbg_write_int(p, n, f, v, "0x%04x\n") #define usbg_write_hex8(p, n, f, v) usbg_write_int(p, n, f, v, "0x%02x\n") +#define usbg_write_bool(p, n, f, v) usbg_write_dec(p, n, f, !!v) static inline int usbg_write_string(const char *path, const char *name, const char *file, const char *buf) |