FxLibcTest/src/fcntl/open.c

50 lines
1.1 KiB
C

#include <ft/test.h>
#include <ft/all-tests.h>
#include <gint/gint.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
static void _ft_fcntl_open_switch(ft_test *t)
{
char const *filename = "ft_open.txt";
int fd, rc;
errno = 0;
fd = open(filename, O_RDONLY);
ft_log(t, "open(\"%s\", O_RDONLY) = %d\n", filename, fd);
if(fd == -1)
ft_log(t, "errno %d: %s\n", errno, strerror(errno));
ft_assert(t, fd == -1 && errno == ENOENT);
if(fd != -1)
close(fd);
fd = open(filename, O_RDWR | O_CREAT);
ft_log(t, "open(\"%s\", O_RDWR | O_CREAT) = %d\n", filename, fd);
if(fd == -1)
ft_log(t, "errno %d: %s\n", errno, strerror(errno));
ft_assert(t, fd >= 0);
if(fd != -1)
close(fd);
rc = unlink(filename);
ft_log(t, "unlink(\"%s\") = %d\n", filename, rc);
if(rc == -1)
ft_log(t, "errno %d: %s\n", errno, strerror(errno));
ft_assert(t, rc == 0);
}
static void _ft_fcntl_open(ft_test *t)
{
gint_world_switch(GINT_CALL(_ft_fcntl_open_switch, (void *)t));
}
ft_test ft_fcntl_open = {
.name = "Opening files",
.function = _ft_fcntl_open,
};
// TODO: Truncation