133422Sbostic # include "../hdr/macros.h" 233422Sbostic SCCSID(@(#)xcreat 2.1); 333422Sbostic 433422Sbostic /* 533422Sbostic "Sensible" creat: write permission in directory is required in 633422Sbostic all cases, and created file is guaranteed to have specified mode 733422Sbostic and be owned by effective user. 833422Sbostic (It does this by first unlinking the file to be created.) 933422Sbostic Returns file descriptor on success, 1033422Sbostic fatal() on failure. 1133422Sbostic */ 1233422Sbostic 1333422Sbostic xcreat(name,mode) 1433422Sbostic char *name; 1533422Sbostic int mode; 1633422Sbostic { 1733422Sbostic register int fd; 1833422Sbostic register char *d; 1933422Sbostic 2033422Sbostic d = alloca(size(name)); 2133422Sbostic copy(name,d); 22*33425Sbostic if (!exists(dname(d))) { 23*33425Sbostic sprintf(Error,"directory `%s' nonexistent (ut1)",d); 24*33425Sbostic fatal(Error); 25*33425Sbostic } 2633422Sbostic unlink(name); 2733422Sbostic if ((fd = creat(name,mode)) >= 0) 2833422Sbostic return(fd); 2933422Sbostic return(xmsg(name,"xcreat")); 3033422Sbostic } 31