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:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2014-06-26 11:50:34 -0400
committerAllan McRae <allan@archlinux.org>2014-08-03 18:46:32 +1000
commite8de265f8039165dc32ffb78f6a6a5eb0c1514ad (patch)
tree83363a49ca0e14815e2f866d8682a3cb905a4cfe /src/common/util-common.c
parent0e2db97a42df30d2731e4842b245191a68817d78 (diff)
move _alpm_lstat into util-common
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Diffstat (limited to 'src/common/util-common.c')
-rw-r--r--src/common/util-common.c25
1 files changed, 25 insertions, 0 deletions
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.