diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2007-03-14 21:41:33 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2007-03-14 21:41:33 +0100 |
commit | 9c6ad9fbbac82e517f5e748ddbe166f96f120afe (patch) | |
tree | 2021ceed05626469a75280a6c1b5cc897e157a75 /udev_db.c | |
parent | 5edec024b1ed7bbdf73095791c13df324038c31d (diff) |
encode db-file names, instead of just replacing '/'
Diffstat (limited to 'udev_db.c')
-rw-r--r-- | udev_db.c | 40 |
1 files changed, 10 insertions, 30 deletions
@@ -33,38 +33,22 @@ #include "udev.h" -static int devpath_to_db_path(const char *devpath, char *filename, size_t len) +static size_t devpath_to_db_path(const char *devpath, char *filename, size_t len) { - size_t start, end, i; + size_t start; /* add location of db files */ strlcpy(filename, udev_root, len); start = strlcat(filename, "/"DB_DIR, len); - end = strlcat(filename, devpath, len); - if (end > len) - end = len; - - /* replace '/' to transform path into a filename */ - for (i = start+1; i < end; i++) - if (filename[i] == '/') - filename[i] = PATH_TO_NAME_CHAR; - - return 0; + strlcat(filename, devpath, len); + return path_encode(&filename[start+1], len - (start+1)); } static int db_file_to_devpath(const char *filename, char *devpath, size_t len) { - size_t end, i; - strlcpy(devpath, "/", len); - end = strlcat(devpath, filename, len); - - /* replace PATH_TO_NAME_CHAR to transform name into devpath */ - for (i = 1; i < end; i++) - if (devpath[i] == PATH_TO_NAME_CHAR) - devpath[i] = '/'; - - return 0; + strlcat(devpath, filename, len); + return path_decode(devpath); } int udev_db_add_device(struct udevice *udev) @@ -338,8 +322,7 @@ int udev_db_get_all_entries(struct list_head *name_list) while (1) { struct dirent *ent; - char filename[PATH_SIZE] = "/"; - size_t end, i; + char device[PATH_SIZE]; ent = readdir(dir); if (ent == NULL || ent->d_name[0] == '\0') @@ -347,12 +330,9 @@ int udev_db_get_all_entries(struct list_head *name_list) if (ent->d_name[0] == '.') continue; - end = strlcat(filename, ent->d_name, sizeof(filename)); - for (i = 1; i < end; i++) - if (filename[i] == PATH_TO_NAME_CHAR) - filename[i] = '/'; - name_list_add(name_list, filename, 1); - dbg("added '%s'", filename); + db_file_to_devpath(ent->d_name, device, sizeof(device)); + name_list_add(name_list, device, 1); + dbg("added '%s'", device); } closedir(dir); |