/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 10-09-2008 0h57 by Vamps (vamps@alterinet.org) * * */ #include #include #include #include #include #include "include/struct.h" #include "include/log.h" int LoadLog(char *file) { log_t.file = malloc(sizeof(char) * strlen(file)); strcpy(log_t.file, file); unlink(file); printf("%s file\n", file); return 0; } int PutLog(char *string) { struct tm *ts; time_t now = time(NULL); char buf[80]; if (log_t.type != 0) { if ((log_t.logfile = fopen(log_t.file, "a+")) < 0) { perror("fopen"); return 1; } if (log_t.type == 1) { ts = localtime(&now); strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts); fprintf(log_t.logfile, "%s : %s\n", buf, string); } fclose(log_t.logfile); } return 0; } int FreeLog(void) { PutLog("End of log\n"); free(log_t.file); return 0; } void LogType(short type) { log_t.type = type; }