- char attr_path[SYSFS_PATH_MAX];
-
- strncpy(attr_path, devpath, SYSFS_PATH_MAX);
- strncat(attr_path, "/", SYSFS_PATH_MAX);
- strncat(attr_path, attr, SYSFS_PATH_MAX);
- dprintf("%s\n", attr_path);
- return sysfs_read_attribute_value(attr_path, value, SYSFS_NAME_LEN);
-}
-
-static int sysfs_get_actual_dev(const char *sysfs_path, char *dev, int len)
-{
- dprintf("%s\n", sysfs_path);
- strncpy(dev, sysfs_path, len);
- strncat(dev, "/device", len);
- if (sysfs_get_link(dev, dev, len)) {
- if (!hotplug_mode)
- log_message(LOG_WARNING, "%s: %s\n", dev,
- strerror(errno));
- return -1;
+ int i, j;
+ int len;
+
+ /* strip trailing whitespace */
+ len = strnlen(from, count);
+ while (isspace(from[len-1]))
+ len--;
+
+ /* strip leading whitespace */
+ i = 0;
+ while (isspace(from[i]) && (i < len))
+ i++;
+
+ j = 0;
+ while (i < len) {
+ /* substitute multiple whitespace */
+ if (isspace(from[i])) {
+ while (isspace(from[i]))
+ i++;
+ to[j++] = '_';
+ }
+ /* skip chars */
+ if (from[i] == '/') {
+ i++;
+ continue;
+ }
+ to[j++] = from[i++];