+2009-09-02 Eric Blake <ebb9@byu.net>
+
+ backupfile, chdir-long, fts, savedir: make safer
+ * lib/backupfile.c (includes): Use "dirent--.h", since
+ numbered_backup can write to stderr during readdir.
+ * lib/savedir.c (includes): Likewise.
+ * lib/chdir-long.c (includes): Use "fcntl--.h", since openat
+ emulation can write to stderr on failure.
+ * lib/fts.c (includes) [!_LIBC]: Likewise for opendir and openat.
+ * lib/getcwd.c: Document why opendir_safer is unused.
+ * lib/glob.c: Likewise.
+ * lib/scandir.c: Likewise.
+ * lib/openat-proc.c: Likewise, for open_safer.
+ * modules/backupfile (Depends-on): Add dirent-safer.
+ * modules/savedir (Depends-on): Likewise.
+ * modules/fts (Depends-on): Add dirent-safer and openat-safer.
+ * modules/chdir-long (Depends-on): Add openat-safer.
+
+ openat-safer: new module
+ * modules/openat-safer: New file.
+ * lib/openat-safer.c: Likewise.
+ * m4/fcntl-safer.m4 (gl_OPENAT_SAFER): New macro.
+ * lib/fcntl-safer.h (openat_safer): Declare.
+ * lib/fcntl--.h (openat): Override.
+ * MODULES.html.sh (File descriptor based I/O): Mention it.
+ * lib/openat.h: Add double-inclusion guards.
+ * lib/openat.c (includes): Only include "fcntl-safer.h", not
+ "fcntl--.h", so we can implement openat.
+ * modules/openat-safer-tests: New test.
+ * tests/test-openat-safer.c: New file.
+
+ dirent-safer: new module
+ * modules/dirent-safer: New file.
+ * lib/dirent--.h: Likewise.
+ * lib/dirent-safer.h: Likewise.
+ * lib/opendir-safer.c: Likewise.
+ * m4/dirent-safer.m4: Likewise.
+ * MODULES.html.sh (Enhancements for POSIX:2008): Mention it.
+ * modules/dirent-safer-tests: New test.
+ * tests/test-dirent-safer.c: New file.
+ * lib/fdopendir.c (includes): Ensure fdopendir is also safe.
+
+ fdopendir: optimize on mingw
+ * lib/unistd.in.h (_gl_directory_name): New prototype.
+ * lib/fchdir.c (_gl_directory_name): Implement it.
+ (fchdir): Use it to simplify implementation.
+ * lib/fdopendir.c (fdopendir) [REPLACE_FCHDIR]: Use metadata from
+ fchdir, when available, to avoid calling [f]chdir().
+
+ fdopendir: split into its own module
+ * lib/openat.c (fdopendir): Move...
+ * lib/fdopendir.c: ...into new file.
+ * modules/fdopendir: New module.
+ * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): New file.
+ * modules/openat (Depends-on): Add fdopendir.
+ * m4/openat.m4 (gl_FUNC_OPENAT): No longer need to check for
+ fdopendir here.
+ * modules/savedir (Depends-on): Only need fdopendir, not full
+ openat.
+ * lib/savedir.c (include): Use <dirent.h>, not "openat.h".
+ * lib/openat.h (fdopendir): Drop prototype.
+ * lib/dirent.in.h (fdopendir): Provide prototype.
+ * m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): Add replacements.
+ * modules/dirent (Makefile.am): Substitute them.
+ * MODULES.html.sh (File system functions): Mention it.
+ * doc/posix-functions/fdopendir.texi (fdopendir): Likewise.
+ * modules/fdopendir-tests: New file.
+ * tests/test-fdopendir.c: Likewise.
+
+ fchdir: use more consistent macro convention
+ * lib/fcntl.in.h (_gl_register_fd): Move declaration to unistd.
+ * lib/sys_stat.in.h (rpl_fstat): Declare via make-time
+ REPLACE_FCHDIR, rather than relying on config.h macros.
+ * lib/unistd.in.h (fchdir): Move all fchdir internal declarations
+ inside a single make-time REPLACE_FCHDIR block, rather than using
+ the config.h FCHDIR_REPLACEMENT.
+ * m4/fchdir.m4 (gl_FUNC_FCHDIR): REPLACE_FCHDIR was already
+ AC_SUBST'd, also AC_DEFINE it. Don't define FCHDIR_REPLACEMENT.
+ Manage fstat replacement.
+ * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Pick up
+ REPLACE_FCHDIR.
+ * modules/sys_stat (Files): Add m4/unistd_h.m4.
+ (Makefile.am): Substitute REPLACE_FCHDIR.
+ * lib/close.c (rpl_close): Use REPLACE_FCHDIR, not
+ FCHDIR_REPLACEMENT.
+ * lib/dup-safer.c (dup_safer): Likewise.
+ * lib/dup2.c (rpl_dup2): Likewise.
+ * lib/dup3.c (rpl_dup3): Likewise.
+ * lib/open.c (rpl_open): Likewise.
+
+ fchdir: simplify error handling, and support dup3
+ * modules/fchdir (Depends-on): Use strdup-posix, not strdup. Add
+ stdbool, malloc-posix, realloc-posix.
+ * lib/fchdir.c (struct dir_info_t): Delete saved_errno.
+ (ensure_dirs_slot): Return false on allocation failure.
+ (rpl_dup2): Delete.
+ (_gl_register_dup): New function.
+ (_gl_unregister_fd, rpl_opendir, rpl_dup): Update callers.
+ (_gl_register_fd): Close fd on allocation failure.
+ * lib/fcntl.in.h (_gl_register_fd): Update signature.
+ * lib/unistd.in.h (_gl_register_dup) [FCHDIR_REPLACEMENT]: New
+ prototype.
+ (rpl_dup2_fchdir): Delete prototype.
+ * lib/open.c (open): Update caller.
+ * lib/dup2.c (dup2): Track fchdir metadata.
+ * lib/dup3.c (dup3): Likewise.
+ * m4/dup2.m4 (gl_REPLACE_DUP2): New macro.
+ * m4/fchdir.m4 (gl_FUNC_FCHDIR): Use it.
+
2009-09-02 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* gnulib-tool (func_create_testdir, func_create_megatestdir): Use