#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <stdbool.h>
#include "config.h"
#include "moroz.h"
void MRZ_CFILE(const char *filename) {
int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd != -1) {
close(fd);
} else {
fprintf(stderr, TXT_RED "ERROR !\n" TXT_RESET);
}
}
void MRZ_CDIR(const char *dirname) {
if (mkdir(dirname, 0755) != 0) {
fprintf(stderr, TXT_RED "ERROR !\n" TXT_RESET);
}
}
char *MRF_RFILE(const char *patch, const char *tag) {
FILE *file = fopen(patch, "r");
if (!file) {
return NULL;
}
char *line = NULL;
size_t len = 0;
char tag_line[64] = {0};
char *result = NULL;
char format[128];
snprintf(format, sizeof(format), "%s %%63s", tag);
while (getline(&line, &len, file) != -1) {
if (sscanf(line, format, tag_line) == 1) {
result = strdup(tag_line);
break;
}
}
free(line);
fclose(file);
return result;
}