mirror of git://git.musl-libc.org/musl
add get_current_dir_name function
This commit is contained in:
parent
414a4cdebc
commit
1611ab0d9b
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue