Use fopen_bbs_path in a couple of places.

Just an example of how it may be used.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-19 15:54:57 +00:00 committed by Andrew Pamment
parent 2f79c4a590
commit bdde1aa621

View File

@ -725,15 +725,10 @@ void record_last10_callers(struct user_record *user) {
void display_last10_callers(struct user_record *user) { void display_last10_callers(struct user_record *user) {
struct last10_callers callers[10]; struct last10_callers callers[10];
char last10_path[PATH_MAX]; int i = 0;
int i, z;
struct tm l10_time; struct tm l10_time;
snprintf(last10_path, PATH_MAX, "%s/last10v2.dat", conf.bbs_path); FILE *fptr = fopen_bbs_path("last10v2.dat", "rb");
FILE *fptr = fopen(last10_path, "rb");
time_t l10_timet;
s_printf("\e[2J\e[1;1H"); s_printf("\e[2J\e[1;1H");
@ -741,7 +736,6 @@ void display_last10_callers(struct user_record *user) {
s_printf(get_string(3)); s_printf(get_string(3));
if (fptr != NULL) { if (fptr != NULL) {
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) { if (fread(&callers[i], sizeof(struct last10_callers), 1, fptr) < 1) {
break; break;
@ -749,12 +743,10 @@ void display_last10_callers(struct user_record *user) {
} }
fclose(fptr); fclose(fptr);
} else {
i = 0;
} }
for (z = 0; z < i; z++) { for (int z = 0; z < i; z++) {
l10_timet = callers[z].time; time_t l10_timet = callers[z].time;
localtime_r(&l10_timet, &l10_time); localtime_r(&l10_timet, &l10_time);
if (conf.date_style == 1) { if (conf.date_style == 1) {
s_printf(get_string(4), callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mon + 1, l10_time.tm_mday, l10_time.tm_year - 100, (callers[z].calls == 1 ? 'N' : ' ')); s_printf(get_string(4), callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mon + 1, l10_time.tm_mday, l10_time.tm_year - 100, (callers[z].calls == 1 ? 'N' : ' '));
@ -789,7 +781,6 @@ void automessage_write() {
FILE *fptr; FILE *fptr;
char automsg[450]; char automsg[450];
char buffer[76]; char buffer[76];
char automsg_path[PATH_MAX];
int i; int i;
struct tm timenow; struct tm timenow;
time_t timen; time_t timen;
@ -813,9 +804,7 @@ void automessage_write() {
strlcat(automsg, "\r\n", sizeof automsg); strlcat(automsg, "\r\n", sizeof automsg);
} }
snprintf(automsg_path, PATH_MAX, "%s/automessage.txt", conf.bbs_path); fptr = fopen_bbs_path("automessage.txt", "w");
fptr = fopen(automsg_path, "w");
if (fptr) { if (fptr) {
fwrite(automsg, strlen(automsg), 1, fptr); fwrite(automsg, strlen(automsg), 1, fptr);
fclose(fptr); fclose(fptr);
@ -826,32 +815,23 @@ void automessage_write() {
} }
void automessage_display() { void automessage_display() {
struct stat s;
FILE *fptr;
char buffer[90]; char buffer[90];
char automsg_path[PATH_MAX];
int i; int i;
s_printf("\r\n\r\n"); s_printf("\r\n\r\n");
snprintf(automsg_path, PATH_MAX, "%s/automessage.txt", conf.bbs_path); FILE *fptr = fopen_bbs_path("automessage.txt", "r");
if (fptr == NULL) {
if (stat(automsg_path, &s) == 0) { dolog("Error opening automessage.txt");
fptr = fopen(automsg_path, "r"); s_printf(get_string(17));
if (fptr) { } else {
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
memset(buffer, 0, 90); memset(buffer, 0, 90);
fgets(buffer, 88, fptr); fgets(buffer, 88, fptr);
buffer[strlen(buffer) - 1] = '\r'; buffer[strlen(buffer) - 1] = '\r';
buffer[strlen(buffer)] = '\n'; buffer[strlen(buffer)] = '\n';
s_printf(buffer); s_printf(buffer);
} }
fclose(fptr); fclose(fptr);
} else {
dolog("Error opening automessage.txt");
}
} else {
s_printf(get_string(17));
} }
s_printf(get_string(6)); s_printf(get_string(6));
s_getc(); s_getc();