Provide euidaccess, canonicalize_file_name; fix fchmodat.

* syscalls.cc (fchmodat): lchmod is not yet implemented.
(euidaccess): New function.
* path.cc (realpath): Update comment.
(canonicalize_file_name): New function.
* include/cygwin/stdlib.h (canonicalize_file_name): Declare it.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* cygwin.din: Export canonicalize_file_name, eaccess, euidaccess.
* posix.sgml: Mention them.
This commit is contained in:
Eric Blake 2009-09-25 23:55:00 +00:00
parent 358d4e3cb0
commit 2bf78f0928
7 changed files with 65 additions and 12 deletions

View File

@ -1,3 +1,14 @@
2009-09-25 Eric Blake <ebb9@byu.net>
* syscalls.cc (fchmodat): lchmod is not yet implemented.
(euidaccess): New function.
* path.cc (realpath): Update comment.
(canonicalize_file_name): New function.
* include/cygwin/stdlib.h (canonicalize_file_name): Declare it.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* cygwin.din: Export canonicalize_file_name, eaccess, euidaccess.
* posix.sgml: Mention them.
2009-09-25 Eric Blake <ebb9@byu.net> 2009-09-25 Eric Blake <ebb9@byu.net>
* fhandler.h (fhandler_base::fhaccess): Add parameter. * fhandler.h (fhandler_base::fhaccess): Add parameter.

View File

@ -165,6 +165,7 @@ cabsf NOSIGFE
_cabsf = cabsf NOSIGFE _cabsf = cabsf NOSIGFE
calloc SIGFE calloc SIGFE
_calloc = calloc SIGFE _calloc = calloc SIGFE
canonicalize_file_name SIGFE
cbrt NOSIGFE cbrt NOSIGFE
_cbrt = cbrt NOSIGFE _cbrt = cbrt NOSIGFE
cbrtf NOSIGFE cbrtf NOSIGFE
@ -296,6 +297,7 @@ dup SIGFE
_dup = dup SIGFE _dup = dup SIGFE
dup2 SIGFE dup2 SIGFE
_dup2 = dup2 SIGFE _dup2 = dup2 SIGFE
eaccess = euidaccess SIGFE
ecvt SIGFE ecvt SIGFE
_ecvt = ecvt SIGFE _ecvt = ecvt SIGFE
ecvtbuf SIGFE ecvtbuf SIGFE
@ -341,6 +343,7 @@ _erff = erff NOSIGFE
err SIGFE err SIGFE
__errno NOSIGFE __errno NOSIGFE
errx SIGFE errx SIGFE
euidaccess SIGFE
execl SIGFE execl SIGFE
_execl = execl SIGFE _execl = execl SIGFE
execle SIGFE execle SIGFE

View File

