37 lines
786 B
C
37 lines
786 B
C
#ifndef lint
|
|
static char sccsid[] = "@(#)xcreat.c 1.1 92/07/30 SMI"; /* from System III 3.1 */
|
|
#endif
|
|
|
|
# include <sys/types.h>
|
|
# include "../hdr/macros.h"
|
|
|
|
/*
|
|
"Sensible" creat: write permission in directory is required in
|
|
all cases, and created file is guaranteed to have specified mode
|
|
and be owned by effective user.
|
|
(It does this by first unlinking the file to be created.)
|
|
Returns file descriptor on success,
|
|
fatal() on failure.
|
|
*/
|
|
|
|
xcreat(name,mode)
|
|
char *name;
|
|
int mode;
|
|
{
|
|
register int fd;
|
|
register char *d;
|
|
char *malloc();
|
|
|
|
d = malloc(size(name));
|
|
copy(name,d);
|
|
if (!exists(dname(d))) {
|
|
sprintf(Error,"directory `%s' nonexistent (ut1)",d);
|
|
fatal(Error);
|
|
}
|
|
free(d);
|
|
unlink(name);
|
|
if ((fd = creat(name,mode)) >= 0)
|
|
return(fd);
|
|
return(xmsg(name,"xcreat"));
|
|
}
|