File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -9,32 +9,32 @@ Repository: https://github.com/capnramses/pro_programming_tools_c_cpp
99#include <string.h>
1010
1111struct file_record_t {
12- void * data ;
12+ void * data ;
1313 size_t sz ;
1414};
15-
15+
1616struct file_record_t read_file ( const char * filename ) {
17- struct file_record_t record ;
17+ struct file_record_t record ;
1818 memset ( & record , 0 , sizeof ( struct file_record_t ) );
19-
19+
2020 FILE * fp = fopen ( filename , "rb" );
21- if ( !fp ) { return record ; }
21+ if ( !fp ) { return record ; }
2222 fseek ( fp , 0L , SEEK_END );
2323 record .sz = (size_t )ftell ( fp );
2424 record .data = malloc ( record .sz );
2525 rewind ( fp );
2626 fread ( record .data , record .sz , 1 , fp );
2727 fclose ( fp );
28-
28+
2929 return record ;
3030}
3131
3232int main () {
33- struct file_record_t record = read_file ( "in.ppm" );
34- if ( !record .data ) {
35- fprintf ( stderr , "ERROR: reading file `in.ppm`\n" );
36- return 1 ;
37- }
38- printf ( "put entire file `in.ppm` in memory. %u bytes. data %p\n" , (unsigned int )record .sz , (void * )record .data );
39- return 0 ;
33+ struct file_record_t record = read_file ( "in.ppm" );
34+ if ( !record .data ) {
35+ fprintf ( stderr , "ERROR: reading file `in.ppm`\n" );
36+ return 1 ;
37+ }
38+ printf ( "put entire file `in.ppm` in memory. %u bytes. data %p\n" , (unsigned int )record .sz , (void * )record .data );
39+ return 0 ;
4040}
You can’t perform that action at this time.
0 commit comments