aboutsummaryrefslogtreecommitdiff
path: root/sys/ki/kfrnam.x
blob: d2600aaab94fc616d0e5ee934cbcffa7439bedec (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
55
56
57
58
59
60
61
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

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


# KFRNAM -- Rename a file.  Both filenames must refer to the same node.

procedure kfrnam (old_osfn, new_osfn, status)

char	old_osfn[ARB]		#I packed old os filename
char	new_osfn[ARB]		#I packed new os filename
int	status			#O answer; ok or err

pointer	sp, fname
int	server1, server2, old, new
int	ki_connect(), ki_sendrcv(), strlen()
include	"kii.com"

begin
	call smark (sp)
	call salloc (fname, SZ_FNAME, TY_CHAR)

	server2 = ki_connect (new_osfn)
	call strcpy (p_sbuf[p_arg[1]], Memc[fname], SZ_FNAME)
	server1 = ki_connect (old_osfn)
	old = p_arg[1]

	if (server1 == NULL && server2 == NULL) {
	    # Both files reside on the local node.

	    call strpak (p_sbuf[old], p_sbuf[old], SZ_SBUF)
	    call strpak (Memc[fname], Memc[fname], SZ_FNAME)
	    call zfrnam (p_sbuf[old], Memc[fname], status)

	} else if (server1 == server2) {
	    # Both files reside on the same remote node.  Pack the two
	    # filenames into p_sbuf and send the request.

	    new = old + strlen(p_sbuf[old])+1 + 1
	    if (new + strlen(Memc[fname])+1 > SZ_SBUF)
		status = ERR
	    else {
		call strcpy (Memc[fname], p_sbuf[new], SZ_SBUF-new+1)

		p_arg[2]  = new
		p_sbuflen = SZ_SBUF

		if (ki_sendrcv (server1, KI_ZFRNAM, 0) == ERR)
		    status = ERR
		else
		    status = p_arg[1]
	    }

	} else {
	    # One file resides on a remote node.
	    status = ERR
	}

	call sfree (sp)
end