diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-02-17 23:10:00 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-02-17 23:10:00 -0500 |
commit | 1611ab0d9b10ad3413f452c2b31a6c1c56dd6939 (patch) | |
tree | f4c82d0ca75bf0effdef07915e154d1aa3405b3b /src | |
parent | 414a4cdebc45925b59225cca208fee9c658b273e (diff) | |
download | musl-1611ab0d9b10ad3413f452c2b31a6c1c56dd6939.tar.gz musl-1611ab0d9b10ad3413f452c2b31a6c1c56dd6939.tar.xz musl-1611ab0d9b10ad3413f452c2b31a6c1c56dd6939.zip |
add get_current_dir_name function
Diffstat (limited to 'src')
-rw-r--r-- | src/misc/get_current_dir_name.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/misc/get_current_dir_name.c b/src/misc/get_current_dir_name.c new file mode 100644 index 00000000..212edf31 --- /dev/null +++ b/src/misc/get_current_dir_name.c @@ -0,0 +1,12 @@ +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <unistd.h> + +char *get_current_dir_name(void) { + char buf[PATH_MAX]; + char* res = getenv("PWD"); + if(res && *res) return strdup(res); + if(!getcwd(buf, sizeof(buf))) return NULL; + return strdup(buf); +} |