summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--src/remove.c44
2 files changed, 22 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 5152963aa..2f19911ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-11-26 Paul Eggert <eggert@cs.ucla.edu>
+
+ Port parts of the code to C89 to minimize the need for c99-to-c89.diff,
+ while trying to retain the readability of C99 as much as possible.
+ * src/remove.c (close_preserve_errno): Remove.
+ (fd_to_subdirp): Rewrite to avoid the need for decl after statement.
+
2006-11-25 Paul Eggert <eggert@cs.ucla.edu>
* src/remove.c (rm_1): Remove decl of local, fd_cwd.
diff --git a/src/remove.c b/src/remove.c
index 06d2f82b4..4728bdd3a 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -148,16 +148,6 @@ struct dirstack_state
};
typedef struct dirstack_state Dirstack_state;
-/* Just like close(fd), but don't modify errno. */
-static inline int
-close_preserve_errno (int fd)
-{
- int saved_errno = errno;
- int result = close (fd);
- errno = saved_errno;
- return result;
-}
-
/* Like fstatat, but cache the result. If ST->st_size is -1, the
status has not been gotten yet. If less than -1, fstatat failed
with errno == -1 - ST->st_size. Otherwise, the status has already
@@ -1121,32 +1111,28 @@ fd_to_subdirp (int fd_cwd, char const *f,
{
int open_flags = O_RDONLY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK;
int fd_sub = openat_permissive (fd_cwd, f, open_flags, 0, cwd_errno);
+ int saved_errno;
/* Record dev/ino of F. We may compare them against saved values
to thwart any attempt to subvert the traversal. They are also used
to detect directory cycles. */
- if (fd_sub < 0 || fstat (fd_sub, subdir_sb) != 0)
- {
- if (0 <= fd_sub)
- close_preserve_errno (fd_sub);
- return NULL;
- }
-
- if (! S_ISDIR (subdir_sb->st_mode))
+ if (fd_sub < 0)
+ return NULL;
+ else if (fstat (fd_sub, subdir_sb) != 0)
+ saved_errno = errno;
+ else if (S_ISDIR (subdir_sb->st_mode))
{
- errno = prev_errno ? prev_errno : ENOTDIR;
- close_preserve_errno (fd_sub);
- return NULL;
- }
-
- DIR *subdir_dirp = fdopendir (fd_sub);
- if (subdir_dirp == NULL)
- {
- close_preserve_errno (fd_sub);
- return NULL;
+ DIR *subdir_dirp = fdopendir (fd_sub);
+ if (subdir_dirp)
+ return subdir_dirp;
+ saved_errno = errno;
}
+ else
+ saved_errno = (prev_errno ? prev_errno : ENOTDIR);
- return subdir_dirp;
+ close (fd_sub);
+ errno = saved_errno;
+ return NULL;
}
/* Remove entries in the directory open on DIRP