[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils save-cwd.c int cleanup (no bug fixes)
From: |
Paul Eggert |
Subject: |
coreutils save-cwd.c int cleanup (no bug fixes) |
Date: |
Mon, 02 Aug 2004 14:07:56 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
The save-cwd.c functions return 0 on success, 1 on failure (setting errno).
It's more consistent with other functions if they return -1 on failure.
I installed this:
2004-08-02 Paul Eggert <address@hidden>
* save-cwd.c: 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.
Index: lib/save-cwd.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/save-cwd.c,v
retrieving revision 1.19
diff -p -u -r1.19 save-cwd.c
--- lib/save-cwd.c 11 May 2004 18:34:38 -0000 1.19
+++ lib/save-cwd.c 14 Jul 2004 23:56:03 -0000
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils save-cwd.c int cleanup (no bug fixes),
Paul Eggert <=