aboutsummaryrefslogtreecommitdiff
path: root/sys/ki/kfgcwd.x
blob: c142eaa8c84bcaaebcce00fc93e4d24d6df4246f (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<config.h>
include	<mach.h>
include	<chars.h>
include	"ki.h"

# KFGCWD -- Get the name of the current default directory.

procedure kfgcwd (outstr, maxch, nchars)

char	outstr[maxch]		# receives pathname of directory
int	maxch			# max chars out
int	nchars			# length of returned string

int	server, op
int	gstrcpy(), ki_sendrcv()
include	"kinode.com"
include	"kii.com"
define	err_ 91

begin
	# If the current directory resides on the local node pass the zfgcwd
	# request to the local kernel, else pass it to the kernel on the remote
	# (default) node.  Leave the CWD in p_sbuf.

	if (n_default == NULL || n_default == n_local) {
err_	    call zfgcwd (p_sbuf, SZ_SBUF, nchars)
	    call strupk (p_sbuf, p_sbuf, SZ_SBUF)
	    p_arg[2] = 1

	} else {
	    # If the current directory is on a remote node then there must be
	    # a connected kernel server attached to that node.

	    server = n_default

	    if (ki_sendrcv (server, KI_ZFGCWD, 0) == ERR) {
		n_default = n_local
		goto err_
	    }
	}

	# Return node // directory.

	op = gstrcpy (n_defaultnode, outstr, maxch) + 1
	if (op > 1) {
	    outstr[op] = FNNODE_CHAR
	    op = op + 1
	}

	nchars = op + gstrcpy (p_sbuf[p_arg[2]], outstr[op], maxch-op+1)
	call strpak (outstr, outstr, maxch)
end