From b7fec480e00b1b9ba68a403d0b08366161c7c303 Mon Sep 17 00:00:00 2001 From: dequis Date: Tue, 18 Oct 2016 03:57:41 -0300 Subject: Support motd.txt files bigger than 2048 chars By using g_file_get_contents() --- irc_send.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'irc_send.c') diff --git a/irc_send.c b/irc_send.c index 70e4e82a..89f0100a 100644 --- a/irc_send.c +++ b/irc_send.c @@ -53,19 +53,18 @@ void irc_send_login(irc_t *irc) void irc_send_motd(irc_t *irc) { - char motd[2048]; - ssize_t len; - int fd; + char *motd; + size_t len; - fd = open(global.conf->motdfile, O_RDONLY); - if (fd == -1 || (len = read(fd, motd, sizeof(motd) - 1)) <= 0) { + g_file_get_contents(global.conf->motdfile, &motd, &len, NULL); + + if (!motd || !len) { irc_send_num(irc, 422, ":We don't need MOTDs."); } else { char linebuf[80]; char *add = "", max, *in; in = motd; - motd[len] = '\0'; linebuf[79] = len = 0; max = sizeof(linebuf) - 1; @@ -100,9 +99,8 @@ void irc_send_motd(irc_t *irc) irc_send_num(irc, 376, ":End of MOTD"); } - if (fd != -1) { - close(fd); - } + g_free(motd); + } /* Used by some funcs that generate PRIVMSGs to figure out if we're talking to -- cgit v1.2.3