libc: Add a new argument(size_t fulllen) to lib_getfullpath
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
08ababd704
commit
6354a742f1
|
@ -83,7 +83,8 @@ FAR char *__dtoa(double d, int mode, int ndigits, FAR int *decpt,
|
|||
|
||||
/* Defined in lib_getfullpath.c */
|
||||
|
||||
int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath);
|
||||
int lib_getfullpath(int dirfd, FAR const char *path,
|
||||
FAR char *fullpath, size_t fulllen);
|
||||
|
||||
/* Defined in lib_fopen.c */
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -68,7 +68,7 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf,
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
|
||||
int lib_getfullpath(int dirfd, FAR const char *path,
|
||||
FAR char *fullpath, size_t fulllen)
|
||||
{
|
||||
if (path == NULL || fullpath == NULL)
|
||||
{
|
||||
|
@ -52,7 +53,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
|
|||
{
|
||||
/* The path is absolute, then dirfd is ignored. */
|
||||
|
||||
strlcpy(fullpath, path, PATH_MAX);
|
||||
strlcpy(fullpath, path, fulllen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -73,7 +74,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
|
|||
}
|
||||
#endif
|
||||
|
||||
sprintf(fullpath, "%s/%s", pwd, path);
|
||||
snprintf(fullpath, fulllen, "%s/%s", pwd, path);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -85,7 +86,7 @@ int lib_getfullpath(int dirfd, FAR const char *path, FAR char *fullpath)
|
|||
ret = fcntl(dirfd, F_GETPATH, fullpath);
|
||||
if (ret >= 0)
|
||||
{
|
||||
strlcat(fullpath, path, PATH_MAX);
|
||||
strlcat(fullpath, path, fulllen);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -65,7 +65,7 @@ int mkdirat(int dirfd, FAR const char *path, mode_t mode)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -115,7 +115,7 @@ int mkfifoat(int dirfd, FAR const char *path, mode_t mode)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -135,7 +135,7 @@ int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -67,7 +67,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...)
|
|||
mode_t mode = 0;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -67,7 +67,7 @@ int utimensat(int dirfd, FAR const char *path,
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -72,10 +72,12 @@ int renameat(int olddirfd, FAR const char *oldpath,
|
|||
char newfullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(olddirfd, oldpath, oldfullpath);
|
||||
ret = lib_getfullpath(olddirfd, oldpath,
|
||||
oldfullpath, sizeof(oldfullpath));
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = lib_getfullpath(newdirfd, newpath, newfullpath);
|
||||
ret = lib_getfullpath(newdirfd, newpath,
|
||||
newfullpath, sizeof(newfullpath));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
|
|
|
@ -138,7 +138,7 @@ int faccessat(int dirfd, FAR const char *path, int amode, int flags)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -69,7 +69,7 @@ int fchownat(int dirfd, FAR const char *path, uid_t owner,
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -80,10 +80,12 @@ int linkat(int olddirfd, FAR const char *path1,
|
|||
char newfullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(olddirfd, path1, oldfullpath);
|
||||
ret = lib_getfullpath(olddirfd, path1,
|
||||
oldfullpath, sizeof(oldfullpath));
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = lib_getfullpath(newdirfd, path2, newfullpath);
|
||||
ret = lib_getfullpath(newdirfd, path2,
|
||||
newfullpath, sizeof(newfullpath));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
|
|
|
@ -71,7 +71,7 @@ ssize_t readlinkat(int dirfd, FAR const char *path, FAR char *buf,
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -68,7 +68,7 @@ int symlinkat(FAR const char *path1, int dirfd, FAR const char *path2)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path2, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path2, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -69,7 +69,7 @@ int unlinkat(int dirfd, FAR const char *path, int flags)
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
|
@ -54,7 +54,7 @@ int futimesat(int dirfd, FAR const char *path, const struct timeval tv[2])
|
|||
char fullpath[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath);
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
|
|
Loading…
Reference in New Issue