diff --git a/tests/Makefile.tests.mk b/tests/Makefile.tests.mk index d6fc3dcee9..01442a8a00 100644 --- a/tests/Makefile.tests.mk +++ b/tests/Makefile.tests.mk @@ -62,6 +62,7 @@ EXPECT_NAMES=\ fcntl/create \ fcntl/fcntl \ fcntl/open \ + fcntl/openat \ fcntl/posix_fallocate \ features \ fnmatch \ diff --git a/tests/expected/fcntl/openat.stdout b/tests/expected/fcntl/openat.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/fcntl/openat.c b/tests/fcntl/openat.c new file mode 100644 index 0000000000..cadbaa0ca4 --- /dev/null +++ b/tests/fcntl/openat.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include + +#include "test_helpers.h" + +int main(void) { + int m = mkdir("test_dir", 0777); + ERROR_IF(mkdir, m, == -1); + + int fd_file = open("test_dir/test_file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644); + ERROR_IF(open, fd_file, == -1); + UNEXP_IF(open, fd_file, < 0); + + int c1 = close(fd_file); + ERROR_IF(close, c1, == -1); + + DIR *dir_stream = opendir("test_dir"); + ERROR_IF(opendir, dir_stream, == NULL); + + int dfd = dirfd(dir_stream); + ERROR_IF(dirfd, dfd, == -1); + UNEXP_IF(dirfd, dfd, < 0); + + int fd_at = openat(dfd, "../test_dir/test_file.txt", O_RDONLY); + ERROR_IF(openat, fd_at, == -1); + UNEXP_IF(openat, fd_at, < 0); + + int c2 = close(fd_at); + ERROR_IF(close, c2, == -1); + + int c3 = closedir(dir_stream); + ERROR_IF(closedir, c3, == -1); + + int u = unlink("test_dir/test_file.txt"); + ERROR_IF(unlink, u, == -1); + + int r = rmdir("test_dir"); + ERROR_IF(rmdir, r, == -1); +} \ No newline at end of file