aboutsummaryrefslogtreecommitdiff
path: root/src/lib9pclient/open.c
blob: 2e8e343cd9192581e44bce22e0abf44490bc9bde (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
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <9pclient.h>
#include "fsimpl.h"

int
fsfopen(CFid *fid, int mode)
{
	Fcall tx, rx;

	tx.type = Topen;
	tx.fid = fid->fid;
	tx.mode = mode;
	if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
		return -1;
	fid->mode = mode;
	return 0;
}

CFid*
fsopen(CFsys *fs, char *name, int mode)
{
	char e[ERRMAX];
	CFid *fid;

	if((fid = fswalk(fs->root, name)) == nil)
		return nil;
	if(fsfopen(fid, mode) < 0){
		rerrstr(e, sizeof e);
		fsclose(fid);
		errstr(e, sizeof e);
		return nil;
	}
	fid->mode = mode;
	return fid;
}