1 /*===- count.c - The 'count' testing tool ---------------------------------===*\
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 \*===----------------------------------------------------------------------===*/
12 int main(int argc
, char **argv
) {
13 unsigned Count
, NumLines
, NumRead
;
14 char Buffer
[4096], *End
;
17 fprintf(stderr
, "usage: %s <expected line count>\n", argv
[0]);
21 Count
= strtol(argv
[1], &End
, 10);
22 if (*End
!= '\0' && End
!= argv
[1]) {
23 fprintf(stderr
, "%s: invalid count argument '%s'\n", argv
[0], argv
[1]);
31 NumRead
= fread(Buffer
, 1, sizeof(Buffer
), stdin
);
33 for (i
= 0; i
!= NumRead
; ++i
)
34 if (Buffer
[i
] == '\n')
36 } while (NumRead
== sizeof(Buffer
));
39 fprintf(stderr
, "%s: error reading stdin\n", argv
[0]);
43 if (Count
!= NumLines
) {
44 fprintf(stderr
, "Expected %d lines, got %d.\n", Count
, NumLines
);