@@ -259,35 +259,57 @@ pgFileDelete(pgFile *file)
259
259
}
260
260
261
261
pg_crc32
262
- pgFileGetCRC (const char * file_path )
262
+ pgFileGetCRC (const char * file_path , bool use_crc32c )
263
263
{
264
264
FILE * fp ;
265
265
pg_crc32 crc = 0 ;
266
266
char buf [1024 ];
267
267
size_t len ;
268
268
int errno_tmp ;
269
269
270
+ #define INIT_FILE_CRC32 (crc ) \
271
+ do { \
272
+ if (use_crc32c) \
273
+ INIT_CRC32C(crc); \
274
+ else \
275
+ INIT_TRADITIONAL_CRC32(crc); \
276
+ } while (0)
277
+ #define COMP_FILE_CRC32 (crc , data , len ) \
278
+ do { \
279
+ if (use_crc32c) \
280
+ COMP_CRC32C((crc), (data), (len)); \
281
+ else \
282
+ COMP_TRADITIONAL_CRC32(crc, data, len); \
283
+ } while (0)
284
+ #define FIN_FILE_CRC32 (crc ) \
285
+ do { \
286
+ if (use_crc32c) \
287
+ FIN_CRC32C(crc); \
288
+ else \
289
+ FIN_TRADITIONAL_CRC32(crc); \
290
+ } while (0)
291
+
270
292
/* open file in binary read mode */
271
293
fp = fopen (file_path , PG_BINARY_R );
272
294
if (fp == NULL )
273
295
elog (ERROR , "cannot open file \"%s\": %s" ,
274
296
file_path , strerror (errno ));
275
297
276
298
/* calc CRC of backup file */
277
- INIT_TRADITIONAL_CRC32 (crc );
299
+ INIT_FILE_CRC32 (crc );
278
300
while ((len = fread (buf , 1 , sizeof (buf ), fp )) == sizeof (buf ))
279
301
{
280
302
if (interrupted )
281
303
elog (ERROR , "interrupted during CRC calculation" );
282
- COMP_TRADITIONAL_CRC32 (crc , buf , len );
304
+ COMP_FILE_CRC32 (crc , buf , len );
283
305
}
284
306
errno_tmp = errno ;
285
307
if (!feof (fp ))
286
308
elog (WARNING , "cannot read \"%s\": %s" , file_path ,
287
309
strerror (errno_tmp ));
288
310
if (len > 0 )
289
- COMP_TRADITIONAL_CRC32 (crc , buf , len );
290
- FIN_TRADITIONAL_CRC32 (crc );
311
+ COMP_FILE_CRC32 (crc , buf , len );
312
+ FIN_FILE_CRC32 (crc );
291
313
292
314
fclose (fp );
293
315
0 commit comments