nuttx: add get_current_dir_name implementation

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
guoshichao
2024-11-26 10:43:46 +08:00
committed by Xiang Xiao
parent d700641921
commit ef6723af9e
3 changed files with 27 additions and 0 deletions
+1
View File
@@ -389,6 +389,7 @@ unsigned int alarm(unsigned int seconds);
int chdir(FAR const char *path);
int fchdir(int fd);
FAR char *getcwd(FAR char *buf, size_t size);
FAR char *get_current_dir_name(void);
/* File path operations */
+1
View File
@@ -97,6 +97,7 @@
"getaddrinfo","netdb.h","defined(CONFIG_LIBC_NETDB)","int","FAR const char *","FAR const char *","FAR const struct addrinfo *","FAR struct addrinfo **"
"getc","stdio.h","","int","FAR FILE *"
"getcwd","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char *","FAR char *","size_t"
"get_current_dir_name","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char *","void"
"getegid","unistd.h","","gid_t"
"geteuid","unistd.h","","uid_t"
"gethostbyname","netdb.h","defined(CONFIG_LIBC_NETDB)","FAR struct hostent *","FAR const char *"
1 __assert assert.h void FAR const char * int FAR const char *
97 getaddrinfo netdb.h defined(CONFIG_LIBC_NETDB) int FAR const char * FAR const char * FAR const struct addrinfo *
98 getc stdio.h int FAR FILE *
99 getcwd unistd.h !defined(CONFIG_DISABLE_ENVIRON) FAR char * FAR char * size_t
100 get_current_dir_name unistd.h !defined(CONFIG_DISABLE_ENVIRON) FAR char * void
101 getegid unistd.h gid_t
102 geteuid unistd.h uid_t
103 gethostbyname netdb.h defined(CONFIG_LIBC_NETDB) FAR struct hostent * FAR const char *
+25
View File
@@ -127,3 +127,28 @@ FAR char *getcwd(FAR char *buf, size_t size)
strlcpy(buf, pwd, size);
return buf;
}
/****************************************************************************
* Name: get_current_dir_name
*
* Description:
* get_current_dir_name() will allocate an buffer to hold the current
* working directory info, and this buffer will be returned to user.
* the user will be responsible to free the buffer.
*
* Input Parameters:
* None
*
* Returned Value:
* On success, get_current_dir_name() returns a pointer to a string
* containing the pathname of the current working directory.
* Otherwise, get_current_dir_name() returns a null pointer and
* sets errno to indicate the error.
* the errno can refer to: getcwd() function's comments.
*
****************************************************************************/
FAR char *get_current_dir_name(void)
{
return getcwd(NULL, 0);
}