X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udevdb.c;h=ca9e63c97e61d4376f0d9593b2c54b3a4b936bcf;hp=5be3c2515126efb327d2276bbaddfbdb98963597;hb=f1db055ab2e349ce22254562faaece66d6a4a873;hpb=d546791d3ab1cbf8cb08b27eab1fc09e1c5d04dc;ds=inline diff --git a/udevdb.c b/udevdb.c index 5be3c2515..ca9e63c97 100644 --- a/udevdb.c +++ b/udevdb.c @@ -62,29 +62,22 @@ int udevdb_add_dev(const char *path, const struct udevice *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; - - dev = malloc(sizeof(*dev)); - if (dev == NULL) - goto exit; + return -ENODEV; memcpy(dev, data.dptr, sizeof(*dev)); -exit: - free(data.dptr); - return dev; + return 0; } int udevdb_delete_dev(const char *path) @@ -135,3 +128,16 @@ int udevdb_init(int init_flag) } return 0; } + +/** + * udevdb_open_ro: open database for reading + */ +int udevdb_open_ro(void) +{ + udevdb = tdb_open(udev_db_filename, 0, 0, O_RDONLY, 0); + if (udevdb == NULL) { + dbg("unable to open database at '%s'", udev_db_filename); + return -EINVAL; + } + return 0; +}