From 7ef312f8a721b99469ea85e33e973475006c6a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 19 Feb 2013 13:17:12 +0100 Subject: [PATCH 2/2] Allow 64-bit stat --- src/code_io.c | 38 ++++++++++++++++++++++++++++++++------ src/indent.h | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/code_io.c b/src/code_io.c index 8c8fd41..8b93188 100644 --- a/src/code_io.c +++ b/src/code_io.c @@ -50,6 +50,8 @@ #include #endif #include +#include +#include #ifdef VMS #include @@ -246,13 +248,18 @@ extern file_buffer_ty * read_file( { static file_buffer_ty fileptr = {NULL}; +#if defined(__MSDOS__) || defined(VMS) /* * size is required to be unsigned for MSDOS, * in order to read files larger than 32767 * bytes in a 16-bit world... */ - unsigned int size; + unsigned int size, size_to_read; +#else + ssize_t size; + size_t size_to_read; +#endif int namelen = strlen(filename); int fd = open(filename, O_RDONLY, 0777); @@ -289,6 +296,10 @@ extern file_buffer_ty * read_file( } } + if (file_stats->st_size > SSIZE_MAX) + { + fatal(_("File %s is too big to read"), filename); + } fileptr.size = file_stats->st_size; if (fileptr.data != 0) @@ -305,11 +316,26 @@ extern file_buffer_ty * read_file( * newline. */ } - size = INDENT_SYS_READ (fd, fileptr.data, fileptr.size); - - if (size == (unsigned int) -1) - { - fatal (_("Error reading input file %s"), filename); + size_to_read = fileptr.size; + while (size_to_read > 0) { + size = INDENT_SYS_READ (fd, fileptr.data + fileptr.size - size_to_read, + size_to_read); + + if (size == +#if defined(__MSDOS__) || defined(VMS) + (unsigned int) +#endif + -1) + { +#if !defined(__MSDOS__) && !defined(VMS) + if (errno == EINTR) + { + continue; + } +#endif + fatal (_("Error reading input file %s"), filename); + } + size_to_read -= size; } if (close (fd) < 0) diff --git a/src/indent.h b/src/indent.h index 60ccb5a..bcb6b64 100644 --- a/src/indent.h +++ b/src/indent.h @@ -106,7 +106,7 @@ typedef unsigned char BOOLEAN; typedef struct file_buffer { char *name; - unsigned long size; + size_t size; char *data; } file_buffer_ty; -- 1.8.1.2