unistd, sys/stat: stat(), mkdir() and rmdir()

This commit is contained in:
Lephenixnoir 2021-12-30 18:14:33 +01:00
parent 6383d9ba0f
commit 25c67e6e10
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 57 additions and 10 deletions

View File

@ -57,7 +57,8 @@ set(SOURCES
src/fcntl/open.c
# unistd
src/unistd/files.c
# sys/stat
src/sysstat/stat.c
)
# fx-9860G-only assets and fx-CG-50-only assets
set(ASSETS_fx

View File

@ -68,4 +68,7 @@ extern ft_test ft_unistd_simple_read;
extern ft_test ft_unistd_seek_patterns;
extern ft_test ft_unistd_folders;
/* sys/stat */
extern ft_test ft_sysstat_stat;
#endif /* _FT_ALL_TESTS_H_ */

View File

@ -97,6 +97,10 @@ ft_list headers_posix[] = {
&ft_unistd_folders,
NULL,
}},
{ "<sys/stat.h>", (ft_test*[]){
&ft_sysstat_stat,
NULL,
}},
{ NULL }
};

33
src/sysstat/stat.c Normal file
View File

@ -0,0 +1,33 @@
#include <ft/test.h>
#include <ft/all-tests.h>
#include <ft/util.h>
#include <gint/gint.h>
#include <errno.h>
#include <sys/stat.h>
static void _ft_sysstat_stat_switch(ft_test *t)
{
struct stat st;
int rc;
DO_E(rc, stat("@MainMem", &st), t, "%d");
ft_assert(t, rc == 0 && S_ISDIR(st.st_mode));
#ifdef FX9860G
DO_E(rc, stat("FxLibcT.g1a", &st), t, "%d");
#else
DO_E(rc, stat("FxLibcT.g3a", &st), t, "%d");
#endif
ft_assert(t, rc == 0 && S_ISREG(st.st_mode));
}
static void _ft_sysstat_stat(ft_test *t)
{
gint_world_switch(GINT_CALL(_ft_sysstat_stat_switch, (void *)t));
}
ft_test ft_sysstat_stat = {
.name = "stat() function",
.function = _ft_sysstat_stat,
};

View File

@ -308,17 +308,9 @@ static void _ft_unistd_folders_switch(ft_test *t)
{
int rc, fd, type, size;
/* Create a directory (don't fail if we already ran the test before) */
/* Create a directory */
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
ft_assert(t, rc == 0 || (rc == -1 && errno == EEXIST));
ft_log(t, "note: this folder might already exist\n");
/* Remove that directory */
DO_E(rc, rmdir("ft_test"), t, "%d");
ft_assert(t, rc == 0);
/* Create it anew (and empty) */
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
ft_assert(t, rc == 0);
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
ft_assert(t, rc == -1 && errno == EEXIST);
@ -352,6 +344,20 @@ static void _ft_unistd_folders_switch(ft_test *t)
&type, &size);
ft_log(t, "BFile_Ext_Stat()=%d (type=%d, size=%d)\n", rc, type, size);
ft_assert(t, rc == 0 && type == BFile_Type_File && size == 28);
/* Clean up everything */
DO_E(rc, rmdir("ft_test/subfolder"), t, "%d");
ft_assert(t, rc == -1 && errno == ENOTEMPTY);
DO_E(rc, unlink("ft_test/subfolder"), t, "%d");
ft_assert(t, rc == -1 && errno == ENOTDIR);
DO_E(rc, unlink("ft_test/subfolder/file.txt"), t, "%d");
ft_assert(t, rc == 0);
DO_E(rc, rmdir("ft_test/subfolder"), t, "%d");
ft_assert(t, rc == 0);
DO_E(rc, unlink("ft_test/file.txt"), t, "%d");
ft_assert(t, rc == 0);
DO_E(rc, rmdir("ft_test"), t, "%d");
ft_assert(t, rc == 0);
}
static void _ft_unistd_folders(ft_test *t)