]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/sanitizer_common/TestCases/Posix/popen.cc
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / sanitizer_common / TestCases / Posix / popen.cc
1 // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
2 // CHECK: 1
3 // CHECK-NEXT: 2
4
5 #include <assert.h>
6 #include <stdio.h>
7
8 int main(void) {
9   // use a tool that produces different output than input to verify
10   // that everything worked correctly
11   FILE *fp = popen("sort", "w");
12   assert(fp);
13
14   // verify that fileno() returns a meaningful descriptor (needed
15   // for the implementation of TSan)
16   assert(fileno(fp) != -1);
17
18   assert(fputs("2\n", fp) >= 0);
19   assert(fputs("1\n", fp) >= 0);
20   assert(pclose(fp) == 0);
21
22   return 0;
23 }