Also handle EINTR for fclose

This commit is contained in:
Kovid Goyal 2025-04-27 10:21:15 +05:30
parent 41899aab14
commit 9ff9e50936
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -224,12 +224,14 @@ read_full_file(const char* filename, size_t *sz) {
rewind(file);
char* buffer = (char*)malloc(file_size + 1); // +1 for the null terminator
if (!buffer) {
errno = EINTR; while (errno == EINTR && fclose(file) != 0);
errno = ENOMEM;
fclose(file);
return NULL;
}
ssize_t q = safe_read_stream(buffer, file_size, file);
fclose(file);
int saved = errno;
errno = EINTR; while (errno == EINTR && fclose(file) != 0);
errno = saved;
if (q < 0) { free(buffer); buffer = NULL; if (sz) *sz = 0; }
else { if (sz) { *sz = q; } buffer[q] = 0; }
return buffer;