X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udevdb.c;h=bbbeddad477958a6cb9827879d82cf1675ae28b5;hb=3fd52a7694d94b57fc5a0dc380673a78683118fe;hp=ec67a079627df09cec9cdf5a1733d99e87139051;hpb=c056c5141b16fe95485eeb233fe8b90954686a60;p=elogind.git diff --git a/udevdb.c b/udevdb.c index ec67a0796..bbbeddad4 100644 --- a/udevdb.c +++ b/udevdb.c @@ -24,6 +24,7 @@ /* * udev database library */ +#define _KLIBC_HAS_ARCH_SIG_ATOMIC_T #include #include #include @@ -54,36 +55,29 @@ int udevdb_add_dev(const char *path, const struct udevice *dev) strcpy(keystr, path); key.dptr = keystr; key.dsize = strlen(keystr) + 1; - + data.dptr = (void *)dev; data.dsize = sizeof(*dev); return tdb_store(udevdb, key, data, TDB_REPLACE); } -struct udevice *udevdb_get_dev(const char *path) +int udevdb_get_dev(const char *path, struct udevice *dev) { TDB_DATA key, data; - struct udevice *dev; if (path == NULL) - return NULL; + return -ENODEV; key.dptr = (void *)path; key.dsize = strlen(path) + 1; data = tdb_fetch(udevdb, key); if (data.dptr == NULL || data.dsize == 0) - return NULL; + return -ENODEV; - dev = malloc(sizeof(*dev)); - if (dev == NULL) - goto exit; - memcpy(dev, data.dptr, sizeof(*dev)); -exit: - free(data.dptr); - return dev; + return 0; } int udevdb_delete_dev(const char *path) @@ -99,7 +93,7 @@ int udevdb_delete_dev(const char *path) key.dptr = keystr; key.dsize = strlen(keystr) + 1; - + return tdb_delete(udevdb, key); } @@ -116,8 +110,8 @@ void udevdb_exit(void) /** * udevdb_init: initializes database - * @init_flag: database can either be in memory - UDEVDB_INTERNAL - or - * written to a file with UDEVDB_DEFAULT. + * @init_flag: UDEVDB_INTERNAL - database stays in memory + * UDEVDB_DEFAULT - database is written to a file */ int udevdb_init(int init_flag) { @@ -127,9 +121,9 @@ int udevdb_init(int init_flag) udevdb = tdb_open(udev_db_filename, 0, init_flag, O_RDWR | O_CREAT, 0644); if (udevdb == NULL) { if (init_flag == UDEVDB_INTERNAL) - dbg("Unable to initialize in-memory database"); + dbg("unable to initialize in-memory database"); else - dbg("Unable to initialize database at %s", udev_db_filename); + dbg("unable to initialize database at '%s'", udev_db_filename); return -EINVAL; } return 0;