chiark / gitweb /
[PATCH] libsysfs: work around a klibc bug
[elogind.git] / libsysfs / sysfs_class.c
index 7a696355ca03d18556248083eda20773727cab36..4ea7f41c99c293410482acfed888498e47f79d27 100644 (file)
@@ -20,7 +20,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  *
  */
-#include "sysfs/libsysfs.h"
+#include "libsysfs.h"
 #include "sysfs.h"
 
 static void sysfs_close_cls_dev(void *dev)
@@ -111,7 +111,7 @@ static void set_classdev_classname(struct sysfs_class_device *cdev)
        if (c == NULL) {
                c = strstr(cdev->path, SYSFS_BLOCK_NAME);
        } else {
-               c = strstr(c, "/");
+               c = strchr(c, '/');
        }
 
        if (c == NULL)
@@ -509,16 +509,16 @@ static int get_classdev_path(const char *classname, const char *clsdev,
        }
        if (strncmp(classname, SYSFS_BLOCK_NAME,
                                sizeof(SYSFS_BLOCK_NAME)) == 0) {
-               safestrncat(path, "/", len);
-               safestrncat(path, SYSFS_BLOCK_NAME, len);
+               safestrcatmax(path, "/", len);
+               safestrcatmax(path, SYSFS_BLOCK_NAME, len);
        } else {
-               safestrncat(path, "/", len);
-               safestrncat(path, SYSFS_CLASS_NAME, len);
-               safestrncat(path, "/", len);
-               safestrncat(path, classname, len);
+               safestrcatmax(path, "/", len);
+               safestrcatmax(path, SYSFS_CLASS_NAME, len);
+               safestrcatmax(path, "/", len);
+               safestrcatmax(path, classname, len);
        }
-       safestrncat(path, "/", len);
-       safestrncat(path, clsdev, len);
+       safestrcatmax(path, "/", len);
+       safestrcatmax(path, clsdev, len);
        return 0;
 }
 
@@ -640,6 +640,9 @@ struct sysfs_attribute *sysfs_get_classdev_attr
                        return cur;
        }
 
+       if (clsdev->directory == NULL)
+               return NULL;
+
        if (clsdev->directory->subdirs == NULL) 
                if ((sysfs_read_dir_subdirs(clsdev->directory)) != 0 ||
                    clsdev->directory->subdirs == NULL)