source: rtems/testsuites/fstests/fsscandir01/init.c @ 03fcbb1

5
Last change on this file since 03fcbb1 was 03fcbb1, checked in by Sebastian Huber <sebastian.huber@…>, on 11/27/18 at 11:45:53

fs: Add struct dirent::d_type support

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 2015.
3 *  On-Line Applications Research Corporation (OAR).
4 * 
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <sys/stat.h>
15#include <dirent.h>
16#include <fcntl.h>
17#include <limits.h>
18#include <stdio.h>
19#include <unistd.h>
20
21#include <tmacros.h>
22
23#include "fstest.h"
24#include "fs_config.h"
25
26const char rtems_test_name[] = "FSSCANDIR " FILESYSTEM;
27
28#define FILE_NAME "aaa"
29
30#define DIR_NAME "bbb"
31
32void test(void)
33{
34  struct dirent **namelist;
35  struct dirent *d;
36  int rv;
37  int n;
38  int i;
39
40  rtems_test_assert(MAXNAMLEN == NAME_MAX);
41
42  rv = mknod(FILE_NAME, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
43  rtems_test_assert(rv == 0);
44
45  rv = mkdir(DIR_NAME, S_IRWXU | S_IRWXG | S_IRWXO );
46  rtems_test_assert(rv == 0);
47
48  n = scandir(".", &namelist, NULL, alphasort);
49  rtems_test_assert(2 <= n || n == 4);
50
51  i = 0;
52  d = namelist[i];
53
54  if (n >= 3) {
55    rtems_test_assert(strcmp(d->d_name, ".") == 0);
56#ifdef DT_UNKNOWN
57    rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
58#endif
59    free(d);
60    ++i;
61    d = namelist[i];
62  }
63
64  if (n == 4) {
65    rtems_test_assert(strcmp(d->d_name, "..") == 0);
66#ifdef DT_UNKNOWN
67    rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
68#endif
69    free(d);
70    ++i;
71    d = namelist[i];
72  }
73
74  rtems_test_assert(strcmp(d->d_name, FILE_NAME) == 0);
75#ifdef DT_UNKNOWN
76  rtems_test_assert(d->d_type == DT_REG || d->d_type == DT_UNKNOWN);
77#endif
78  free(d);
79  ++i;
80  d = namelist[i];
81
82  rtems_test_assert(strcmp(d->d_name, DIR_NAME) == 0);
83#ifdef DT_UNKNOWN
84  rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
85#endif
86  free(d);
87
88  free(namelist);
89}
Note: See TracBrowser for help on using the repository browser.