Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_current_dir_name() api implementation #104

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions libs/libc/libc.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 *"
Expand Down
25 changes: 25 additions & 0 deletions libs/libc/unistd/lib_getcwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading