From 8c98346f6f1837e1aae8c04dc52f56c04cacefa6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 14 Jun 2005 06:54:39 +0000 Subject: Provide an alternative to exiting immediately upon save_cwd or restore_cwd failure. Now, an application can arrange e.g., to perform a longjump in that case. * openat.c: Include dirname.h. Use IS_ABSOLUTE_FILE_NAME rather than testing for leading slash. (rpl_openat, fdopendir, fstatat): Call openat_save_die and openat_restore_die rather than calling error directly. Don't include "error.h" or "exitfail.h"; they're no longer needed. * openat-die.c (openat_save_die, openat_restore_die): New file. * openat.h (openat_save_die, openat_restore_die): Declare and define. --- lib/openat.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'lib/openat.c') diff --git a/lib/openat.c b/lib/openat.c index ec51b2d13..495f4b2f3 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -27,8 +27,7 @@ #include #include -#include "error.h" -#include "exitfail.h" +#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ #include "save-cwd.h" #include "gettext.h" @@ -62,12 +61,11 @@ rpl_openat (int fd, char const *file, int flags, ...) va_end (arg); } - if (fd == AT_FDCWD || *file == '/') + if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file)) return open (file, flags, mode); if (save_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("openat: unable to record current working directory")); + openat_save_die (errno); if (fchdir (fd) != 0) { @@ -81,8 +79,7 @@ rpl_openat (int fd, char const *file, int flags, ...) saved_errno = errno; if (restore_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("openat: unable to restore working directory")); + openat_restore_die (errno); free_cwd (&saved_cwd); @@ -108,8 +105,7 @@ fdopendir (int fd) return opendir ("."); if (save_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("fdopendir: unable to record current working directory")); + openat_save_die (errno); if (fchdir (fd) != 0) { @@ -123,8 +119,7 @@ fdopendir (int fd) saved_errno = errno; if (restore_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("fdopendir: unable to restore working directory")); + openat_restore_die (errno); free_cwd (&saved_cwd); @@ -152,8 +147,7 @@ fstatat (int fd, char const *file, struct stat *st, int flag) : stat (file, st)); if (save_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("fstatat: unable to record current working directory")); + openat_save_die (errno); if (fchdir (fd) != 0) { @@ -169,8 +163,7 @@ fstatat (int fd, char const *file, struct stat *st, int flag) saved_errno = errno; if (restore_cwd (&saved_cwd) != 0) - error (exit_failure, errno, - _("fstatat: unable to restore working directory")); + openat_restore_die (errno); free_cwd (&saved_cwd); -- cgit v1.2.3-54-g00ecf