summaryrefslogtreecommitdiff
path: root/usr.bin/mg/dir.c
blob: 20bfc8a96f77b7b7af830e5e50ba440d6a96ba01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*	$OpenBSD: dir.c,v 1.4 2001/01/29 01:58:06 niklas Exp $	*/

/*
 * Name:	MG 2a
 *		Directory management functions
 * Created:	Ron Flax (ron@vsedev.vse.com)
 *		Modified for MG 2a by Mic Kaczmarczik 03-Aug-1987
 */

#include "def.h"

#ifndef NO_DIR
char           *wdir;
static char     cwd[NFILEN];

/*
 * Initialize anything the directory management routines need
 */
VOID
dirinit()
{

	if (!(wdir = getcwd(cwd, sizeof(cwd))))
		panic("Can't get current directory!");
}

/*
 * Change current working directory
 */
/* ARGSUSED */
int
changedir(f, n)
	int    f, n;
{
	int    s;
	char   bufc[NPAT];

	if ((s = ereply("Change default directory: ", bufc, NPAT)) != TRUE)
		return (s);
	if (bufc[0] == '\0')
		(VOID) strcpy(bufc, wdir);
	if (chdir(bufc) == -1) {
		ewprintf("Can't change dir to %s", bufc);
		return (FALSE);
	} else {
		if (!(wdir = getcwd(cwd, sizeof(cwd))))
			panic("Can't get current directory!");
		ewprintf("Current directory is now %s", wdir);
		return (TRUE);
	}
}

/*
 * Show current directory
 */
/* ARGSUSED */
int
showcwdir(f, n)
{

	ewprintf("Current directory: %s", wdir);
	return (TRUE);
}
#endif