diff --git a/programs/tests/CMakeLists.txt b/programs/tests/CMakeLists.txt index eca7307..7d7635e 100644 --- a/programs/tests/CMakeLists.txt +++ b/programs/tests/CMakeLists.txt @@ -1,5 +1,6 @@ # List of programs. set(TEST_LIST + t_creat.c t_write_read.c t_gid.c t_alarm.c diff --git a/programs/tests/t_creat.c b/programs/tests/t_creat.c new file mode 100644 index 0000000..0589adb --- /dev/null +++ b/programs/tests/t_creat.c @@ -0,0 +1,37 @@ +/// @file t_creat.c +/// @brief test the creat syscall +/// @copyright (c) 2024 This file is distributed under the MIT License. +/// See LICENSE.md for details. + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + int fd = creat("foo", 0660); + if (fd < 0) { + printf("creat: foo: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + if (write(fd, "foo", 3) != 3) { + printf("write: foo: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + struct stat_t st; + if (stat("foo", &st) < 0) { + printf("stat: foo: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + if (st.st_size != 3) { + printf("Wrong file size. (expected: 3, is: %u)\n", st.st_size); + exit(EXIT_FAILURE); + } + + return 0; +}