Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/common/util-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/util-common.c')
-rw-r--r--src/common/util-common.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/common/util-common.c b/src/common/util-common.c
index e6f95194..3316eaec 100644
--- a/src/common/util-common.c
+++ b/src/common/util-common.c
@@ -80,17 +80,21 @@ char *mdirname(const char *path)
* @param buf structure to fill with stat information
* @return the return code from lstat
*/
-int llstat(const char *path, struct stat *buf)
+int llstat(char *path, struct stat *buf)
{
int ret;
+ char *c = NULL;
size_t len = strlen(path);
- /* strip the trailing slash if one exists */
- if(len != 0 && path[len - 1] == '/') {
- char *newpath = strdup(path);
- newpath[len - 1] = '\0';
- ret = lstat(newpath, buf);
- free(newpath);
+ while(len > 1 && path[len - 1] == '/') {
+ --len;
+ c = path + len;
+ }
+
+ if(c) {
+ *c = '\0';
+ ret = lstat(path, buf);
+ *c = '/';
} else {
ret = lstat(path, buf);
}