X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=udev_db.c;h=4515998fcd8c311fa950f63142269567c5d939cf;hb=4e05e4238b2cb63eb3f3cd51cf76f136fa684f2e;hp=df63bbe2ce147690a16d585382a16c9b2f308b85;hpb=8f2f6e426fc4cc1fa39b864a1792428a4269b751;p=elogind.git diff --git a/udev_db.c b/udev_db.c index df63bbe2c..4515998fc 100644 --- a/udev_db.c +++ b/udev_db.c @@ -179,7 +179,7 @@ int udev_db_get_device_by_devpath(struct udevice *udev, const char *devpath) return parse_db_file(udev, filename); } -int udev_db_get_device_byname(struct udevice *udev, const char *name) +int udev_db_get_device_by_name(struct udevice *udev, const char *name) { struct dirent *ent; DIR *dir; @@ -239,3 +239,38 @@ found: return 0; } + +int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)) +{ + struct dirent *ent; + DIR *dir; + char filename[NAME_SIZE]; + struct udevice db_udev; + + dir = opendir(udev_db_path); + if (dir == NULL) { + dbg("unable to udev db '%s'", udev_db_path); + return -1; + } + + while (1) { + ent = readdir(dir); + if (ent == NULL || ent->d_name[0] == '\0') + break; + + if (ent->d_name[0] == '.') + continue; + + snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name); + filename[NAME_SIZE-1] = '\0'; + + memset(&db_udev, 0x00, sizeof(struct udevice)); + if (parse_db_file(&db_udev, filename) == 0) { + if (handler_function(&db_udev) != 0) + break; + } + } + + closedir(dir); + return 0; +}