Skip to content

Commit

Permalink
make generate work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
EionRobb committed Jan 1, 2016
1 parent 08b6340 commit 958aeec
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,6 +2951,27 @@ void sig_abrt_handler (int signum __attribute__ ((unused))) {
exit (EXIT_FAILURE);
}

static int
read_all(int fd, void *buf, size_t len)
{
unsigned int rs = 0;
while(rs < len)
{
int rval = read(fd, buf + rs, len - rs);
if (rval == 0)
break;
if (rval < 0)
return rval;

rs += rval;
}
return rs;
}

#ifndef O_BINARY
#define O_BINARY 0
#endif

int main (int argc, char **argv) {
signal (SIGSEGV, sig_segv_handler);
signal (SIGABRT, sig_abrt_handler);
Expand All @@ -2977,12 +2998,12 @@ int main (int argc, char **argv) {
usage ();
}

int fd = open (argv[optind], O_RDONLY);
int fd = open (argv[optind], O_RDONLY | O_BINARY);
if (fd < 0) {
fprintf (stderr, "Can not open file '%s'. Error %m\n", argv[optind]);
exit (1);
}
buf_size = read (fd, buf, (1 << 20));
buf_size = read_all (fd, buf, (1 << 20));
if (fd == (1 << 20)) {
fprintf (stderr, "Too big tlo file\n");
exit (2);
Expand Down

0 comments on commit 958aeec

Please sign in to comment.