@@ -33,6 +33,11 @@ decompressor.
33
33
#include "gzip_container.h"
34
34
#include "zlib_container.h"
35
35
36
+ /* Windows workaround for stdout output. */
37
+ #if _WIN32
38
+ #include <fcntl.h>
39
+ #endif
40
+
36
41
/*
37
42
Loads a file into a memory array.
38
43
*/
@@ -47,6 +52,10 @@ static void LoadFile(const char* filename,
47
52
48
53
fseek (file , 0 , SEEK_END );
49
54
* outsize = ftell (file );
55
+ if (* outsize > 2147483647 ) {
56
+ fprintf (stderr ,"Files larger than 2GB are not supported.\n" );
57
+ exit (EXIT_FAILURE );
58
+ }
50
59
rewind (file );
51
60
52
61
* out = (unsigned char * )malloc (* outsize );
@@ -71,6 +80,10 @@ Saves a file from a memory array, overwriting the file if it existed.
71
80
static void SaveFile (const char * filename ,
72
81
const unsigned char * in , size_t insize ) {
73
82
FILE * file = fopen (filename , "wb" );
83
+ if (file == NULL ) {
84
+ fprintf (stderr ,"Error: Cannot write to output file, terminating.\n" );
85
+ exit (EXIT_FAILURE );
86
+ }
74
87
assert (file );
75
88
fwrite ((char * )in , 1 , insize , file );
76
89
fclose (file );
@@ -99,10 +112,17 @@ static void CompressFile(const ZopfliOptions* options,
99
112
SaveFile (outfilename , out , outsize );
100
113
} else {
101
114
size_t i ;
115
+ /* Windows workaround for stdout output. */
116
+ #if _WIN32
117
+ _setmode (_fileno (stdout ), _O_BINARY );
118
+ #endif
102
119
for (i = 0 ; i < outsize ; i ++ ) {
103
120
/* Works only if terminal does not convert newlines. */
104
121
printf ("%c" , out [i ]);
105
122
}
123
+ #if _WIN32
124
+ _setmode (_fileno (stdout ), _O_TEXT );
125
+ #endif
106
126
}
107
127
108
128
free (out );
@@ -168,7 +188,7 @@ int main(int argc, char* argv[]) {
168
188
}
169
189
170
190
if (options .numiterations < 1 ) {
171
- fprintf (stderr , "Error: must have 1 or more iterations" );
191
+ fprintf (stderr , "Error: must have 1 or more iterations\n " );
172
192
return 0 ;
173
193
}
174
194
0 commit comments