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