}
else
{
- char *finger = memmem (buf, chunksz, fingerprint, sizeof fingerprint);
- if (!finger)
- {
- fprintf (stderr, "%s: %s: missing fingerprint\n", prog, file);
- return EXIT_FAILURE;
- }
- else if (memmem (finger + 1, buf + chunksz - (finger + 1),
- fingerprint, sizeof fingerprint))
- {
- fprintf (stderr, "%s: %s: two occurrences of fingerprint\n",
- prog, file);
- return EXIT_FAILURE;
- }
+ bool fingered = false;
- if (fseeko (f, finger - buf, SEEK_SET) != 0)
+ for (char *finger = buf;
+ (finger = memmem (finger, buf + chunksz - finger,
+ fingerprint, sizeof fingerprint));
+ finger++)
{
- perror (file);
- return EXIT_FAILURE;
+ if (! (fseeko (f, finger - buf, SEEK_SET) == 0
+ && fwrite (digest, 1, sizeof digest, f) == sizeof digest))
+ {
+ perror (file);
+ return EXIT_FAILURE;
+ }
+ fingered = true;
}
- if (fwrite (digest, 1, sizeof digest, f) != sizeof digest)
+ if (!fingered)
{
- perror (file);
+ fprintf (stderr, "%s: %s: missing fingerprint\n", prog, file);
return EXIT_FAILURE;
}
}