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

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler-rt/test/msan/getline.cpp	Thu Feb 13 15:10:13 2020 +0900
@@ -0,0 +1,40 @@
+// RUN: echo "abcde" > %t-testdata
+// RUN: echo "12345" >> %t-testdata
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t %t-testdata
+// RUN: %clangxx_msan -O2 %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O0 -xc %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O2 -xc %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
+
+#if defined(__FreeBSD__)
+#define _WITH_GETLINE  // To declare getline().
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+  assert(argc == 2);
+  printf("%s\n", argv[1]);
+
+  FILE *fp = fopen(argv[1], "r");
+  assert(fp);
+
+  char *line = 0;
+  size_t len = 0;
+  int n = getline(&line, &len, fp);
+  assert(n == 6);
+  assert(strcmp(line, "abcde\n") == 0);
+
+  n = getline(&line, &len, fp);
+  assert(n == 6);
+  assert(strcmp(line, "12345\n") == 0);
+
+  free(line);
+  fclose(fp);
+
+  return 0;
+}