From: Hans de Goede Date: Sat, 18 Jun 2011 11:52:37 +0000 (+0200) Subject: get_media_devices: Properly canonicalize names X-Git-Tag: v4l-utils-0.8.5~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31a1c72b92efd8b0b6423f9351a7862654fcd34b;p=platform%2Fupstream%2Fv4l-utils.git get_media_devices: Properly canonicalize names Signed-off-by: Hans de Goede --- diff --git a/utils/libmedia_dev/get_media_devices.c b/utils/libmedia_dev/get_media_devices.c index 612709d..492a317 100644 --- a/utils/libmedia_dev/get_media_devices.c +++ b/utils/libmedia_dev/get_media_devices.c @@ -103,7 +103,6 @@ static int get_class(char *class, char virt_dev[60]; int err = -2; struct media_device_entry *md_ptr = NULL; - int size; char *p, *device; static int virtual = 0; @@ -114,22 +113,17 @@ static int get_class(char *class, return 0; } for (entry = readdir(dir); entry; entry = readdir(dir)) { + /* Skip . and .. */ + if (entry->d_name[0] == '.') + continue; + /* Canonicalize the device name */ snprintf(fname, PATH_MAX, "%s/%s", dname, entry->d_name); - - size = readlink(fname, link, PATH_MAX); - if (size > 0) { - link[size] = '\0'; - - /* Canonicalize the device name */ - - /* remove the ../../devices/ from the name */ - p = strstr(link, DEVICE_STR); - if (!p) - goto error; - device = p + sizeof(DEVICE_STR); + if (realpath(fname, link)) { + /* remove the /sys/devices/ from the name */ + device = link + 13; /* Remove the subsystem/class_name from the string */ - p = strstr(link, class); + p = strstr(device, class); if (!p) goto error; *(p - 1) = '\0';