diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-24 21:04:05 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-24 21:04:05 +0200 |
commit | e7df29252e566e254e9f252d3d3cdce80b8376a7 (patch) | |
tree | f37209c9d443068c3be95ff2b873c534101140e2 /minilib | |
parent | ab9f793cd6d03baf97ca62afa7c42052cafa5ea4 (diff) | |
download | compilertests-e7df29252e566e254e9f252d3d3cdce80b8376a7.tar.gz compilertests-e7df29252e566e254e9f252d3d3cdce80b8376a7.tar.bz2 |
allow reading of an empty file in readallfile
Diffstat (limited to 'minilib')
-rw-r--r-- | minilib/io.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/minilib/io.c b/minilib/io.c index 006f5df..4c56c02 100644 --- a/minilib/io.c +++ b/minilib/io.c @@ -63,11 +63,14 @@ char *readallfile( char *filename ) size = ftell( f ); rewind( f ); - if( size == 0 ) { - return NULL; - } buf = allocate( size + 1 ); + + if( size == 0 ) { + buf[size] = '\0'; + fclose( f ); + return buf; + } if( fread( buf, size, 1, f ) != 1 ) { return NULL; |