File indexing completed on 2025-05-11 08:24:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <sys/stat.h>
0034 #include <dirent.h>
0035 #include <fcntl.h>
0036 #include <limits.h>
0037 #include <stdio.h>
0038 #include <unistd.h>
0039
0040 #include <tmacros.h>
0041
0042 #include "fstest.h"
0043 #include "fs_config.h"
0044
0045 const char rtems_test_name[] = "FSSCANDIR " FILESYSTEM;
0046 const RTEMS_TEST_STATE rtems_test_state = TEST_STATE;
0047
0048 #define FILE_NAME "aaa"
0049
0050 #define DIR_NAME "bbb"
0051
0052 void test(void)
0053 {
0054 struct dirent **namelist;
0055 struct dirent *d;
0056 int rv;
0057 int n;
0058 int i;
0059
0060 rtems_test_assert(MAXNAMLEN == NAME_MAX);
0061
0062 rv = mknod(FILE_NAME, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
0063 rtems_test_assert(rv == 0);
0064
0065 rv = mkdir(DIR_NAME, S_IRWXU | S_IRWXG | S_IRWXO );
0066 rtems_test_assert(rv == 0);
0067
0068 n = scandir(".", &namelist, NULL, alphasort);
0069 rtems_test_assert(2 <= n || n == 4);
0070
0071 i = 0;
0072 d = namelist[i];
0073
0074 if (n >= 3) {
0075 rtems_test_assert(strcmp(d->d_name, ".") == 0);
0076 #ifdef DT_UNKNOWN
0077 rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
0078 #endif
0079 free(d);
0080 ++i;
0081 d = namelist[i];
0082 }
0083
0084 if (n == 4) {
0085 rtems_test_assert(strcmp(d->d_name, "..") == 0);
0086 #ifdef DT_UNKNOWN
0087 rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
0088 #endif
0089 free(d);
0090 ++i;
0091 d = namelist[i];
0092 }
0093
0094 rtems_test_assert(strcmp(d->d_name, FILE_NAME) == 0);
0095 #ifdef DT_UNKNOWN
0096 rtems_test_assert(d->d_type == DT_REG || d->d_type == DT_UNKNOWN);
0097 #endif
0098 free(d);
0099 ++i;
0100 d = namelist[i];
0101
0102 rtems_test_assert(strcmp(d->d_name, DIR_NAME) == 0);
0103 #ifdef DT_UNKNOWN
0104 rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
0105 #endif
0106 free(d);
0107
0108 free(namelist);
0109 }