-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! [LibOS] Make handling of corruption more consistent (WIP)
Signed-off-by: g2flyer <[email protected]>
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "common.h" | ||
|
||
static void read_complete_file(const char* path) { | ||
int fd = open(path, O_RDONLY); | ||
if (fd < 0) { | ||
printf("ERROR: Failed to open input file %s: %s\n", path, strerror(errno)); | ||
return; | ||
} | ||
|
||
char buf[1024]; | ||
while (true) { | ||
ssize_t ret = read(fd, buf, sizeof(buf)); | ||
if (ret < 0) { | ||
if (errno == EAGAIN || errno == EINTR) | ||
continue; | ||
printf("ERROR: Failed to read file %s: %s\n", path, strerror(errno)); | ||
return; | ||
} | ||
if (ret == 0) | ||
break; | ||
} | ||
|
||
if (close(fd) != 0) | ||
printf("ERROR: Failed to close file %s: %s\n", path, strerror(errno)); | ||
} | ||
|
||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 2) | ||
fatal_error("Usage: %s <file_path>\n", argv[0]); | ||
|
||
setup(); | ||
read_complete_file(argv[1]); | ||
return 0; | ||
} |