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

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 */

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 *"

Can't render this file because it has a wrong number of fields in line 3.

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);
}