111 lines
2.2 KiB
C
111 lines
2.2 KiB
C
#include <ft/test.h>
|
|
#include <ft/all-tests.h>
|
|
#include <ft/util.h>
|
|
|
|
#include <gint/gint.h>
|
|
#include <gint/bfile.h>
|
|
#include <gint/fs.h>
|
|
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <dirent.h>
|
|
|
|
extern char *fc_to_utf8_alloc(uint16_t const *fc);
|
|
|
|
static void _ft_dirent_glob_switch(ft_test *t)
|
|
{
|
|
int search_handle, rc;
|
|
uint16_t found_file[256];
|
|
struct BFile_FileInfo fileinfo;
|
|
char *str;
|
|
uint16_t const *path = u"\\\\fls0\\*";
|
|
|
|
DO_E(rc, BFile_FindFirst(path, &search_handle, found_file, &fileinfo),
|
|
t, "%d");
|
|
ft_assert(t, rc == 0 || rc == BFile_EntryNotFound);
|
|
if(rc < 0) return;
|
|
|
|
str = fc_to_utf8_alloc(found_file);
|
|
ft_log(t, "Found: %s\n", str);
|
|
free(str);
|
|
|
|
while(1) {
|
|
rc = BFile_FindNext(search_handle, found_file, &fileinfo);
|
|
ft_assert(t, rc == 0 || rc == BFile_EnumerateEnd);
|
|
if(rc == BFile_EnumerateEnd)
|
|
break;
|
|
|
|
str = fc_to_utf8_alloc(found_file);
|
|
ft_log(t, "Found: %s\n", str);
|
|
free(str);
|
|
}
|
|
|
|
DO_E(rc, BFile_FindClose(search_handle), t, "%d");
|
|
ft_assert(t, rc == 0);
|
|
}
|
|
|
|
static void _ft_dirent_glob(ft_test *t)
|
|
{
|
|
gint_world_switch(GINT_CALL(_ft_dirent_glob_switch, (void *)t));
|
|
}
|
|
|
|
ft_test ft_dirent_glob = {
|
|
.name = "Glob \\\\fls0\\*",
|
|
.function = _ft_dirent_glob,
|
|
};
|
|
|
|
static struct dirent *read_ent(ft_test *t, DIR *dp)
|
|
{
|
|
int offset = telldir(dp);
|
|
struct dirent *ent = readdir(dp);
|
|
|
|
if(!ent) {
|
|
ft_log(t, "%02d <end>\n", offset);
|
|
}
|
|
else {
|
|
ft_log(t, "%02d %s%s\n", offset, ent->d_name,
|
|
ent->d_type == DT_DIR ? "/" : "");
|
|
}
|
|
|
|
return ent;
|
|
}
|
|
|
|
static void _ft_dirent_open_folders_switch(ft_test *t)
|
|
{
|
|
DIR *dp;
|
|
struct dirent *ent;
|
|
int offset;
|
|
|
|
DO_E(dp, opendir("/"), t, "%p");
|
|
ft_assert(t, dp != NULL);
|
|
if(!dp) return;
|
|
|
|
do ent = read_ent(t, dp);
|
|
while(ent);
|
|
|
|
DO_E(offset, telldir(dp), t, "%d");
|
|
if(offset > 0) offset--;
|
|
ft_log(t, "seekdir(dp, %d)\n", offset);
|
|
seekdir(dp, offset);
|
|
read_ent(t, dp);
|
|
|
|
rewinddir(dp);
|
|
ft_log(t, "rewinddir(dp)\n");
|
|
read_ent(t, dp);
|
|
|
|
closedir(dp);
|
|
}
|
|
|
|
static void _ft_dirent_open_folders(ft_test *t)
|
|
{
|
|
gint_world_switch(GINT_CALL(_ft_dirent_open_folders_switch, (void*)t));
|
|
}
|
|
|
|
ft_test ft_dirent_open_folders = {
|
|
.name = "Opening folders",
|
|
.function = _ft_dirent_open_folders,
|
|
};
|