summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2014-03-17 20:01:53 +0100
committerBert Münnich <ber.t@posteo.de>2014-03-17 20:01:53 +0100
commit6d7acac3d132c5be09a9a4e8d0f4ebd4972e9385 (patch)
treefdc879d53995a7ff4e8f49ab9810a5156e74d7e2 /main.c
parent653a6ee83b722e430ac3068f53650dd382d9209b (diff)
downloadnsxiv-6d7acac3d132c5be09a9a4e8d0f4ebd4972e9385.tar.zst
Use real path of all files internally, requires _XOPEN_SOURCE>=500, fixes issue #137
Diffstat (limited to 'main.c')
-rw-r--r--main.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/main.c b/main.c
index d5ff918..f949e77 100644
--- a/main.c
+++ b/main.c
@@ -127,16 +127,28 @@ void check_add_file(char *filename)
filecnt *= 2;
files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t));
}
+
+#if defined _BSD_SOURCE || defined _XOPEN_SOURCE && \
+ ((_XOPEN_SOURCE - 0) >= 500 || defined _XOPEN_SOURCE_EXTENDED)
+
+ if ((files[fileidx].path = realpath(filename, NULL)) == NULL) {
+ warn("could not get real path of file: %s\n", filename);
+ return;
+ }
+#else
if (*filename != '/') {
- files[fileidx].path = absolute_path(filename);
- if (files[fileidx].path == NULL) {
+ if ((files[fileidx].path = absolute_path(filename)) == NULL) {
warn("could not get absolute path of file: %s\n", filename);
return;
}
+ } else {
+ files[fileidx].path = NULL;
}
+#endif
+
files[fileidx].loaded = false;
files[fileidx].name = s_strdup(filename);
- if (*filename == '/')
+ if (files[fileidx].path == NULL)
files[fileidx].path = files[fileidx].name;
if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0')
files[fileidx].base = ++bn;