Krolyxon
Commit 6d7acac

Branches

Refs →

nsxiv6d7acac

Use real path of all files internally, requires _XOPEN_SOURCE>=500, fixes issue #137

Author
Bert Münnich
Date
2014-03-17 20:01 +0100
Parent
653a6ee
Commit
6d7acac3d132c5be09a9a4e8d0f4ebd4972e9385

+22 −9

2 files changed

  1. M Makefile +7 −6
  2. M main.c +15 −3
M Makefile View
@@ -1,12 +1,13 @@
1−VERSION = git-20140218
1+VERSION = git-20140317
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
55
6−CC = gcc
7−CFLAGS = -std=c99 -Wall -pedantic -O2 -I$(PREFIX)/include -DHAVE_GIFLIB
8−LDFLAGS = -L$(PREFIX)/lib
9−LIBS = -lX11 -lImlib2 -lgif
6+CC = gcc
7+CFLAGS = -std=c99 -Wall -pedantic -O2
8+CPPFLAGS = -I$(PREFIX)/include -D_XOPEN_SOURCE=500 -DHAVE_GIFLIB
9+LDFLAGS = -L$(PREFIX)/lib
10+LIBS = -lX11 -lImlib2 -lgif
1011
1112 SRC = commands.c exif.c image.c main.c options.c thumbs.c util.c window.c
1213 OBJ = $(SRC:.c=.o)
@@ -16,7 +17,7 @@ all: sxiv
1617 $(OBJ): Makefile config.h
1718
1819 .c.o:
19− $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
20+ $(CC) $(CFLAGS) $(CPPFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
2021
2122 config.h:
2223 cp config.def.h $@
M main.c View
@@ -127,16 +127,28 @@ void check_add_file(char *filename)
127127 filecnt *= 2;
128128 files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t));
129129 }
130+
131+#if defined _BSD_SOURCE || defined _XOPEN_SOURCE && \
132+ ((_XOPEN_SOURCE - 0) >= 500 || defined _XOPEN_SOURCE_EXTENDED)
133+
134+ if ((files[fileidx].path = realpath(filename, NULL)) == NULL) {
135+ warn("could not get real path of file: %s\n", filename);
136+ return;
137+ }
138+#else
130139 if (*filename != '/') {
131− files[fileidx].path = absolute_path(filename);
132− if (files[fileidx].path == NULL) {
140+ if ((files[fileidx].path = absolute_path(filename)) == NULL) {
133141 warn("could not get absolute path of file: %s\n", filename);
134142 return;
135143 }
144+ } else {
145+ files[fileidx].path = NULL;
136146 }
147+#endif
148+
137149 files[fileidx].loaded = false;
138150 files[fileidx].name = s_strdup(filename);
139− if (*filename == '/')
151+ if (files[fileidx].path == NULL)
140152 files[fileidx].path = files[fileidx].name;
141153 if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0')
142154 files[fileidx].base = ++bn;