1
0

savesync.c 458 B

123456789101112131415161718192021222324
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include "open.h"
  6. #include "savesync.h"
  7. #include "writeall.h"
  8. static int writesync(int fd,const void *x,long long xlen)
  9. {
  10. if (writeall(fd,x,xlen) == -1) return -1;
  11. return fsync(fd);
  12. }
  13. int savesync(const char *fn,const void *x,long long xlen)
  14. {
  15. int fd;
  16. int r;
  17. fd = open_write(fn);
  18. if (fd == -1) return -1;
  19. r = writesync(fd,x,xlen);
  20. close(fd);
  21. return r;
  22. }