| 1363 | } |
| 1364 | |
| 1365 | static bool |
| 1366 | digest_check (char const *checkfile_name) |
| 1367 | { |
| 1368 | FILE *checkfile_stream; |
| 1369 | intmax_t n_misformatted_lines = 0; |
| 1370 | intmax_t n_mismatched_checksums = 0; |
| 1371 | intmax_t n_open_or_read_failures = 0; |
| 1372 | bool properly_formatted_lines = false; |
| 1373 | bool matched_checksums = false; |
| 1374 | unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN]; |
| 1375 | /* Make sure bin_buffer is properly aligned. */ |
| 1376 | unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN); |
| 1377 | intmax_t line_number; |
| 1378 | char *line; |
| 1379 | size_t line_chars_allocated; |
| 1380 | bool is_stdin = streq (checkfile_name, "-"); |
| 1381 | |
| 1382 | if (is_stdin) |
| 1383 | { |
| 1384 | have_read_stdin = true; |
| 1385 | checkfile_name = _("standard input"); |
| 1386 | checkfile_stream = stdin; |
| 1387 | } |
| 1388 | else |
| 1389 | { |
| 1390 | checkfile_stream = fopen (checkfile_name, "r"); |
| 1391 | if (checkfile_stream == NULL) |
| 1392 | { |
| 1393 | error (0, errno, "%s", quotef (checkfile_name)); |
| 1394 | return false; |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | line_number = 0; |
| 1399 | line = NULL; |
| 1400 | line_chars_allocated = 0; |
| 1401 | do |
| 1402 | { |
| 1403 | char *filename; |
| 1404 | int binary; |
| 1405 | unsigned char *digest; |
| 1406 | ssize_t line_length; |
| 1407 | |
| 1408 | ++line_number; |
| 1409 | if (line_number == 0) |
| 1410 | error (EXIT_FAILURE, 0, _("%s: too many checksum lines"), |
| 1411 | quotef (checkfile_name)); |
| 1412 | |
| 1413 | line_length = getline (&line, &line_chars_allocated, checkfile_stream); |
| 1414 | if (line_length <= 0) |
| 1415 | break; |
| 1416 | |
| 1417 | /* Ignore comment lines, which begin with a '#' character. */ |
| 1418 | if (line[0] == '#') |
| 1419 | continue; |
| 1420 | |
| 1421 | /* Remove any trailing newline. */ |
| 1422 | line_length -= line[line_length - 1] == '\n'; |
no test coverage detected