rm journal.c, rm format.h

This commit is contained in:
Luna 2019-07-13 13:59:15 -03:00
parent 5fb7f0263a
commit 007cd0e22a
2 changed files with 0 additions and 57 deletions

View File

View File

@ -1,57 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
// functions to deal with the journal file
FILE *journal_open(char *topic)
{
char *home_path = getenv("HOME");
// combine w/ home path
char *journal_dir = (char*)malloc(1024);
snprintf(journal_dir, 1024, "%s/.lunabot", home_path);
// construct a 744
mkdir(journal_dir, S_IRWXU | S_IRGRP | S_IROTH);
char *journal_path = (char*)malloc(1024);
snprintf(journal_path, 1024, "%s/%s", journal_dir, topic);
FILE* res = fopen(journal_path, "a");
free(journal_path);
free(journal_dir);
return res;
}
void journal_write(FILE* journal_fd, char* message)
{
// TODO: strlen()?
fwrite(message, strlen(message), 1, journal_fd);
}
void journal_close(FILE* journal_fd)
{
fclose(journal_fd);
}
void journal_write_topic(FILE *journal_fd, char *topic, char *message)
{
char *tstamp = malloc(128 * sizeof(char));
char fmt_msg[512];
time_t rawtime;
time(&rawtime);
const struct tm *cur_time = gmtime(&rawtime);
strftime(tstamp, 128, "%c", cur_time);
sprintf(fmt_msg, "[%s] [%s]: %s\n", tstamp, topic, message);
free(tstamp);
journal_write(journal_fd, fmt_msg);
}