/* Preliminary(?) implementation of the openat family of functions. */
static int
-gen_full_path_at (char *path_ret, int dirfd, const char *pathname)
+gen_full_path_at (char *path_ret, int dirfd, const char *pathname,
+ bool null_pathname_allowed = false)
{
- if (!*pathname)
+ /* Set null_pathname_allowed to true to allow GLIBC compatible behaviour
+ for NULL pathname. Only used by futimesat. */
+ if (!pathname && !null_pathname_allowed)
{
- set_errno (ENOENT);
+ set_errno (EFAULT);
return -1;
}
- if (strlen (pathname) >= PATH_MAX)
+ if (pathname)
{
- set_errno (ENAMETOOLONG);
- return -1;
+ if (!*pathname)
+ {
+ set_errno (ENOENT);
+ return -1;
+ }
+ if (strlen (pathname) >= PATH_MAX)
+ {
+ set_errno (ENAMETOOLONG);
+ return -1;
+ }
}
- if (isdirsep (*pathname))
+ if (pathname && isdirsep (*pathname))
stpcpy (path_ret, pathname);
else
{
set_errno (ENOTDIR);
return -1;
}
- if (p[-1] != '/')
- *p++ = '/';
- stpcpy (p, pathname);
+ if (pathname)
+ {
+ if (p[-1] != '/')
+ *p++ = '/';
+ stpcpy (p, pathname);
+ }
}
return 0;
}
extern "C" int
openat (int dirfd, const char *pathname, int flags, ...)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" int
faccessat (int dirfd, const char *pathname, int mode, int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
int res = -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (!gen_full_path_at (path, dirfd, pathname))
{
extern "C" int
fchmodat (int dirfd, const char *pathname, mode_t mode, int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
fchownat (int dirfd, const char *pathname, __uid32_t uid, __gid32_t gid,
int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" int
fstatat (int dirfd, const char *pathname, struct __stat64 *st, int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
utimensat (int dirfd, const char *pathname, const struct timespec *times,
int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" int
futimesat (int dirfd, const char *pathname, const struct timeval *times)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
- if (gen_full_path_at (path, dirfd, pathname))
+ if (gen_full_path_at (path, dirfd, pathname, true))
return -1;
return utimes (path, times);
}
int newdirfd, const char *newpathname,
int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *oldpath = tp.c_get ();
if (gen_full_path_at (oldpath, olddirfd, oldpathname))
return -1;
extern "C" int
mkdirat (int dirfd, const char *pathname, mode_t mode)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" int
mkfifoat (int dirfd, const char *pathname, mode_t mode)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" int
mknodat (int dirfd, const char *pathname, mode_t mode, __dev32_t dev)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
extern "C" ssize_t
readlinkat (int dirfd, const char *pathname, char *buf, size_t bufsize)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;
renameat (int olddirfd, const char *oldpathname,
int newdirfd, const char *newpathname)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *oldpath = tp.c_get ();
if (gen_full_path_at (oldpath, olddirfd, oldpathname))
return -1;
extern "C" int
symlinkat (const char *oldpath, int newdirfd, const char *newpathname)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *newpath = tp.c_get ();
if (gen_full_path_at (newpath, newdirfd, newpathname))
return -1;
extern "C" int
unlinkat (int dirfd, const char *pathname, int flags)
{
+ tmp_pathbuf tp;
myfault efault;
if (efault.faulted (EFAULT))
return -1;
- tmp_pathbuf tp;
char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname))
return -1;