summaryrefslogtreecommitdiffstats
path: root/bin/sh/cd.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
committerpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
commit5195be912eb257c05a0c97e561e72f01af2583ff (patch)
treee47ab3981b495c675a987dd1e943d1f4c823f314 /bin/sh/cd.c
parent2fc7d7d1fa299368ccdddede67b31695266698bd (diff)
downloadFreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.zip
FreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.tar.gz
Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
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