MCPcopy Create free account
hub / github.com/RsyncProject/rsync / sparse_end

Function sparse_end

fileio.c:43–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41static OFF_T sparse_past_write = 0;
42
43int sparse_end(int f, OFF_T size, int updating_basis_or_equiv)
44{
45 int ret = 0;
46
47 if (updating_basis_or_equiv) {
48 if (sparse_seek && do_punch_hole(f, sparse_past_write, sparse_seek) < 0)
49 ret = -1;
50#ifdef HAVE_FTRUNCATE /* A compilation formality -- in-place requires ftruncate() */
51 else /* Just in case the original file was longer */
52 ret = do_ftruncate(f, size);
53#endif
54 } else if (sparse_seek) {
55#ifdef HAVE_FTRUNCATE
56 ret = do_ftruncate(f, size);
57#else
58 if (do_lseek(f, sparse_seek-1, SEEK_CUR) != size-1)
59 ret = -1;
60 else {
61 do {
62 ret = write(f, "", 1);
63 } while (ret < 0 && errno == EINTR);
64
65 ret = ret <= 0 ? -1 : 0;
66 }
67#endif
68 }
69
70 sparse_past_write = sparse_seek = 0;
71
72 return ret;
73}
74
75/* Note that the offset is just the caller letting us know where
76 * the current file position is in the file. The use_seek arg tells

Callers 1

receive_dataFunction · 0.85

Calls 3

do_punch_holeFunction · 0.85
do_ftruncateFunction · 0.85
do_lseekFunction · 0.85

Tested by

no test coverage detected