1// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2//
3// UNSUPPORTED: darwin, target={{.*(linux|solaris).*}}
4
5#include <sys/param.h>
6#include <sys/types.h>
7
8#include <sys/stat.h>
9
10#include <assert.h>
11#include <fts.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15int main() {
16 char *const paths[] = {(char *)"/etc", 0};
17 FTS *ftsp = fts_open(paths, FTS_LOGICAL, NULL);
18 assert(ftsp);
19
20 FTSENT *chp = fts_children(ftsp, 0);
21 assert(chp);
22
23 size_t n = 0;
24 for (FTSENT *p = fts_read(ftsp); p; p = fts_read(ftsp)) {
25 /* Skip recursively subdirectories */
26 if (p->fts_info == FTS_D && p->fts_level != FTS_ROOTLEVEL) /* pre-order */
27 fts_set(ftsp, p, FTS_SKIP);
28 else if (p->fts_info == FTS_DP) /* post-order */
29 continue;
30 else if (p->fts_info == FTS_F) /* regular file */
31 n++;
32 }
33
34 int rv = fts_close(ftsp);
35 assert(!rv);
36
37 printf(format: "Number of files in /etc: '%zu'\n", n);
38
39 return EXIT_SUCCESS;
40
41 // CHECK: Number of files in /etc: '{{.*}}'
42}
43

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/fts.cpp