From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- C/final-project-z2h/src/file.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 C/final-project-z2h/src/file.c (limited to 'C/final-project-z2h/src/file.c') diff --git a/C/final-project-z2h/src/file.c b/C/final-project-z2h/src/file.c new file mode 100644 index 0000000..fcdb036 --- /dev/null +++ b/C/final-project-z2h/src/file.c @@ -0,0 +1,39 @@ +#include + +#include +#include +#include +#include + +#include "file.h" +#include "common.h" + + +int create_db_file(char *filename) { + int fd = open(filename, O_RDWR); + if (fd != -1) { + close(fd); + printf("File already exists\n"); + return STATUS_ERROR; + } + + fd = open(filename, O_RDWR | O_CREAT, 0644); + if (fd == -1) { + perror("open"); + return STATUS_ERROR; + } + + return fd; +} + +int open_db_file(char *filename) { + int fd = open(filename, O_RDWR, 0644); + if (fd == -1) { + perror("open"); + return STATUS_ERROR; + } + + return fd; +} + + -- cgit v1.2.3