MCPcopy Create free account
hub / github.com/coreutils/coreutils / write_zeros

Function write_zeros

src/copy-file-data.c:282–301  ·  view source on GitHub ↗

Write to FD. Write data consisting of N_BYTES' worth of '\0's. Use the buffer *ABUF of size BUF_SIZE for temporary storage, allocating the buffer lazily if *ABUF is null. Return true if successful, false (setting errno) otherwise. */

Source from the content-addressed store, hash-verified

280 allocating the buffer lazily if *ABUF is null.
281 Return true if successful, false (setting errno) otherwise. */
282static bool
283write_zeros (int fd, off_t n_bytes, char **abuf, idx_t buf_size)
284{
285 char *zeros = NULL;
286 while (n_bytes)
287 {
288 idx_t n = MIN (buf_size, n_bytes);
289 if (!zeros)
290 {
291 if (!*abuf)
292 *abuf = xalignalloc (getpagesize (), buf_size);
293 zeros = memset (*abuf, 0, n);
294 }
295 if (full_write (fd, zeros, n) != n)
296 return false;
297 n_bytes -= n;
298 }
299
300 return true;
301}
302
303#ifdef SEEK_HOLE
304/* Perform an efficient extent copy, if possible. This avoids

Callers 2

lseek_copyFunction · 0.85
copy_file_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected