File: savesync.c

package info (click to toggle)
tinyssh 20250501-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,388 kB
  • sloc: ansic: 20,245; sh: 1,582; python: 1,449; makefile: 913
file content (26 lines) | stat: -rw-r--r-- 572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
taken from nacl-20110221, from curvecp/savesync.c
- reformated using clang-format
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "open.h"
#include "savesync.h"
#include "writeall.h"

static int writesync(int fd, const void *x, long long xlen) {
    if (writeall(fd, x, xlen) == -1) return -1;
    return fsync(fd);
}

int savesync(const char *fn, const void *x, long long xlen) {
    int fd;
    int r;
    fd = open_write(fn);
    if (fd == -1) return -1;
    r = writesync(fd, x, xlen);
    close(fd);
    return r;
}