fchdir: simplify error handling, and support dup3
authorEric Blake <ebb9@byu.net>
Mon, 31 Aug 2009 20:20:03 +0000 (14:20 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 3 Sep 2009 01:14:43 +0000 (19:14 -0600)
commit4475e25b6a19e31e5783781f2132cdbd05bcf7c4
tree8e8a8793c084d0e534a75896602a77b0218fa079
parent5578788cdb078c97988eb445c2bd848081679e4c
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.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/dup2.c
lib/dup3.c
lib/fchdir.c
lib/fcntl.in.h
lib/open.c
lib/unistd.in.h
m4/dup2.m4
m4/fchdir.m4
modules/fchdir