aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c68
1 files changed, 0 insertions, 68 deletions
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')