1// RUN: echo "abcde" > %t-testdata
2// RUN: echo "12345" >> %t-testdata
3// RUN: %clangxx_msan -O0 %s -o %t && %run %t %t-testdata
4// RUN: %clangxx_msan -O2 %s -o %t && %run %t %t-testdata
5// RUN: %clang_msan -O0 -xc %s -o %t && %run %t %t-testdata
6// RUN: %clang_msan -O2 -xc %s -o %t && %run %t %t-testdata
7// RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
8// RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
9
10#if defined(__FreeBSD__)
11#define _WITH_GETLINE // To declare getline().
12#endif
13
14#include <assert.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
19int main(int argc, char **argv) {
20 assert(argc == 2);
21 printf(format: "%s\n", argv[1]);
22
23 FILE *fp = fopen(filename: argv[1], modes: "r");
24 assert(fp);
25
26 char *line = 0;
27 size_t len = 0;
28 int n = getline(lineptr: &line, n: &len, stream: fp);
29 assert(n == 6);
30 assert(strcmp(line, "abcde\n") == 0);
31
32 n = getline(lineptr: &line, n: &len, stream: fp);
33 assert(n == 6);
34 assert(strcmp(line, "12345\n") == 0);
35
36 free(ptr: line);
37 fclose(stream: fp);
38
39 return 0;
40}
41

source code of compiler-rt/test/msan/getline.cpp