add creat test

Tesing commit f7e53f9b00.
This commit is contained in:
Florian Fischer
2024-02-29 09:49:24 +01:00
parent 7b54ff8d2a
commit 43054529d5
2 changed files with 38 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
# List of programs.
set(TEST_LIST
t_creat.c
t_write_read.c
t_gid.c
t_alarm.c
+37
View File
@@ -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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <strerror.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/unistd.h>
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;
}