home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libbsd42 / fopenexcl.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  415b  |  21 lines

  1. /*
  2.  * fopenexcl(name) - fopen(name, "w") with error if name exists (Berklix)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/file.h>        /* 4.2's O_EXCL defn */
  8.  
  9. FILE *
  10. fopenexcl(name)
  11. register char *name;
  12. {
  13.     /* This is the cheaper way. */
  14.     register int fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0666);
  15.  
  16.     if (fd < 0)
  17.         return NULL;        /* name existed or couldn't be made */
  18.     else
  19.         return fdopen(fd, "w");
  20. }
  21.