From 9a7e97cd89b307ecc0cd2f304919b576cb5704d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 28 Oct 2015 21:52:41 +0100 Subject: Use XSI realpath(3) --- main.c | 15 --------------- util.c | 68 ------------------------------------------------------------------ util.h | 2 -- 3 files changed, 85 deletions(-) diff --git a/main.c b/main.c index a03f5a4..96ea947 100644 --- a/main.c +++ b/main.c @@ -131,27 +131,12 @@ void check_add_file(char *filename, bool given) memset(&files[filecnt/2], 0, filecnt/2 * sizeof(*files)); } -#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 != '/') { - 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].name = s_strdup(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; else diff --git a/util.c b/util.c index 01a26d4..49d9fd0 100644 --- a/util.c +++ b/util.c @@ -106,74 +106,6 @@ void size_readable(float *size, const char **unit) *unit = units[MIN(i, ARRLEN(units) - 1)]; } -char* absolute_path(const char *filename) -{ - size_t len; - const char *basename; - char *dir, *dirname = NULL, *path = NULL, *s; - char *cwd = NULL, *twd = NULL; - - if (*filename == '\0' || *filename == '/') - return NULL; - - len = FNAME_LEN; - cwd = (char*) s_malloc(len); - while ((s = getcwd(cwd, len)) == NULL && errno == ERANGE) { - len *= 2; - cwd = (char*) s_realloc(cwd, len); - } - if (s == NULL) - goto error; - - s = strrchr(filename, '/'); - if (s != NULL) { - len = s - filename; - dirname = (char*) s_malloc(len + 1); - strncpy(dirname, filename, len); - dirname[len] = '\0'; - basename = s + 1; - - if (chdir(cwd) < 0) - /* we're not able to come back afterwards */ - goto error; - if (chdir(dirname) < 0) - goto error; - - len = FNAME_LEN; - twd = (char*) s_malloc(len); - while ((s = getcwd(twd, len)) == NULL && errno == ERANGE) { - len *= 2; - twd = (char*) s_realloc(twd, len); - } - if (chdir(cwd) < 0) - die("could not revert to prior working directory"); - if (s == NULL) - goto error; - dir = twd; - } else { - /* only a single filename given */ - basename = filename; - dir = cwd; - } - - len = strlen(dir) + strlen(basename) + 2; - path = (char*) s_malloc(len); - snprintf(path, len, "%s/%s", dir, basename); - - goto end; - -error: - free(path); - path = NULL; - -end: - free(dirname); - free(cwd); - free(twd); - - return path; -} - int r_opendir(r_dir_t *rdir, const char *dirname) { if (*dirname == '\0') diff --git a/util.h b/util.h index 692abba..c0ac98f 100644 --- a/util.h +++ b/util.h @@ -70,8 +70,6 @@ void die(const char*, ...); void size_readable(float*, const char**); -char* absolute_path(const char*); - int r_opendir(r_dir_t*, const char*); int r_closedir(r_dir_t*); char* r_readdir(r_dir_t*); -- cgit v1.2.3