MCPcopy Create free account
hub / github.com/containers/bubblewrap / load_file_data

Function load_file_data

utils.c:598–642  ·  view source on GitHub ↗

Sets errno on error (== NULL), * Always ensures terminating zero */

Source from the content-addressed store, hash-verified

596/* Sets errno on error (== NULL),
597 * Always ensures terminating zero */
598char *
599load_file_data (int fd,
600 size_t *size)
601{
602 cleanup_free char *data = NULL;
603 ssize_t data_read;
604 ssize_t data_len;
605 ssize_t res;
606
607 data_read = 0;
608 data_len = 4080;
609 data = xmalloc (data_len);
610
611 do
612 {
613 if (data_len == data_read + 1)
614 {
615 if (data_len > SSIZE_MAX / 2)
616 {
617 errno = EFBIG;
618 return NULL;
619 }
620
621 data_len *= 2;
622 data = xrealloc (data, data_len);
623 }
624
625 do
626 res = read (fd, data + data_read, data_len - data_read - 1);
627 while (res < 0 && errno == EINTR);
628
629 if (res < 0)
630 return NULL;
631
632 data_read += res;
633 }
634 while (res > 0);
635
636 data[data_read] = 0;
637
638 if (size)
639 *size = (size_t) data_read;
640
641 return steal_pointer (&data);
642}
643
644/* Sets errno on error (== NULL),
645 * Always ensures terminating zero */

Callers 3

load_file_atFunction · 0.85
seccomp_program_newFunction · 0.85
parse_args_recurseFunction · 0.85

Calls 3

xmallocFunction · 0.85
xreallocFunction · 0.85
steal_pointerFunction · 0.85

Tested by

no test coverage detected