summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-06-14 06:54:39 +0000
committerJim Meyering <jim@meyering.net>2005-06-14 06:54:39 +0000
commit8c98346f6f1837e1aae8c04dc52f56c04cacefa6 (patch)
tree4d8eb61de2b3e339efaa22ac41cba039775432de /lib
parent57f2a7090ce3653874a0815b572592409e273d7c (diff)
downloadcoreutils-8c98346f6f1837e1aae8c04dc52f56c04cacefa6.tar.xz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/openat.c23
1 files changed, 8 insertions, 15 deletions
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 <errno.h>
#include <fcntl.h>
-#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);