summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-08-02 21:06:22 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-08-02 21:06:22 +0000
commit27454c431f877bc8c4d5e71f5d0d1b244b681d46 (patch)
tree7feda25adafa6fbaf3ba30f1bf44131f8629b6af /lib
parentd0cbf9ff71bdf7744ed72f12709a4e2f56e1c2bd (diff)
downloadcoreutils-27454c431f877bc8c4d5e71f5d0d1b244b681d46.tar.xz
Include <stdbool.h>.
(errno): Remove decl; we now assume C89 or better. (save_cwd): Use bool for booleans. (save_cwd, restore_cwd): Return -1 on failure, not 1, since we set errno on failure.
Diffstat (limited to 'lib')
-rw-r--r--lib/save-cwd.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/save-cwd.c b/lib/save-cwd.c
index 17d077db8..93b1fe85c 100644
--- a/lib/save-cwd.c
+++ b/lib/save-cwd.c
@@ -21,6 +21,7 @@
# include "config.h"
#endif
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,9 +36,6 @@
#endif
#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
#ifndef O_DIRECTORY
# define O_DIRECTORY 0
@@ -66,7 +64,7 @@ extern int errno;
int
save_cwd (struct saved_cwd *cwd)
{
- static int have_working_fchdir = 1;
+ static bool have_working_fchdir = true;
cwd->desc = -1;
cwd->name = NULL;
@@ -80,7 +78,7 @@ save_cwd (struct saved_cwd *cwd)
if (cwd->desc < 0)
{
cwd->name = xgetcwd ();
- return cwd->name == NULL;
+ return cwd->name ? 0 : -1;
}
# if __sun__ || sun
@@ -92,7 +90,7 @@ save_cwd (struct saved_cwd *cwd)
{
close (cwd->desc);
cwd->desc = -1;
- have_working_fchdir = 0;
+ have_working_fchdir = false;
}
else
{
@@ -100,13 +98,13 @@ save_cwd (struct saved_cwd *cwd)
close (cwd->desc);
cwd->desc = -1;
errno = saved_errno;
- return 1;
+ return -1;
}
}
# endif /* __sun__ || sun */
#else
# define fchdir(x) (abort (), 0)
- have_working_fchdir = 0;
+ have_working_fchdir = false;
#endif
}
@@ -114,22 +112,22 @@ save_cwd (struct saved_cwd *cwd)
{
cwd->name = xgetcwd ();
if (cwd->name == NULL)
- return 1;
+ return -1;
}
return 0;
}
/* Change to recorded location, CWD, in directory hierarchy.
- Upon failure, return nonzero (errno is set by chdir or fchdir).
+ Upon failure, return -1 (errno is set by chdir or fchdir).
Upon success, return zero. */
int
restore_cwd (const struct saved_cwd *cwd)
{
if (0 <= cwd->desc)
- return fchdir (cwd->desc) < 0;
+ return fchdir (cwd->desc);
else
- return chdir (cwd->name) < 0;
+ return chdir (cwd->name);
}
void