2 * Copyright 2019 Intel Corporation
3 * SPDX-License-Identifier: MIT
11 #if defined(__linux__)
19 readN(int fd
, char *buf
, size_t len
)
24 ssize_t ret
= read(fd
, buf
+ total
, len
- total
);
29 if (ret
== -EINTR
|| ret
== -EAGAIN
)
36 } while (total
!= len
);
38 return total
? total
: err
;
46 char *buf
= malloc(len
);
54 size_t offset
= 0, remaining
= len
- 1;
55 while ((read
= readN(fd
, buf
+ offset
, remaining
)) == remaining
) {
56 char *newbuf
= realloc(buf
, 2 * len
);
67 remaining
= len
- offset
- 1;
81 os_read_file(const char *filename
)
85 int fd
= open(filename
, O_RDONLY
);
87 /* errno set by open() */
92 if (fstat(fd
, &stat
) == 0)
98 /* add NULL terminator */
101 char *buf
= malloc(len
);
108 ssize_t read
= readN(fd
, buf
, len
- 1);
123 os_read_file(const char *filename
)