Annotation of src/usr.bin/mg/dir.c, Revision 1.11
1.11 ! vincent 1: /* $OpenBSD: dir.c,v 1.10 2004/03/05 22:02:18 vincent Exp $ */
1.4 niklas 2:
1.1 deraadt 3: /*
4: * Name: MG 2a
5: * Directory management functions
6: * Created: Ron Flax (ron@vsedev.vse.com)
7: * Modified for MG 2a by Mic Kaczmarczik 03-Aug-1987
8: */
9:
10: #include "def.h"
11:
12: #ifndef NO_DIR
1.6 mickey 13: char *wdir;
14: static char cwd[NFILEN];
1.1 deraadt 15:
16: /*
17: * Initialize anything the directory management routines need
18: */
1.5 art 19: void
1.8 vincent 20: dirinit(void)
1.1 deraadt 21: {
1.10 vincent 22: if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL) {
23: ewprintf("Can't get current directory!");
24: chdir("/");
25: strlcpy(cwd, "/", sizeof(cwd));
26: }
1.1 deraadt 27: }
28:
29: /*
30: * Change current working directory
31: */
1.3 millert 32: /* ARGSUSED */
33: int
1.8 vincent 34: changedir(int f, int n)
1.1 deraadt 35: {
1.11 ! vincent 36: char bufc[NPAT], *bufp;
1.1 deraadt 37:
1.11 ! vincent 38: if ((bufp = ereply("Change default directory: ", bufc, NPAT)) == NULL)
! 39: return ABORT;
1.1 deraadt 40: if (bufc[0] == '\0')
1.9 vincent 41: (void)strlcpy(bufc, wdir, sizeof bufc);
1.1 deraadt 42: if (chdir(bufc) == -1) {
43: ewprintf("Can't change dir to %s", bufc);
1.3 millert 44: return (FALSE);
1.1 deraadt 45: } else {
1.9 vincent 46: if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL)
1.1 deraadt 47: panic("Can't get current directory!");
48: ewprintf("Current directory is now %s", wdir);
1.3 millert 49: return (TRUE);
1.1 deraadt 50: }
51: }
52:
53: /*
54: * Show current directory
55: */
1.3 millert 56: /* ARGSUSED */
57: int
1.8 vincent 58: showcwdir(int f, int n)
1.1 deraadt 59: {
1.3 millert 60:
1.1 deraadt 61: ewprintf("Current directory: %s", wdir);
1.3 millert 62: return (TRUE);
1.1 deraadt 63: }
64: #endif