Punch a hole at pos for len bytes. The current file position must be at pos and will be * changed to be at pos + len. */
| 1559 | /* Punch a hole at pos for len bytes. The current file position must be at pos and will be |
| 1560 | * changed to be at pos + len. */ |
| 1561 | int do_punch_hole(int fd, OFF_T pos, OFF_T len) |
| 1562 | { |
| 1563 | #ifdef HAVE_FALLOCATE |
| 1564 | # ifdef HAVE_FALLOC_FL_PUNCH_HOLE |
| 1565 | if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, pos, len) == 0) { |
| 1566 | if (do_lseek(fd, len, SEEK_CUR) != pos + len) |
| 1567 | return -1; |
| 1568 | return 0; |
| 1569 | } |
| 1570 | # endif |
| 1571 | # ifdef HAVE_FALLOC_FL_ZERO_RANGE |
| 1572 | if (fallocate(fd, FALLOC_FL_ZERO_RANGE, pos, len) == 0) { |
| 1573 | if (do_lseek(fd, len, SEEK_CUR) != pos + len) |
| 1574 | return -1; |
| 1575 | return 0; |
| 1576 | } |
| 1577 | # endif |
| 1578 | #else |
| 1579 | (void)pos; |
| 1580 | #endif |
| 1581 | { |
| 1582 | char zeros[4096]; |
| 1583 | memset(zeros, 0, sizeof zeros); |
| 1584 | while (len > 0) { |
| 1585 | int chunk = len > (int)sizeof zeros ? (int)sizeof zeros : len; |
| 1586 | int wrote = write(fd, zeros, chunk); |
| 1587 | if (wrote <= 0) { |
| 1588 | if (wrote < 0 && errno == EINTR) |
| 1589 | continue; |
| 1590 | return -1; |
| 1591 | } |
| 1592 | len -= wrote; |
| 1593 | } |
| 1594 | } |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
| 1598 | int do_open_nofollow(const char *pathname, int flags) |
| 1599 | { |
no test coverage detected