44
44
// `read_file_and_null_terminate` reads a file into a NUL-terminated string.
45
45
// On success: returns a NUL-terminated string and (optionally) sets `*out_len` excluding NUL.
46
46
// On error: returns NULL.
47
- static char * read_file_and_null_terminate (const char * filename , size_t * out_len ) {
47
+ static char *
48
+ read_file_and_null_terminate (const char * filename , size_t * out_len )
49
+ {
48
50
BSON_ASSERT_PARAM (filename );
49
51
BSON_OPTIONAL_PARAM (out_len );
50
52
51
53
bool ok = false;
52
- char * contents = NULL ;
54
+ char * contents = NULL ;
53
55
char errmsg_buf [BSON_ERROR_BUFFER_SIZE ];
54
56
55
- FILE * file = fopen (filename , "rb" );
57
+ FILE * file = fopen (filename , "rb" );
56
58
if (!file ) {
57
- MONGOC_ERROR ("Failed to open file: '%s' with error: '%s'" , bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
59
+ MONGOC_ERROR ("Failed to open file: '%s' with error: '%s'" ,
60
+ bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
58
61
goto fail ;
59
62
}
60
63
61
64
if (0 != fseek (file , 0 , SEEK_END )) {
62
- MONGOC_ERROR ("Failed to seek in file: '%s' with error: '%s'" , bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
65
+ MONGOC_ERROR ("Failed to seek in file: '%s' with error: '%s'" ,
66
+ bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
63
67
goto fail ;
64
68
}
65
69
66
70
long file_len = ftell (file );
67
71
if (file_len < 0 ) {
68
- MONGOC_ERROR ("Failed to get length of file: '%s' with error: '%s'" , bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
72
+ MONGOC_ERROR ("Failed to get length of file: '%s' with error: '%s'" ,
73
+ bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
69
74
goto fail ;
70
75
}
71
76
@@ -75,7 +80,8 @@ static char* read_file_and_null_terminate (const char* filename, size_t *out_len
75
80
}
76
81
77
82
if (0 != fseek (file , 0 , SEEK_SET )) {
78
- MONGOC_ERROR ("Failed to seek in file: '%s' with error: '%s'" , bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
83
+ MONGOC_ERROR ("Failed to seek in file: '%s' with error: '%s'" ,
84
+ bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
79
85
goto fail ;
80
86
}
81
87
@@ -87,7 +93,8 @@ static char* read_file_and_null_terminate (const char* filename, size_t *out_len
87
93
MONGOC_ERROR ("Unexpected EOF reading file: '%s'" , filename );
88
94
goto fail ;
89
95
} else {
90
- MONGOC_ERROR ("Failed to read file: '%s' with error: '%s'" , bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
96
+ MONGOC_ERROR ("Failed to read file: '%s' with error: '%s'" ,
97
+ bson_strerror_r (errno , errmsg_buf , sizeof errmsg_buf ));
91
98
goto fail ;
92
99
}
93
100
}
0 commit comments