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 xcreat(name,mode)1333422Sbosticxcreat(name,mode) 1433422Sbostic char *name; 1533422Sbostic int mode; 1633422Sbostic { 1733422Sbostic register int fd; 1833422Sbostic register char *d; 1933422Sbostic 20*36472Ssam d = alloc(size(name)); 2133422Sbostic copy(name,d); 2233425Sbostic if (!exists(dname(d))) { 23*36472Ssam free(d); 2433425Sbostic sprintf(Error,"directory `%s' nonexistent (ut1)",d); 2533425Sbostic fatal(Error); 2633425Sbostic } 27*36472Ssam free(d); 2833422Sbostic unlink(name); 2933422Sbostic if ((fd = creat(name,mode)) >= 0) 3033422Sbostic return(fd); 3133422Sbostic return(xmsg(name,"xcreat")); 3233422Sbostic } 33