nsxiv6d7acac
Use real path of all files internally, requires _XOPEN_SOURCE>=500, fixes issue #137
+22 −9
2 files changed
| @@ -1,12 +1,13 @@ | |||
| 1 | − | VERSION = git-20140218 | |
| 1 | + | VERSION = git-20140317 | |
| 2 | 2 | ||
| 3 | 3 | PREFIX = /usr/local | |
| 4 | 4 | MANPREFIX = $(PREFIX)/share/man | |
| 5 | 5 | ||
| 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 | |
| 10 | 11 | ||
| 11 | 12 | SRC = commands.c exif.c image.c main.c options.c thumbs.c util.c window.c | |
| 12 | 13 | OBJ = $(SRC:.c=.o) | |
| @@ -16,7 +17,7 @@ all: sxiv | |||
| 16 | 17 | $(OBJ): Makefile config.h | |
| 17 | 18 | ||
| 18 | 19 | .c.o: | |
| 19 | − | $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< | |
| 20 | + | $(CC) $(CFLAGS) $(CPPFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< | |
| 20 | 21 | ||
| 21 | 22 | config.h: | |
| 22 | 23 | cp config.def.h $@ | |
| @@ -127,16 +127,28 @@ void check_add_file(char *filename) | |||
| 127 | 127 | filecnt *= 2; | |
| 128 | 128 | files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t)); | |
| 129 | 129 | } | |
| 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 | |
| 130 | 139 | if (*filename != '/') { | |
| 131 | − | files[fileidx].path = absolute_path(filename); | |
| 132 | − | if (files[fileidx].path == NULL) { | |
| 140 | + | if ((files[fileidx].path = absolute_path(filename)) == NULL) { | |
| 133 | 141 | warn("could not get absolute path of file: %s\n", filename); | |
| 134 | 142 | return; | |
| 135 | 143 | } | |
| 144 | + | } else { | |
| 145 | + | files[fileidx].path = NULL; | |
| 136 | 146 | } | |
| 147 | + | #endif | |
| 148 | + | ||
| 137 | 149 | files[fileidx].loaded = false; | |
| 138 | 150 | files[fileidx].name = s_strdup(filename); | |
| 139 | − | if (*filename == '/') | |
| 151 | + | if (files[fileidx].path == NULL) | |
| 140 | 152 | files[fileidx].path = files[fileidx].name; | |
| 141 | 153 | if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0') | |
| 142 | 154 | files[fileidx].base = ++bn; | |