@ -1,6 +1,6 @@
/* stdlib.h /* stdlib.h
Copyright 2005, 2006, 2007 Red Hat Inc. Copyright 2005, 2006, 2007, 2008, 2009 Red Hat Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -23,6 +23,7 @@ void setprogname (const char *);
#ifndef __STRICT_ANSI__ #ifndef __STRICT_ANSI__
char *realpath (const char *, char *); char *realpath (const char *, char *);
char *canonicalize_file_name (const char *);
int unsetenv (const char *); int unsetenv (const char *);
char *initstate (unsigned seed, char *state, size_t size); char *initstate (unsigned seed, char *state, size_t size);
long random (void); long random (void);

View File

@ -366,12 +366,13 @@ details. */
210: New ctype layout using variable ctype pointer. Export __ctype_ptr__. 210: New ctype layout using variable ctype pointer. Export __ctype_ptr__.
211: Export fpurge, mkstemps. 211: Export fpurge, mkstemps.
212: Add and export libstdc++ malloc wrappers. 212: Add and export libstdc++ malloc wrappers.
213: Export canonicalize_file_name, eaccess, euidaccess.
*/ */
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0 #define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 212 #define CYGWIN_VERSION_API_MINOR 213
/* There is also a compatibity version number associated with the /* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible shared memory regions. It is incremented when incompatible

View File

@ -2845,7 +2845,7 @@ cygwin_conv_to_full_posix_path (const char *path, char *posix_path)
MAX_PATH); MAX_PATH);
} }
/* The realpath function is supported on some UNIX systems. */ /* The realpath function is required by POSIX:2008. */
extern "C" char * extern "C" char *
realpath (const char *path, char *resolved) realpath (const char *path, char *resolved)
@ -2876,11 +2876,9 @@ realpath (const char *path, char *resolved)
path_conv real_path (tpath, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes); path_conv real_path (tpath, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes);
/* Linux has this funny non-standard extension. If "resolved" is NULL, /* POSIX 2008 requires malloc'ing if resolved is NULL, and states
realpath mallocs the space by itself and returns it to the application. that using non-NULL resolved is asking for portability
The application is responsible for calling free() then. This extension problems. */
is backed by POSIX, which allows implementation-defined behaviour if
"resolved" is NULL. That's good enough for us to do the same here. */
if (!real_path.error && real_path.exists ()) if (!real_path.error && real_path.exists ())
{ {
@ -2894,14 +2892,24 @@ realpath (const char *path, char *resolved)
return resolved; return resolved;
} }
/* FIXME: on error, we are supposed to put the name of the path /* FIXME: on error, Linux puts the name of the path
component which could not be resolved into RESOLVED. */ component which could not be resolved into RESOLVED, but POSIX
does not require this. */
if (resolved) if (resolved)
resolved[0] = '\0'; resolved[0] = '\0';
set_errno (real_path.error ?: ENOENT); set_errno (real_path.error ?: ENOENT);
return NULL; return NULL;
} }
/* Linux provides this extension. Since the only portable use of
realpath requires a NULL second argument, we might as well have a
one-argument wrapper. */
extern "C" char *
canonicalize_file_name (const char *path)
{
return realpath (path, NULL);
}
/* Return non-zero if path is a POSIX path list. /* Return non-zero if path is a POSIX path list.
This is exported to the world as cygwin_foo by cygwin.din. This is exported to the world as cygwin_foo by cygwin.din.

View File

@ -890,6 +890,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
dn_expand dn_expand
dn_skipname dn_skipname
drem drem
eaccess
endusershell endusershell
err err
errx errx
@ -1005,6 +1006,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
asnprintf asnprintf
asprintf asprintf
asprintf_r asprintf_r
canonicalize_file_name
dremf dremf
envz_add envz_add
envz_entry envz_entry
@ -1012,6 +1014,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
envz_merge envz_merge
envz_remove envz_remove
envz_strip envz_strip
euidaccess
exp10 exp10
exp10f exp10f
fcloseall fcloseall

View File

@ -1580,6 +1580,29 @@ access (const char *fn, int flags)
return res; return res;
} }
/* Linux provides this extension; it is basically a wrapper around the
POSIX:2008 faccessat (AT_FDCWD, fn, flags, AT_EACCESS). We also
provide eaccess as an alias for this, in cygwin.din. */
extern "C" int
euidaccess (const char *fn, int flags)
{
// flags were incorrectly specified
int res = -1;
if (flags & ~(F_OK|R_OK|W_OK|X_OK))
set_errno (EINVAL);
else
{
fhandler_base *fh = build_fh_name (fn, NULL, PC_SYM_FOLLOW, stat_suffixes);
if (fh)
{
res = fh->fhaccess (flags, true);
delete fh;
}
}
debug_printf ("returning %d", res);
return res;
}
static void static void
rename_append_suffix (path_conv &pc, const char *path, size_t len, rename_append_suffix (path_conv &pc, const char *path, size_t len,
const char *suffix) const char *suffix)
@ -3878,9 +3901,12 @@ fchmodat (int dirfd, const char *pathname, mode_t mode, int flags)
myfault efault; myfault efault;
if (efault.faulted (EFAULT)) if (efault.faulted (EFAULT))
return -1; return -1;
if (flags & ~AT_SYMLINK_NOFOLLOW) if (flags)
{ {
set_errno (EINVAL); /* BSD has lchmod, but Linux does not. POSIX says
AT_SYMLINK_NOFOLLOW is allowed to fail on symlinks; but Linux
blindly fails even for non-symlinks. */
set_errno ((flags & ~AT_SYMLINK_NOFOLLOW) ? EINVAL : EOPNOTSUPP);
return -1; return -1;
} }
char *path = tp.c_get (); char *path = tp.c_get ();