open_read.c 326 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_read(const char *fn)
  7. {
  8. #ifdef O_CLOEXEC
  9. return open(fn,O_RDONLY | O_NONBLOCK | O_CLOEXEC);
  10. #else
  11. int fd = open(fn,O_RDONLY | O_NONBLOCK);
  12. if (fd == -1) return -1;
  13. fcntl(fd,F_SETFD,1);
  14. return fd;
  15. #endif
  16. }