]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
[PATCH] libsysfs: remove trailing slash on SYSFS_PATH override
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Sat, 26 Mar 2005 23:09:05 +0000 (00:09 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:54:59 +0000 (23:54 -0700)
libsysfs/sysfs/libsysfs.h
libsysfs/sysfs_utils.c

index 6140c3aecbca2de8b7493b8a93ebc937930ea7f2..2f122405d73453c001ef398fb90943fe4b3584cc 100644 (file)
 #define        SYSFS_NAME_LEN          64
 #define SYSFS_BUS_ID_SIZE      32
 
+/* mount path for sysfs, can be overridden by exporting SYSFS_PATH */
+#define SYSFS_MNT_PATH         "/sys"
+
 enum sysfs_attribute_method {
        SYSFS_METHOD_SHOW =     0x01,   /* attr can be read by user */
        SYSFS_METHOD_STORE =    0x02,   /* attr can be changed by user */
 };
 
-/* NOTE: statically define mnt path for sysfs */
-#define SYSFS_MNT_PATH         "/sys"
-
 /*
  * NOTE: 
  * 1. We have the statically allocated "name" as the first element of all 
index 9f6e18f665dd592cdb9de80ef9830e78880cd477..210c2a086d022b83f416a0106023dcb795600f4b 100644 (file)
  */ 
 int sysfs_remove_trailing_slash(char *path)
 {
-       char *c = NULL;
+       size_t len;
 
        if (!path) {
                errno = EINVAL;
                return 1;
        }
-       c = strrchr(path, '/');
-       if (c == NULL) {
-               dprintf("Invalid path %s\n", path);
-               errno = EINVAL;
-               return 1;
-       }
-       if (*(c+1) == '\0') 
-               *c = '\0';
+
+       len = strlen(path);
+       while (len > 0 && path[len-1] == '/')
+               path[--len] = '\0';
        return 0;
 }
 
@@ -64,6 +60,7 @@ int sysfs_get_mnt_path(char *mnt_path, size_t len)
                sysfs_path_env = getenv(SYSFS_PATH_ENV);
                if (sysfs_path_env != NULL) {
                        safestrcpymax(mnt_path, sysfs_path_env, len);
+                       sysfs_remove_trailing_slash(mnt_path);
                        return 0;
                }
                safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);