skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

writenclose_unsafe5.c (517B)


      1 /* ISC license. */
      2 
      3 #include <sys/stat.h>
      4 #include <errno.h>
      5 
      6 #include <skalibs/allreadwrite.h>
      7 #include <skalibs/djbunix.h>
      8 
      9 int writenclose_unsafe5 (int fd, char const *s, size_t len, devino *devino, unsigned int options)
     10 {
     11   if (allwrite(fd, s, len) < len) return 0 ;
     12   if (options & 1 && fd_sync(fd) == -1 && errno != EINVAL) return 0 ;
     13   if (devino)
     14   {
     15     struct stat st ;
     16     if (fstat(fd, &st) == -1) return 0 ;
     17     devino->dev = st.st_dev ;
     18     devino->ino = st.st_ino ;
     19   }
     20   fd_close(fd) ;
     21   return 1 ;
     22 }