X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=libsysfs%2Fsysfs_utils.c;h=bd7f99ae15d6c0417f492e7e72ef981bf8de3af3;hb=7a551dc35580988d13ff8e6e3e37398ac779181a;hp=9f6e18f665dd592cdb9de80ef9830e78880cd477;hpb=f385ff6512012a75b8381938dd3f55f991b53e9a;p=elogind.git diff --git a/libsysfs/sysfs_utils.c b/libsysfs/sysfs_utils.c index 9f6e18f66..bd7f99ae1 100644 --- a/libsysfs/sysfs_utils.c +++ b/libsysfs/sysfs_utils.c @@ -3,7 +3,7 @@ * * System utility functions for libsysfs * - * Copyright (C) IBM Corp. 2003 + * Copyright (C) IBM Corp. 2003-2005 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,20 +30,16 @@ */ 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); @@ -236,7 +233,7 @@ int sysfs_path_is_dir(const char *path) errno = EINVAL; return 1; } - if ((lstat(path, &astats)) != 0) { + if ((stat(path, &astats)) != 0) { dprintf("stat() failed\n"); return 1; }