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 \*===----------------------------------------------------------------------===*/
9 #include "llvm/Support/AutoConvert.h"
13 int main(int argc
, char **argv
) {
15 if (enableAutoConversion(fileno(stdin
)) == -1)
16 fprintf(stderr
, "Setting conversion on stdin failed\n");
18 if (enableAutoConversion(fileno(stderr
)) == -1)
19 fprintf(stdout
, "Setting conversion on stderr failed\n");
21 size_t Count
, NumLines
, NumRead
;
22 char Buffer
[4096], *End
;
25 fprintf(stderr
, "usage: %s <expected line count>\n", argv
[0]);
29 Count
= strtoul(argv
[1], &End
, 10);
30 if (*End
!= '\0' && End
!= argv
[1]) {
31 fprintf(stderr
, "%s: invalid count argument '%s'\n", argv
[0], argv
[1]);
39 NumRead
= fread(Buffer
, 1, sizeof(Buffer
), stdin
);
41 for (i
= 0; i
!= NumRead
; ++i
)
42 if (Buffer
[i
] == '\n')
44 } while (NumRead
== sizeof(Buffer
));
47 fprintf(stderr
, "%s: error reading stdin\n", argv
[0]);
51 if (Count
!= NumLines
) {
52 fprintf(stderr
, "Expected %zu lines, got %zu.\n", Count
, NumLines
);