mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36:28 +08:00
Use lib_get_pathbuffer instead of stack variables
Summary: Modified the usage logic, mainly introduced lib_get_pathbuffer and lib_put_pathbuffer Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
@@ -177,6 +177,7 @@ nl_catd catopen(FAR const char *name, int oflag)
|
||||
FAR const char *lang;
|
||||
FAR const char *p;
|
||||
FAR const char *z;
|
||||
FAR char *buf;
|
||||
|
||||
if (strchr(name, '/'))
|
||||
{
|
||||
@@ -195,9 +196,15 @@ nl_catd catopen(FAR const char *name, int oflag)
|
||||
lang = "";
|
||||
}
|
||||
|
||||
buf = lib_get_pathbuffer();
|
||||
if (buf == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
for (p = path; *p; p = z)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
nl_catd catd;
|
||||
size_t i;
|
||||
|
||||
@@ -261,7 +268,7 @@ nl_catd catopen(FAR const char *name, int oflag)
|
||||
l = 1;
|
||||
}
|
||||
|
||||
if (v == NULL || i + l >= sizeof(buf))
|
||||
if (v == NULL || i + l >= PATH_MAX)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -286,10 +293,12 @@ nl_catd catopen(FAR const char *name, int oflag)
|
||||
catd = catmap(i ? buf : name);
|
||||
if (catd != MAP_FAILED)
|
||||
{
|
||||
lib_put_pathbuffer(buf);
|
||||
return catd;
|
||||
}
|
||||
}
|
||||
|
||||
lib_put_pathbuffer(buf);
|
||||
set_errno(ENOENT);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
@@ -549,9 +549,9 @@ FAR char *dcngettext(FAR const char *domainname,
|
||||
{
|
||||
FAR struct mofile_s *mofile;
|
||||
FAR const char *lang;
|
||||
char path[PATH_MAX];
|
||||
FAR char *notrans;
|
||||
FAR char *trans;
|
||||
FAR char *path;
|
||||
|
||||
notrans = (FAR char *)(n == 1 ? msgid1 : msgid2);
|
||||
|
||||
@@ -576,6 +576,12 @@ FAR char *dcngettext(FAR const char *domainname,
|
||||
lang = "C";
|
||||
}
|
||||
|
||||
path = lib_get_pathbuffer();
|
||||
if (path == NULL)
|
||||
{
|
||||
return notrans;
|
||||
}
|
||||
|
||||
snprintf(path, PATH_MAX,
|
||||
CONFIG_LIBC_LOCALE_PATH"/%s/%s/%s.mo",
|
||||
lang, g_catname[category], domainname);
|
||||
@@ -598,6 +604,7 @@ FAR char *dcngettext(FAR const char *domainname,
|
||||
if (mofile == NULL)
|
||||
{
|
||||
nxmutex_unlock(&g_lock);
|
||||
lib_put_pathbuffer(path);
|
||||
return notrans;
|
||||
}
|
||||
|
||||
@@ -606,6 +613,7 @@ FAR char *dcngettext(FAR const char *domainname,
|
||||
if (mofile->map == MAP_FAILED)
|
||||
{
|
||||
nxmutex_unlock(&g_lock);
|
||||
lib_put_pathbuffer(path);
|
||||
lib_free(mofile);
|
||||
return notrans;
|
||||
}
|
||||
@@ -651,6 +659,7 @@ FAR char *dcngettext(FAR const char *domainname,
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_lock); /* Leave look before search */
|
||||
lib_put_pathbuffer(path);
|
||||
|
||||
trans = molookup(mofile->map, mofile->size, msgid1);
|
||||
if (trans == NULL)
|
||||
|
||||
@@ -66,20 +66,33 @@
|
||||
|
||||
int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((flags & AT_SYMLINK_NOFOLLOW) != 0)
|
||||
{
|
||||
return lchmod(fullpath, mode);
|
||||
ret = lchmod(fullpath, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = chmod(fullpath, mode);
|
||||
}
|
||||
|
||||
return chmod(fullpath, mode);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -67,20 +67,33 @@
|
||||
int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf,
|
||||
int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((flags & AT_SYMLINK_NOFOLLOW) != 0)
|
||||
{
|
||||
return lstat(fullpath, buf);
|
||||
ret = lstat(fullpath, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = stat(fullpath, buf);
|
||||
}
|
||||
|
||||
return stat(fullpath, buf);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <sys/ipc.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -60,9 +61,17 @@
|
||||
|
||||
key_t ftok(FAR const char *pathname, int proj_id)
|
||||
{
|
||||
char fullpath[PATH_MAX] = CONFIG_LIBC_FTOK_VFS_PATH "/";
|
||||
FAR char *fullpath;
|
||||
struct stat st;
|
||||
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
return (key_t)-1;
|
||||
}
|
||||
|
||||
snprintf(fullpath, PATH_MAX, "%s/",
|
||||
CONFIG_LIBC_FTOK_VFS_PATH);
|
||||
strlcat(fullpath, pathname, sizeof(fullpath));
|
||||
if (stat(fullpath, &st) < 0 && get_errno() == ENOENT)
|
||||
{
|
||||
@@ -71,10 +80,12 @@ key_t ftok(FAR const char *pathname, int proj_id)
|
||||
if (mkdir(fullpath, S_IRWXU) < 0 ||
|
||||
stat(fullpath, &st) < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return (key_t)-1;
|
||||
}
|
||||
}
|
||||
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ((key_t)proj_id << 24 |
|
||||
(key_t)(st.st_dev & 0xff) << 16 |
|
||||
(key_t)(st.st_ino & 0xffff));
|
||||
|
||||
@@ -417,11 +417,17 @@ int glob(FAR const char *pat, int flags,
|
||||
size_t i;
|
||||
size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0;
|
||||
int error = 0;
|
||||
char buf[PATH_MAX];
|
||||
FAR char *buf;
|
||||
|
||||
head.next = NULL;
|
||||
head.name[0] = '\0';
|
||||
|
||||
buf = lib_get_pathbuffer();
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!errfunc)
|
||||
{
|
||||
errfunc = ignore_err;
|
||||
@@ -442,6 +448,7 @@ int glob(FAR const char *pat, int flags,
|
||||
|
||||
if (!p)
|
||||
{
|
||||
lib_put_pathbuffer(buf);
|
||||
return GLOB_NOSPACE;
|
||||
}
|
||||
|
||||
@@ -453,6 +460,7 @@ int glob(FAR const char *pat, int flags,
|
||||
lib_free(p);
|
||||
}
|
||||
|
||||
lib_put_pathbuffer(buf);
|
||||
if (error == GLOB_NOSPACE)
|
||||
{
|
||||
freelist(&head);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <nuttx/lib/lib.h>
|
||||
|
||||
#if defined(CONFIG_LIBC_MEMFD_TMPFS) || defined(CONFIG_LIBC_MEMFD_SHMFS)
|
||||
/****************************************************************************
|
||||
@@ -54,10 +55,17 @@ int memfd_create(FAR const char *name, unsigned int flags)
|
||||
set_errno(ENOSYS);
|
||||
return -1;
|
||||
#else
|
||||
char path[PATH_MAX];
|
||||
FAR char *path;
|
||||
int ret;
|
||||
|
||||
snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH_FMT, name);
|
||||
path = lib_get_pathbuffer();
|
||||
if (path == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(path, PATH_MAX, LIBC_MEM_FD_VFS_PATH_FMT, name);
|
||||
# ifdef CONFIG_LIBC_MEMFD_SHMFS
|
||||
ret = shm_open(path, O_RDWR | flags, 0660);
|
||||
if (ret >= 0)
|
||||
@@ -73,6 +81,7 @@ int memfd_create(FAR const char *name, unsigned int flags)
|
||||
}
|
||||
# endif
|
||||
|
||||
lib_put_pathbuffer(path);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -64,15 +64,25 @@
|
||||
|
||||
int mkdirat(int dirfd, FAR const char *path, mode_t mode)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return mkdir(fullpath, mode);
|
||||
ret = mkdir(fullpath, mode);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -114,17 +114,27 @@ int mkfifo(FAR const char *pathname, mode_t mode)
|
||||
|
||||
int mkfifoat(int dirfd, FAR const char *path, mode_t mode)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return mkfifo(fullpath, mode);
|
||||
ret = mkfifo(fullpath, mode);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PIPES && CONFIG_DEV_FIFO_SIZE > 0 */
|
||||
|
||||
@@ -134,15 +134,25 @@ int mknod(FAR const char *path, mode_t mode, dev_t dev)
|
||||
|
||||
int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return mknod(fullpath, mode, dev);
|
||||
ret = mknod(fullpath, mode, dev);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -65,13 +65,21 @@
|
||||
|
||||
int openat(int dirfd, FAR const char *path, int oflags, ...)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
mode_t mode = 0;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
@@ -85,5 +93,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
return open(fullpath, oflags, mode);
|
||||
ret = open(fullpath, oflags, mode);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -66,20 +66,33 @@
|
||||
int utimensat(int dirfd, FAR const char *path,
|
||||
const struct timespec times[2], int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((flags & AT_SYMLINK_NOFOLLOW) != 0)
|
||||
{
|
||||
return lutimens(fullpath, times);
|
||||
ret = lutimens(fullpath, times);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = utimens(fullpath, times);
|
||||
}
|
||||
|
||||
return utimens(fullpath, times);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -70,23 +70,43 @@
|
||||
int renameat(int olddirfd, FAR const char *oldpath,
|
||||
int newdirfd, FAR const char *newpath)
|
||||
{
|
||||
char oldfullpath[PATH_MAX];
|
||||
char newfullpath[PATH_MAX];
|
||||
FAR char *oldfullpath;
|
||||
FAR char *newfullpath;
|
||||
int ret;
|
||||
|
||||
oldfullpath = lib_get_pathbuffer();
|
||||
if (oldfullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
newfullpath = lib_get_pathbuffer();
|
||||
if (newfullpath == NULL)
|
||||
{
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(olddirfd, oldpath,
|
||||
oldfullpath, sizeof(oldfullpath));
|
||||
oldfullpath, PATH_MAX);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = lib_getfullpath(newdirfd, newpath,
|
||||
newfullpath, sizeof(newfullpath));
|
||||
newfullpath, PATH_MAX);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
lib_put_pathbuffer(newfullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return rename(oldfullpath, newfullpath);
|
||||
ret = rename(oldfullpath, newfullpath);
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
lib_put_pathbuffer(newfullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -137,15 +137,25 @@ int access(FAR const char *path, int amode)
|
||||
|
||||
int faccessat(int dirfd, FAR const char *path, int amode, int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return access(fullpath, amode);
|
||||
ret = access(fullpath, amode);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <nuttx/lib/lib.h>
|
||||
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
|
||||
@@ -66,16 +68,26 @@
|
||||
|
||||
int fchdir(int fd)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
FAR char *path;
|
||||
int ret;
|
||||
|
||||
path = lib_get_pathbuffer();
|
||||
if (path == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = fcntl(fd, F_GETPATH, path);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return chdir(path);
|
||||
ret = chdir(path);
|
||||
lib_put_pathbuffer(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ENVIRON */
|
||||
|
||||
@@ -68,20 +68,33 @@
|
||||
int fchownat(int dirfd, FAR const char *path, uid_t owner,
|
||||
gid_t group, int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((flags & AT_SYMLINK_NOFOLLOW) != 0)
|
||||
{
|
||||
return lchown(fullpath, owner, group);
|
||||
ret = lchown(fullpath, owner, group);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = chown(fullpath, owner, group);
|
||||
}
|
||||
|
||||
return chown(fullpath, owner, group);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -78,25 +78,45 @@
|
||||
int linkat(int olddirfd, FAR const char *path1,
|
||||
int newdirfd, FAR const char *path2, int flags)
|
||||
{
|
||||
char oldfullpath[PATH_MAX];
|
||||
char newfullpath[PATH_MAX];
|
||||
FAR char *oldfullpath;
|
||||
FAR char *newfullpath;
|
||||
int ret;
|
||||
|
||||
oldfullpath = lib_get_pathbuffer();
|
||||
if (oldfullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
newfullpath = lib_get_pathbuffer();
|
||||
if (newfullpath == NULL)
|
||||
{
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(olddirfd, path1,
|
||||
oldfullpath, sizeof(oldfullpath));
|
||||
oldfullpath, PATH_MAX);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = lib_getfullpath(newdirfd, path2,
|
||||
newfullpath, sizeof(newfullpath));
|
||||
newfullpath, PATH_MAX);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
lib_put_pathbuffer(newfullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return link(oldfullpath, newfullpath);
|
||||
ret = link(oldfullpath, newfullpath);
|
||||
lib_put_pathbuffer(oldfullpath);
|
||||
lib_put_pathbuffer(newfullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PSEUDOFS_SOFTLINKS */
|
||||
|
||||
@@ -70,17 +70,27 @@
|
||||
ssize_t readlinkat(int dirfd, FAR const char *path, FAR char *buf,
|
||||
size_t bufsize)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return readlink(fullpath, buf, bufsize);
|
||||
ret = readlink(fullpath, buf, bufsize);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PSEUDOFS_SOFTLINKS */
|
||||
|
||||
@@ -67,17 +67,27 @@
|
||||
|
||||
int symlinkat(FAR const char *path1, int dirfd, FAR const char *path2)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path2, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path2, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return symlink(path1, fullpath);
|
||||
ret = symlink(path1, fullpath);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PSEUDOFS_SOFTLINKS */
|
||||
|
||||
@@ -68,20 +68,33 @@
|
||||
|
||||
int unlinkat(int dirfd, FAR const char *path, int flags)
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if ((flags & AT_REMOVEDIR) != 0)
|
||||
{
|
||||
return rmdir(fullpath);
|
||||
ret = rmdir(fullpath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = unlink(fullpath);
|
||||
}
|
||||
|
||||
return unlink(fullpath);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -53,15 +53,25 @@ int utimes(FAR const char *path, const struct timeval tv[2])
|
||||
|
||||
int futimesat(int dirfd, FAR const char *path, const struct timeval tv[2])
|
||||
{
|
||||
char fullpath[PATH_MAX];
|
||||
FAR char *fullpath;
|
||||
int ret;
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath));
|
||||
fullpath = lib_get_pathbuffer();
|
||||
if (fullpath == NULL)
|
||||
{
|
||||
set_errno(ENOMEM);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = lib_getfullpath(dirfd, path, fullpath, PATH_MAX);
|
||||
if (ret < 0)
|
||||
{
|
||||
lib_put_pathbuffer(fullpath);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return utimes(fullpath, tv);
|
||||
ret = utimes(fullpath, tv);
|
||||
lib_put_pathbuffer(fullpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user