4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-31 11:30:56 +08:00

* path.cc (cygwin_conv_path): Define tp before setting up faul handler.

* syscalls.cc: Ditto, throughout.
	(gen_full_path_at): Add bool parameter to allow NULL pathname.
	(futimesat): Allow NULL pathname as GLIBC.
This commit is contained in:
Corinna Vinschen 2008-05-22 11:18:46 +00:00
parent ae47b14a12
commit b72918135c
3 changed files with 49 additions and 28 deletions

View File

@ -1,3 +1,10 @@
2008-05-22 Corinna Vinschen <corinna@vinschen.de>
* path.cc (cygwin_conv_path): Define tp before setting up faul handler.
* syscalls.cc: Ditto, throughout.
(gen_full_path_at): Add bool parameter to allow NULL pathname.
(futimesat): Allow NULL pathname as GLIBC.
2008-05-21 Christopher Faylor <me+cygwin@cgf.cx> 2008-05-21 Christopher Faylor <me+cygwin@cgf.cx>
* string.h (strchr): Eliminate. * string.h (strchr): Eliminate.

View File

@ -2799,12 +2799,12 @@ extern "C" ssize_t
cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to, cygwin_conv_path (cygwin_conv_path_t what, const void *from, void *to,
size_t size) size_t size)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
path_conv p; path_conv p;
tmp_pathbuf tp;
size_t lsiz = 0; size_t lsiz = 0;
char *buf = NULL; char *buf = NULL;
int error = 0; int error = 0;
@ -2935,11 +2935,11 @@ realpath (const char *path, char *resolved)
/* Guard reading from a potentially invalid path and writing to a /* Guard reading from a potentially invalid path and writing to a
potentially invalid resolved. */ potentially invalid resolved. */
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return NULL; return NULL;
tmp_pathbuf tp;
char *tpath; char *tpath;
if (isdrive (path)) if (isdrive (path))
{ {

View File

@ -3567,8 +3567,18 @@ pclose (FILE *fp)
/* Preliminary(?) implementation of the openat family of functions. */ /* Preliminary(?) implementation of the openat family of functions. */
static int 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)
{ {
/* 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 (EFAULT);
return -1;
}
if (pathname)
{
if (!*pathname) if (!*pathname)
{ {
set_errno (ENOENT); set_errno (ENOENT);
@ -3579,7 +3589,8 @@ gen_full_path_at (char *path_ret, int dirfd, const char *pathname)
set_errno (ENAMETOOLONG); set_errno (ENAMETOOLONG);
return -1; return -1;
} }
if (isdirsep (*pathname)) }
if (pathname && isdirsep (*pathname))
stpcpy (path_ret, pathname); stpcpy (path_ret, pathname);
else else
{ {
@ -3604,20 +3615,23 @@ gen_full_path_at (char *path_ret, int dirfd, const char *pathname)
set_errno (ENOTDIR); set_errno (ENOTDIR);
return -1; return -1;
} }
if (pathname)
{
if (p[-1] != '/') if (p[-1] != '/')
*p++ = '/'; *p++ = '/';
stpcpy (p, pathname); stpcpy (p, pathname);
} }
}
return 0; return 0;
} }
extern "C" int extern "C" int
openat (int dirfd, const char *pathname, int flags, ...) openat (int dirfd, const char *pathname, int flags, ...)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3634,12 +3648,12 @@ openat (int dirfd, const char *pathname, int flags, ...)
extern "C" int extern "C" int
faccessat (int dirfd, const char *pathname, int mode, int flags) faccessat (int dirfd, const char *pathname, int mode, int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
int res = -1; int res = -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (!gen_full_path_at (path, dirfd, pathname)) if (!gen_full_path_at (path, dirfd, pathname))
{ {
@ -3665,10 +3679,10 @@ faccessat (int dirfd, const char *pathname, int mode, int flags)
extern "C" int extern "C" int
fchmodat (int dirfd, const char *pathname, mode_t mode, int flags) fchmodat (int dirfd, const char *pathname, mode_t mode, int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3679,10 +3693,10 @@ extern "C" int
fchownat (int dirfd, const char *pathname, __uid32_t uid, __gid32_t gid, fchownat (int dirfd, const char *pathname, __uid32_t uid, __gid32_t gid,
int flags) int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3693,10 +3707,10 @@ fchownat (int dirfd, const char *pathname, __uid32_t uid, __gid32_t gid,
extern "C" int extern "C" int
fstatat (int dirfd, const char *pathname, struct __stat64 *st, int flags) fstatat (int dirfd, const char *pathname, struct __stat64 *st, int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3709,10 +3723,10 @@ extern "C" int
utimensat (int dirfd, const char *pathname, const struct timespec *times, utimensat (int dirfd, const char *pathname, const struct timespec *times,
int flags) int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3725,12 +3739,12 @@ utimensat (int dirfd, const char *pathname, const struct timespec *times,
extern "C" int extern "C" int
futimesat (int dirfd, const char *pathname, const struct timeval *times) futimesat (int dirfd, const char *pathname, const struct timeval *times)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); 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 -1;
return utimes (path, times); return utimes (path, times);
} }
@ -3740,10 +3754,10 @@ linkat (int olddirfd, const char *oldpathname,
int newdirfd, const char *newpathname, int newdirfd, const char *newpathname,
int flags) int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *oldpath = tp.c_get (); char *oldpath = tp.c_get ();
if (gen_full_path_at (oldpath, olddirfd, oldpathname)) if (gen_full_path_at (oldpath, olddirfd, oldpathname))
return -1; return -1;
@ -3766,10 +3780,10 @@ linkat (int olddirfd, const char *oldpathname,
extern "C" int extern "C" int
mkdirat (int dirfd, const char *pathname, mode_t mode) mkdirat (int dirfd, const char *pathname, mode_t mode)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3779,10 +3793,10 @@ mkdirat (int dirfd, const char *pathname, mode_t mode)
extern "C" int extern "C" int
mkfifoat (int dirfd, const char *pathname, mode_t mode) mkfifoat (int dirfd, const char *pathname, mode_t mode)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3792,10 +3806,10 @@ mkfifoat (int dirfd, const char *pathname, mode_t mode)
extern "C" int extern "C" int
mknodat (int dirfd, const char *pathname, mode_t mode, __dev32_t dev) mknodat (int dirfd, const char *pathname, mode_t mode, __dev32_t dev)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3805,10 +3819,10 @@ mknodat (int dirfd, const char *pathname, mode_t mode, __dev32_t dev)
extern "C" ssize_t extern "C" ssize_t
readlinkat (int dirfd, const char *pathname, char *buf, size_t bufsize) readlinkat (int dirfd, const char *pathname, char *buf, size_t bufsize)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;
@ -3819,10 +3833,10 @@ extern "C" int
renameat (int olddirfd, const char *oldpathname, renameat (int olddirfd, const char *oldpathname,
int newdirfd, const char *newpathname) int newdirfd, const char *newpathname)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *oldpath = tp.c_get (); char *oldpath = tp.c_get ();
if (gen_full_path_at (oldpath, olddirfd, oldpathname)) if (gen_full_path_at (oldpath, olddirfd, oldpathname))
return -1; return -1;
@ -3835,10 +3849,10 @@ renameat (int olddirfd, const char *oldpathname,
extern "C" int extern "C" int
symlinkat (const char *oldpath, int newdirfd, const char *newpathname) symlinkat (const char *oldpath, int newdirfd, const char *newpathname)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *newpath = tp.c_get (); char *newpath = tp.c_get ();
if (gen_full_path_at (newpath, newdirfd, newpathname)) if (gen_full_path_at (newpath, newdirfd, newpathname))
return -1; return -1;
@ -3848,10 +3862,10 @@ symlinkat (const char *oldpath, int newdirfd, const char *newpathname)
extern "C" int extern "C" int
unlinkat (int dirfd, const char *pathname, int flags) unlinkat (int dirfd, const char *pathname, int flags)
{ {
tmp_pathbuf tp;
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
tmp_pathbuf tp;
char *path = tp.c_get (); char *path = tp.c_get ();
if (gen_full_path_at (path, dirfd, pathname)) if (gen_full_path_at (path, dirfd, pathname))
return -1; return -1;