summaryrefslogtreecommitdiff
path: root/sys/src/cmd/bind.c
blob: 36cd9a0cf37a5ffdfbf10ba8e4e830288e18919e (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
#include <u.h>
#include <libc.h>

void	usage(void);

void
main(int argc, char *argv[])
{
	ulong flag = 0;
	int qflag = 0;

	ARGBEGIN{
	case 'a':
		flag |= MAFTER;
		break;
	case 'b':
		flag |= MBEFORE;
		break;
	case 'c':
		flag |= MCREATE;
		break;
	case 'q':
		qflag = 1;
		break;
	default:
		usage();
	}ARGEND

	if(argc != 2 || (flag&MAFTER)&&(flag&MBEFORE))
		usage();

	if(bind(argv[0], argv[1], flag) == -1){
		if(qflag)
			exits(0);
		/* try to give a less confusing error than the default */
		if(access(argv[0], 0) < 0)
			fprint(2, "bind: %s: %r\n", argv[0]);
		else if(access(argv[1], 0) < 0)
			fprint(2, "bind: %s: %r\n", argv[1]);
		else
			fprint(2, "bind %s %s: %r\n", argv[0], argv[1]);
		exits("bind");
	}
	exits(0);
}

void
usage(void)
{
	fprint(2, "usage: bind [-b|-a|-c|-bc|-ac] new old\n");
	exits("usage");
}