summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);
+}