summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unistd.h1
-rw-r--r--src/misc/get_current_dir_name.c12
2 files changed, 13 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index 95b514ec..7662e518 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -158,6 +158,7 @@ unsigned ualarm(unsigned, unsigned);
int setgroups(size_t, const gid_t []);
int setresuid(uid_t, uid_t, uid_t);
int setresgid(gid_t, gid_t, gid_t);
+char *get_current_dir_name(void);
#endif
#define _XOPEN_VERSION 700
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);
+}