#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 usr_name[64] = {0};

    while (getline(&line, &len, file) != -1) {
        if (sscanf(line, tag "%63s", usr_name) == 1) {
            break;
        } else {
            break;
            return 1;
        }
    }

    free(line);
    fclose(file);
}
