update to 1.01
[nvi.git] / ex / ex_cd.c
blob13ea7bcec6026375c5f1a151eb42b26b2f4b6804
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_cd.c,v 8.3 1993/12/02 10:47:00 bostic Exp $ (Berkeley) $Date: 1993/12/02 10:47:00 $";
10 #endif /* not lint */
12 #include <sys/param.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
19 #include "vi.h"
20 #include "excmd.h"
23 * ex_cd -- :cd[!] [directory]
24 * Change directories.
26 int
27 ex_cd(sp, ep, cmdp)
28 SCR *sp;
29 EXF *ep;
30 EXCMDARG *cmdp;
32 char *dir, buf[MAXPATHLEN];
34 switch (cmdp->argc) {
35 case 0:
36 if ((dir = getenv("HOME")) == NULL) {
37 msgq(sp, M_ERR,
38 "Environment variable HOME not set.");
39 return (1);
41 break;
42 case 1:
43 dir = cmdp->argv[0]->bp;
44 break;
45 default:
46 abort();
49 if (chdir(dir) < 0) {
50 msgq(sp, M_SYSERR, dir);
51 return (1);
53 if (getcwd(buf, sizeof(buf)) != NULL)
54 msgq(sp, M_INFO, "New directory: %s", buf);
55 return (0);