summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-02-17 23:10:00 -0500
committerRich Felker <dalias@aerifal.cx>2012-02-17 23:10:00 -0500
commit1611ab0d9b10ad3413f452c2b31a6c1c56dd6939 (patch)
treef4c82d0ca75bf0effdef07915e154d1aa3405b3b /src/misc
parent414a4cdebc45925b59225cca208fee9c658b273e (diff)
downloadmusl-1611ab0d9b10ad3413f452c2b31a6c1c56dd6939.tar.gz
add get_current_dir_name function
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/get_current_dir_name.c12
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);
+}