diff options
Diffstat (limited to 'core/path.c')
-rw-r--r-- | core/path.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/path.c b/core/path.c index ed53d5d465..e373df21ab 100644 --- a/core/path.c +++ b/core/path.c @@ -31,6 +31,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#include <errno.h> #include "config.h" #include "core/mp_msg.h" #include "core/path.h" @@ -178,6 +179,19 @@ char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2) have_separator ? "" : "/", BSTR_P(p2)); } +char *mp_getcwd(void *talloc_ctx) +{ + char *wd = talloc_array(talloc_ctx, char, 20); + while (getcwd(wd, talloc_get_size(wd)) == NULL) { + if (errno != ERANGE) { + talloc_free(wd); + return NULL; + } + wd = talloc_realloc(talloc_ctx, wd, char, talloc_get_size(wd) * 2); + } + return wd; +} + bool mp_path_exists(const char *path) { struct stat st; |