summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-05-12 09:35:06 +0000
committerJim Meyering <jim@meyering.net>2004-05-12 09:35:06 +0000
commit9549a2091eac2555ff79d29da640c14d0cdf359f (patch)
treea76a28ac73597bef3e67345f58475a6525b73feb /src
parent647df1388910871843e2b60124c5560954f90552 (diff)
downloadcoreutils-9549a2091eac2555ff79d29da640c14d0cdf359f.tar.xz
(AD_pop_and_chdir): Move lstat-`.' into if-block
where the result is used. This avoids one unnecessary lstat call per command line argument.
Diffstat (limited to 'src')
-rw-r--r--src/remove.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/remove.c b/src/remove.c
index a5beceed1..bded9278d 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -371,7 +371,6 @@ AD_pop_and_chdir (Dirstack_state *ds)
/* Get the name of the current directory from the top of the stack. */
char *dir = top_dir (ds);
enum RM_status old_status = AD_stack_top(ds)->status;
- struct stat sb;
struct AD_ent *top;
AD_stack_pop (ds);
@@ -384,6 +383,8 @@ AD_pop_and_chdir (Dirstack_state *ds)
top = AD_stack_top (ds);
if (1 < AD_stack_height (ds))
{
+ struct stat sb;
+
/* We can give a better diagnostic here, since the target is relative. */
if (chdir (".."))
{
@@ -391,25 +392,22 @@ AD_pop_and_chdir (Dirstack_state *ds)
_("cannot chdir from %s to .."),
quote (full_filename (".")));
}
- }
- else
- {
- if (restore_cwd (&top->u.saved_cwd))
- error (EXIT_FAILURE, errno,
- _("failed to return to initial working directory"));
- }
- if (lstat (".", &sb))
- error (EXIT_FAILURE, errno,
- _("cannot lstat `.' in %s"), quote (full_filename (".")));
+ if (lstat (".", &sb))
+ error (EXIT_FAILURE, errno,
+ _("cannot lstat `.' in %s"), quote (full_filename (".")));
- if (1 < AD_stack_height (ds))
- {
/* Ensure that post-chdir dev/ino match the stored ones. */
if ( ! SAME_INODE (sb, top->u.a))
error (EXIT_FAILURE, 0,
_("%s changed dev/ino"), quote (full_filename (".")));
}
+ else
+ {
+ if (restore_cwd (&top->u.saved_cwd))
+ error (EXIT_FAILURE, errno,
+ _("failed to return to initial working directory"));
+ }
return dir;
}