/*
* udev database library
*/
+#define _KLIBC_HAS_ARCH_SIG_ATOMIC_T
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
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)
}
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;
+}