1*33422Sbostic # include	"../hdr/macros.h"
2*33422Sbostic SCCSID(@(#)xcreat	2.1);
3*33422Sbostic 
4*33422Sbostic /*
5*33422Sbostic 	"Sensible" creat: write permission in directory is required in
6*33422Sbostic 	all cases, and created file is guaranteed to have specified mode
7*33422Sbostic 	and be owned by effective user.
8*33422Sbostic 	(It does this by first unlinking the file to be created.)
9*33422Sbostic 	Returns file descriptor on success,
10*33422Sbostic 	fatal() on failure.
11*33422Sbostic */
12*33422Sbostic 
13*33422Sbostic xcreat(name,mode)
14*33422Sbostic char *name;
15*33422Sbostic int mode;
16*33422Sbostic {
17*33422Sbostic 	register int fd;
18*33422Sbostic 	register char *d;
19*33422Sbostic 
20*33422Sbostic 	d = alloca(size(name));
21*33422Sbostic 	copy(name,d);
22*33422Sbostic 	if (!exists(dname(d)))
23*33422Sbostic 		fatal(sprintf(Error,"directory `%s' nonexistent (ut1)",d));
24*33422Sbostic 	unlink(name);
25*33422Sbostic 	if ((fd = creat(name,mode)) >= 0)
26*33422Sbostic 		return(fd);
27*33422Sbostic 	return(xmsg(name,"xcreat"));
28*33422Sbostic }
29