From 3ae7f34539e42f96b9f2e3212a23d82e128544f9 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 17 Dec 2023 18:26:26 +0100 Subject: Reformatted player_add_comment() and fixed the type of the var passed to strltime() --- FICS/playerdb.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/FICS/playerdb.c b/FICS/playerdb.c index 72177cc..5628d15 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -2336,23 +2336,26 @@ PUBLIC int player_num_comments(int p) return lines_file(fname); } -PUBLIC int player_add_comment(int p_by, int p_to, char *comment) +PUBLIC int +player_add_comment(int p_by, int p_to, char *comment) { - char fname[MAX_FILENAME_SIZE]; - FILE *fp; - int t = time(0); + FILE *fp; + char fname[MAX_FILENAME_SIZE]; + time_t t = time(NULL); - if (!parray[p_to].registered) - return -1; - sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, parray[p_to].login[0], - parray[p_to].login, "comments"); - fp = fopen(fname, "a"); - if (!fp) - return -1; - fprintf(fp, "%s at %s: %s\n", parray[p_by].name, strltime(&t), comment); - fclose(fp); - parray[p_to].num_comments = player_num_comments(p_to); - return 0; + if (!parray[p_to].registered) + return -1; + + sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, + parray[p_to].login[0], parray[p_to].login, "comments"); + + if ((fp = fopen(fname, "a")) == NULL) + return -1; + + fprintf(fp, "%s at %s: %s\n", parray[p_by].name, strltime(&t), comment); + fclose(fp); + parray[p_to].num_comments = player_num_comments(p_to); + return 0; } PUBLIC int player_show_comments(int p, int p1) -- cgit v1.2.3