annotate compiler-rt/test/msan/getline.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: echo "abcde" > %t-testdata
anatofuz
parents:
diff changeset
2 // RUN: echo "12345" >> %t-testdata
anatofuz
parents:
diff changeset
3 // RUN: %clangxx_msan -O0 %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
4 // RUN: %clangxx_msan -O2 %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
5 // RUN: %clang_msan -O0 -xc %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
6 // RUN: %clang_msan -O2 -xc %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
7 // RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
8 // RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 #if defined(__FreeBSD__)
anatofuz
parents:
diff changeset
11 #define _WITH_GETLINE // To declare getline().
anatofuz
parents:
diff changeset
12 #endif
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #include <assert.h>
anatofuz
parents:
diff changeset
15 #include <stdio.h>
anatofuz
parents:
diff changeset
16 #include <stdlib.h>
anatofuz
parents:
diff changeset
17 #include <string.h>
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 int main(int argc, char **argv) {
anatofuz
parents:
diff changeset
20 assert(argc == 2);
anatofuz
parents:
diff changeset
21 printf("%s\n", argv[1]);
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 FILE *fp = fopen(argv[1], "r");
anatofuz
parents:
diff changeset
24 assert(fp);
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 char *line = 0;
anatofuz
parents:
diff changeset
27 size_t len = 0;
anatofuz
parents:
diff changeset
28 int n = getline(&line, &len, fp);
anatofuz
parents:
diff changeset
29 assert(n == 6);
anatofuz
parents:
diff changeset
30 assert(strcmp(line, "abcde\n") == 0);
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 n = getline(&line, &len, fp);
anatofuz
parents:
diff changeset
33 assert(n == 6);
anatofuz
parents:
diff changeset
34 assert(strcmp(line, "12345\n") == 0);
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 free(line);
anatofuz
parents:
diff changeset
37 fclose(fp);
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 return 0;
anatofuz
parents:
diff changeset
40 }