summaryrefslogtreecommitdiffstats
path: root/bin/sh/cd.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/cd.c')
-rw-r--r--bin/sh/cd.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 31a0001..34d1bd2 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -33,13 +33,19 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: cd.c,v 1.4 1994/12/26 13:02:05 bde Exp $
+ * $Id: cd.c,v 1.5 1995/11/14 01:04:52 peter Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)cd.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
/*
* The cd and pwd commands.
*/
@@ -52,32 +58,24 @@ static char sccsid[] = "@(#)cd.c 8.1 (Berkeley) 5/31/93";
#include "output.h"
#include "memalloc.h"
#include "error.h"
+#include "redir.h"
#include "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/unistd.h>
-#include <errno.h>
-
-
-#ifdef __STDC__
-STATIC int docd(char *, int);
-STATIC void updatepwd(char *);
-STATIC void getpwd(void);
-STATIC char *getcomponent(void);
-#else
-STATIC int docd();
-STATIC void updatepwd();
-STATIC void getpwd();
-STATIC char *getcomponent();
-#endif
+#include "show.h"
+STATIC int docd __P((char *, int));
+STATIC char *getcomponent __P((void));
+STATIC void updatepwd __P((char *));
+STATIC void getpwd __P((void));
char *curdir; /* current working directory */
char *prevdir; /* previous working directory */
STATIC char *cdcomppath;
int
-cdcmd(argc, argv) char **argv; {
+cdcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char *dest;
char *path;
char *p;
@@ -100,8 +98,7 @@ cdcmd(argc, argv) char **argv; {
if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
path = nullstr;
while ((p = padvance(&path, dest)) != NULL) {
- if (stat(p, &statb) >= 0
- && (statb.st_mode & S_IFMT) == S_IFDIR) {
+ if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
if (!print) {
/*
* XXX - rethink
@@ -116,6 +113,8 @@ cdcmd(argc, argv) char **argv; {
}
}
error("can't cd to %s", dest);
+ /*NOTREACHED*/
+ return 0;
}
@@ -133,6 +132,7 @@ cdcmd(argc, argv) char **argv; {
STATIC int
docd(dest, print)
char *dest;
+ int print;
{
INTOFF;
if (chdir(dest) < 0) {
@@ -153,7 +153,8 @@ docd(dest, print)
STATIC int
docd(dest, print)
char *dest;
- {
+ int print;
+{
register char *p;
register char *q;
char *symlink;
@@ -173,7 +174,7 @@ top:
}
first = 1;
while ((q = getcomponent()) != NULL) {
- if (q[0] == '\0' || q[0] == '.' && q[1] == '\0')
+ if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
continue;
if (! first)
STPUTC('/', p);
@@ -186,7 +187,7 @@ top:
STACKSTRNUL(p);
if (lstat(stackblock(), &statb) < 0)
error("lstat %s failed", stackblock());
- if ((statb.st_mode & S_IFMT) != S_IFLNK)
+ if (!S_ISLNK(statb.st_mode))
continue;
/* Hit a symbolic link. We have to start all over again. */
@@ -316,7 +317,10 @@ updatepwd(dir)
int
-pwdcmd(argc, argv) char **argv; {
+pwdcmd(argc, argv)
+ int argc;
+ char **argv;
+{
getpwd();
out1str(curdir);
out1c('\n');
@@ -367,7 +371,7 @@ getpwd() {
pip[1] = -1;
p = buf;
while ((i = read(pip[0], p, buf + MAXPWD - p)) > 0
- || i == -1 && errno == EINTR) {
+ || (i == -1 && errno == EINTR)) {
if (i > 0)
p += i;
}
OpenPOWER on IntegriCloud