Eric Blake [Wed, 23 Sep 2009 20:13:00 +0000 (14:13 -0600)]
lstat: avoid mingw compilation error
The openat module required lstat, but then repeated the checks
for whether lstat worked. When cross-compiling to mingw, this
led to a wrong answer and tried compiling lstat.c, even though it
was not necessary, with a result of a compiler warning about
undeclared lstat.
* m4/lstat.m4 (gl_FUNC_LSTAT): Avoid duplicate calls to
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, and deal with missing
lstat ourselves.
* lib/lstat.c [!HAVE_LSTAT]: Do nothing if <sys/stat.h> override
was adequate.
* m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Let lstat module handle
the checks for lstat.
(gl_SYS_STAT_H_DEFAULTS): Set default for HAVE_LSTAT.
Eric Blake [Mon, 21 Sep 2009 20:40:20 +0000 (14:40 -0600)]
readlink: document portability issue with symlink length
Per comments in areadlink, ERANGE on a too-small buffer is
expected on some platforms; making the readlink module guarantee
GNU behavior of truncated contents is counter-productive, since
we would be duplicating areadlink to learn a-priori how large to
make the buffer, and since truncated contents are not as useful.
* doc/posix-functions/lstat.texi (lstat): Mention that some file
systems have bogus st_size on symlinks, and mention the
areadlink-with-size module.
* doc/posix-functions/fstatat.texi (fstatat): Likewise.
* doc/posix-functions/readlink.texi (readlink): Mention the
areadlink module, and ERANGE failure.
* doc/posix-functions/readlinkat.texi (readlinkat): Likewise.
* tests/test-readlink.c (main): Relax test for AIX, HP-UX.
Eric Blake [Tue, 22 Sep 2009 12:24:25 +0000 (06:24 -0600)]
link-follow: ensure correct result
* m4/fcntl_h.m4 (gl_FCNTL_H): Clean up temporary file.
* m4/link-follow.m4 (gl_FUNC_LINK_FOLLOWS_SYMLINK): Likewise, and
distinguish between possible failures.
Eric Blake [Wed, 16 Sep 2009 23:13:20 +0000 (17:13 -0600)]
unlink: new module, for Solaris 9 bug
unlink("file/") mistakenly succeeded. This patch favors, but
does not enforce, GNU semantics that unlink("link-to-dir/")
flat-out fails rather than attempting to unlink "dir".
Eric Blake [Thu, 17 Sep 2009 21:55:24 +0000 (15:55 -0600)]
lstat: fix Solaris 9 bug
lstat("file/",buf) mistakenly succeeded.
* lib/lstat.c (lstat): Also check for trailing slash on
non-symlink, non-directories. Use stat module to simplify logic.
* doc/posix-functions/lstat.texi (lstat): Document it.
* modules/lstat-tests (Depends-on): Add errno, same-inode.
(configure.ac): Check for symlink.
* tests/test-lstat.c (main): Add more tests.
Eric Blake [Tue, 15 Sep 2009 23:08:39 +0000 (17:08 -0600)]
stat: fix Solaris 9 bug
stat("file/",buf) mistakenly succeeded.
* m4/stat.m4 (gl_FUNC_STAT): Detect Solaris 9 bug with trailing
slash.
* lib/stat.c (rpl_stat): Work around it.
* doc/posix-functions/stat.texi (stat): Update documentation.
Jim Meyering [Thu, 17 Sep 2009 12:15:38 +0000 (14:15 +0200)]
posixtm-tests: revamp
Record only the expected time_t value, not the ctime string.
Skip any test that would require a time_t value larger than
currently representable (e.g., if run with 32-bit time_t,
this skips any test that expects an out-of-range value).
* tests/test-posixtm.c (struct posixtm_test) [valid, t_expected]:
New members.
[expected]: Remove member.
(T): Include new column: valid. Move date strings into comments.
(main): Adapt.
Print a diagnostic for each skipped test.
Don't skip the entire test (exit 77) if time_t is unsigned.
Instead, skip only the individual tests with a negative result.
Jim Meyering [Wed, 16 Sep 2009 08:36:36 +0000 (10:36 +0200)]
posixtm-tests: correct the sole failing test
* tests/test-posixtm.c: Correct 0000-01-01 00:00:00 test so that
expected output matches what mktime now produces. Cross-checked via
erlang's calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}})
* modules/chdir-long (Depends-on): Relax openat-safer to openat.
* modules/save-cwd (Depends-on): Replace fcntl-safer with
unistd-safer.
* lib/chdir-long.c (includes): Replace "fcntl--.h" with
<fcntl.h>; this module does not leak fds.
* lib/openat.c (includes): Do not use "fcntl_safer"; plain openat
must be allowed to return 0, leaving openat_safer to add the
safety.
(openat_permissive): Avoid writing to just-opened fd 2 if
restoring the current directory fails.
* lib/openat-die.c (openat_restore_fail): Add comment.
* lib/save-cwd.c (includes): Make "fcntl--.h" conditional.
(save_cwd): Guarantee safe fd, but without use of open_safer.
* tests/test-openat.c: New test.
* modules/openat-tests (Files, Makefile.am): Distribute and build
new file.
Eric Blake [Sat, 12 Sep 2009 12:04:46 +0000 (06:04 -0600)]
canonicalize: in CAN_ALL_BUT_LAST, allow trailing slash
Coreutils' `readlink -f foo/' should not fail if lstat("foo")
gives ENOENT.
* lib/canonicalize.c (canonicalize_filename_mode): Skip trailing
slashes when checking if last component is missing.
* tests/test-canonicalize.c (main): Test this.
Eric Blake [Thu, 10 Sep 2009 21:44:15 +0000 (15:44 -0600)]
canonicalize-lgpl: use native realpath if it works
Forward-looking to when more platforms comply with POSIX 2008,
but don't provide glibc extensions. For example, this could
fix // handling in cygwin 1.7 (well, if cygwin didn't have bugs
in .. handling). canonicalize can't use native realpath, for
the same reason that it does not use resolvepath.
* lib/canonicalize-lgpl.c (realpath): Guard with
FUNC_REALPATH_WORKS.
* lib/stdlib.in.h (realpath): Make declaration optional based on
HAVE_REALPATH.
* m4/canonicalize-lgpl.m4 (gl_CANONICALIZE_LGPL): Check whether
native realpath works.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Provide default.
* modules/stdlib (Makefile.am): Substitute witness.
Eric Blake [Fri, 11 Sep 2009 18:18:10 +0000 (12:18 -0600)]
canonicalize, canonicalize-lgpl: use <stdlib.h>
Match current gnulib conventions of glibc functions being declared in
the same header as glibc. This makes it easier to replace broken
canonicalize_file_name. canonicalize still requires "canonicalize.h"
because canonicalize_filename_mode is not in glibc. With this patch,
canonicalize-lgpl always provides realpath and canonicalize_file_name,
while canonicalize can provide canonicalize_file_name but not
realpath; if both modules are in use, canonicalize_file_name comes
from the LGPLv2+ sources, but the testing comes from canonicalize.
* modules/canonicalize-lgpl (Files): Drop canonicalize.h.
(Include): Mention <stdlib.h>.
(configure.ac): Mention functions we provide.
* modules/canonicalize (configure.ac): Likewise.
* m4/canonicalize-lgpl.m4 (gl_CANONICALIZE_LGPL): Always replace
realpath if canonicalize_file_name is missing.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Provide defaults.
* modules/stdlib (Makefile.am): Substitute witnesses.
* lib/stdlib.in.h (canonicalize_file_name, realpath): Declare.
* lib/canonicalize-lgpl.c (includes): Adjust accordingly.
* lib/canonicalize.h (canonicalize_file_name): Drop declaration.
* NEWS: Document this.
* doc/glibc-functions/canonicalize_file_name.texi
(canonicalize_file_name): Likewise.
* doc/posix-functions/realpath.texi (realpath): Likewise.
* tests/test-canonicalize-lgpl.c (includes): Use <stdlib.h>.
Eric Blake [Fri, 11 Sep 2009 14:59:54 +0000 (08:59 -0600)]
test-canonicalize-lgpl: consolidate into single C program
Testing canonicalize bugs is easier if the setup can be run under
control of the debugger, rather than in a driver script. As a
bonus side effect, parallel testing with test-canonicalize no
longer competes for the file name "./ise".
* tests/test-canonicalize-lgpl.sh: Delete; move setup into...
* tests/test-canonicalize-lgpl.c (main): ...the program, making it
easier to run in debugger. Add some tests.
* modules/canonicalize-lgpl-tests (Files): Remove unused file.
(configure.ac, Makefile.am): Simplify.
Eric Blake [Fri, 11 Sep 2009 20:57:01 +0000 (14:57 -0600)]
canonicalize: avoid resolvepath
Back when canonicalize merely provided canonicalize_file_name,
resolvepath was more efficient than implementing a complete
realpath. But since resolvepath can't implement other modes for
canonicalize_filename_mode, using it is now just bulk on Solaris.
* m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE): Delete
unnecessary checks.
* lib/canonicalize.c (includes): Simplify.
(canonicalize_file_name): Drop resolvepath implementation.
* modules/canonicalize (Depends-on): Drop filenamecat.
The m4 files were checking whether canonicalize_file_name was
declared, but without enabling extensions, this would never
succeed. Also, mingw failed to compile the module combination of
canonicalize-lgpl and sys_stat, due to a link error on lstat.
* modules/canonicalize (Depends-on): Add extensions, lstat,
pathmax, stdlib.
(Files): Drop pathmax.h.
(configure.ac): Adjust macro name.
* modules/canonicalize-lgpl (Depends-on): Add errno, extensions,
lstat, stdlib, sys_stat.
* m4/canonicalize.m4 (AC_FUNC_CANONICALIZE_FILE_NAME): Rename...
(gl_FUNC_CANONICALIZE_FILENAME_MODE): ...to this, and require
extensions.
* m4/canonicalize-lgpl.m4 (gl_CANONICALIZE_LGPL)
(gl_CANONICALIZE_LGPL_SEPARATE): Require extensions.
(gl_PREREQ_CANONICALIZE_LGPL): Assume unistd.h.
* lib/canonicalize.h (canonicalize_file_name): Use <stdlib.h>
declaration, if available.
* lib/canonicalize-lgpl.c [HAVE_READLINK]: Delete this condition;
we can rely on the readlink module.
(MAXSYMLINKS): Also consult SYMLOOP_MAX.
(includes): Use <unistd.h> unconditionally.
Jim Meyering [Sat, 12 Sep 2009 22:35:49 +0000 (00:35 +0200)]
posixtm: don't reject a time with "60" as the number of seconds
* lib/posixtm.c (posixtime): The code to reject invalid dates would
also reject a time specified with the .60 suffix, whereas POSIX allows
that, in order to accommodate leap seconds. Don't reject that.
(main): Adjust tests accordingly.
* modules/posixtm (Depends-on): Add stpcpy.
Eric Blake [Thu, 10 Sep 2009 02:52:26 +0000 (20:52 -0600)]
getcwd: port to mingw
* m4/getcwd.m4 (gl_FUNC_GETCWD): Mingw directories are very
different from the POSIX assumptions made throughout the getcwd
module; fortunately, the mingw getcwd does not need replacement.
(gl_FUNC_GETCWD_NULL): Skip test on mingw.
* modules/getcwd-tests: New test.
* tests/test-getcwd.c: Likewise.
Eric Blake [Wed, 9 Sep 2009 17:06:44 +0000 (11:06 -0600)]
test-link: consolidate into single C program, test more cases
* tests/test-link.sh: Delete.
* tests/test-link.c: Test more error conditions. Exposes bugs on
at least Cygwin and Solaris.
* modules/link-tests (Files): Remove unused file.
(Depends-on): Add errno, sys_stat.
(Makefile.am): Simplify.