forked from Imagelibrary/rtems
fs: Add struct dirent::d_type support
This commit is contained in:
@@ -8,47 +8,82 @@
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
#include "fstest.h"
|
||||
#include "fs_config.h"
|
||||
#include "fstest_support.h"
|
||||
#include "pmacros.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
const char rtems_test_name[] = "FSSCANDIR " FILESYSTEM;
|
||||
|
||||
/*
|
||||
* This code is from the scandir() man page.
|
||||
*/
|
||||
static void test_scandir(void)
|
||||
#define FILE_NAME "aaa"
|
||||
|
||||
#define DIR_NAME "bbb"
|
||||
|
||||
void test(void)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
struct dirent *d;
|
||||
int rv;
|
||||
int n;
|
||||
|
||||
n = scandir(".", &namelist, 0, NULL);
|
||||
if (n < 0) {
|
||||
perror("scandir");
|
||||
} else {
|
||||
while(n--) {
|
||||
printf("%s\n", namelist[n]->d_name);
|
||||
free(namelist[n]);
|
||||
}
|
||||
free(namelist);
|
||||
}
|
||||
int i;
|
||||
|
||||
rtems_test_assert(MAXNAMLEN == NAME_MAX);
|
||||
}
|
||||
|
||||
rv = mknod(FILE_NAME, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
void test (void)
|
||||
{
|
||||
test_scandir();
|
||||
rv = mkdir(DIR_NAME, S_IRWXU | S_IRWXG | S_IRWXO );
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
n = scandir(".", &namelist, NULL, alphasort);
|
||||
rtems_test_assert(2 <= n || n == 4);
|
||||
|
||||
i = 0;
|
||||
d = namelist[i];
|
||||
|
||||
if (n >= 3) {
|
||||
rtems_test_assert(strcmp(d->d_name, ".") == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
}
|
||||
|
||||
if (n == 4) {
|
||||
rtems_test_assert(strcmp(d->d_name, "..") == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
}
|
||||
|
||||
rtems_test_assert(strcmp(d->d_name, FILE_NAME) == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_REG || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
|
||||
rtems_test_assert(strcmp(d->d_name, DIR_NAME) == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
|
||||
free(namelist);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user