From e8de265f8039165dc32ffb78f6a6a5eb0c1514ad Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 26 Jun 2014 11:50:34 -0400 Subject: move _alpm_lstat into util-common Signed-off-by: Andrew Gregory --- src/common/util-common.c | 25 +++++++++++++++++++++++++ src/common/util-common.h | 4 ++++ 2 files changed, 29 insertions(+) (limited to 'src/common') diff --git a/src/common/util-common.c b/src/common/util-common.c index c5097ddf..e6f95194 100644 --- a/src/common/util-common.c +++ b/src/common/util-common.c @@ -73,6 +73,31 @@ char *mdirname(const char *path) return strdup("."); } +/** lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink. + * Linux lstat follows POSIX semantics and still performs a dereference on + * the first, and for uses of lstat in libalpm this is not what we want. + * @param path path to file to lstat + * @param buf structure to fill with stat information + * @return the return code from lstat + */ +int llstat(const char *path, struct stat *buf) +{ + int ret; + 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); + } else { + ret = lstat(path, buf); + } + + return ret; +} + #ifndef HAVE_STRNDUP /* A quick and dirty implementation derived from glibc */ /** Determines the length of a fixed-size string. diff --git a/src/common/util-common.h b/src/common/util-common.h index e28c60d9..5f04b00c 100644 --- a/src/common/util-common.h +++ b/src/common/util-common.h @@ -20,9 +20,13 @@ #ifndef _PM_UTIL_COMMON_H #define _PM_UTIL_COMMON_H +#include /* struct stat */ + const char *mbasename(const char *path); char *mdirname(const char *path); +int llstat(const char *path, struct stat *buf); + #ifndef HAVE_STRNDUP char *strndup(const char *s, size_t n); #endif -- cgit v1.2.3-70-g09d2