[RISCV] Regenerate autogen test to remove spurious diff
[llvm-project.git] / llvm / utils / count / count.c
blob300be2aa8a18e209ad3491bf530f019bec6e62ed
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"
10 #include <stdio.h>
11 #include <stdlib.h>
13 int main(int argc, char **argv) {
14 #ifdef __MVS__
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");
20 #endif
21 size_t Count, NumLines, NumRead;
22 char Buffer[4096], *End;
24 if (argc != 2) {
25 fprintf(stderr, "usage: %s <expected line count>\n", argv[0]);
26 return 2;
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]);
32 return 2;
35 NumLines = 0;
36 do {
37 size_t i;
39 NumRead = fread(Buffer, 1, sizeof(Buffer), stdin);
41 for (i = 0; i != NumRead; ++i)
42 if (Buffer[i] == '\n')
43 ++NumLines;
44 } while (NumRead == sizeof(Buffer));
46 if (!feof(stdin)) {
47 fprintf(stderr, "%s: error reading stdin\n", argv[0]);
48 return 3;
51 if (Count != NumLines) {
52 fprintf(stderr, "Expected %zu lines, got %zu.\n", Count, NumLines);
53 return 1;
56 return 0;