some fixes
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Failing after 8s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 11s

This commit is contained in:
wt committed 2025-10-23 12:35:05 +07:00
1 parent dc05f8f861
commit 72a78d2e7a
7 files changed
+66 -24

No files matched your search

+25
View File
@@ -1,10 +1,14 @@
#include "file.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *read_file(const char *path) {
create_file_if_not_exists(path);
FILE *fp = fopen(path, "rb");
if (fp == NULL) {
perror("Error opening file");
@@ -36,6 +40,7 @@ char *read_file(const char *path) {
}
char *write_file(const char *path, const char *data) {
create_file_if_not_exists(path);
FILE *fp = fopen(path, "w");
if (fp == NULL) {
printf("%s\n", path);
@@ -50,3 +55,23 @@ char *write_file(const char *path, const char *data) {
char *ret = strdup(data);
return ret;
}
int create_file_if_not_exists(const char *filename) {
if (!check_file_exists(filename)) {
return 0;
}
FILE *file = fopen(filename, "w");
if (file == nullptr) {
perror("Error creating file");
return -1;
}
fclose(file);
return 0;
}
int check_file_exists(const char *filename) {
if (access(filename, F_OK) == 0) {
return 0;
}
return -1;
}