summaryrefslogtreecommitdiff
path: root/src/libstddjb/writevnclose_unsafe5.c
blob: 49b1444c1d24eaa22f40067224734110b0f1765d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* ISC license. */

#include <sys/stat.h>
#include <errno.h>

#include <skalibs/allreadwrite.h>
#include <skalibs/siovec.h>
#include <skalibs/djbunix.h>

int writevnclose_unsafe5 (int fd, struct iovec const *v, unsigned int vlen, devino *devino, unsigned int options)
{
  if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) return 0 ;
  if (options & 1 && fd_sync(fd) == -1 && errno != EINVAL) return 0 ;
  if (devino)
  {
    struct stat st ;
    if (fstat(fd, &st) == -1) return 0 ;
    devino->dev = st.st_dev ;
    devino->ino = st.st_ino ;
  }
  fd_close(fd) ;
  return 1 ;
}