@@ -1,5 +1,6 @@
|
||||
# List of programs.
|
||||
set(TEST_LIST
|
||||
t_creat.c
|
||||
t_write_read.c
|
||||
t_gid.c
|
||||
t_alarm.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 <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;
|
||||
}
|
||||
Reference in New Issue
Block a user