open_write.c 357 B

1234567891011121314151617
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include "open.h"
  6. int open_write(const char *fn)
  7. {
  8. #ifdef O_CLOEXEC
  9. return open(fn,O_CREAT | O_WRONLY | O_NONBLOCK | O_CLOEXEC,0644);
  10. #else
  11. int fd = open(fn,O_CREAT | O_WRONLY | O_NONBLOCK,0644);
  12. if (fd == -1) return -1;
  13. fcntl(fd,F_SETFD,1);
  14. return fd;
  15. #endif
  16. }