aboutsummaryrefslogtreecommitdiffstats
path: root/irc_send.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-09-05 12:31:22 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-09-05 12:31:22 +0100
commitfef78131a46462ee1d1457aa690c52a52b23151a (patch)
treec4ecee50eb32da7aee9587b7a107eb2ab348e48a /irc_send.c
parent41e0c00fd22d1cdace2040be5912d64f51f12ab8 (diff)
Fix compiler warnings. Also fixing irc_send_motd(), which so far got away
with a horrible practice of reading the MOTD file one by one.
Diffstat (limited to 'irc_send.c')
-rw-r--r--irc_send.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/irc_send.c b/irc_send.c
index fa4e6815..76b88118 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -52,24 +52,27 @@ void irc_send_login( irc_t *irc )
void irc_send_motd( irc_t *irc )
{
+ char motd[2048];
+ size_t len;
int fd;
fd = open( global.conf->motdfile, O_RDONLY );
- if( fd == -1 )
+ if( fd == -1 || ( len = read( fd, motd, sizeof( motd ) - 1 ) ) <= 0 )
{
irc_send_num( irc, 422, ":We don't need MOTDs." );
}
else
{
- char linebuf[80]; /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */
- char *add, max;
- int len;
+ char linebuf[80];
+ char *add, max, *in;
+ in = motd;
+ motd[len] = '\0';
linebuf[79] = len = 0;
max = sizeof( linebuf ) - 1;
irc_send_num( irc, 375, ":- %s Message Of The Day - ", irc->root->host );
- while( read( fd, linebuf + len, 1 ) == 1 )
+ while( ( linebuf[len] = *(in++) ) )
{
if( linebuf[len] == '\n' || len == max )
{
@@ -79,13 +82,15 @@ void irc_send_motd( irc_t *irc )
}
else if( linebuf[len] == '%' )
{
- read( fd, linebuf + len, 1 );
+ linebuf[len] = *(in++);
if( linebuf[len] == 'h' )
add = irc->root->host;
else if( linebuf[len] == 'v' )
add = BITLBEE_VERSION;
else if( linebuf[len] == 'n' )
add = irc->user->nick;
+ else if( linebuf[len] == '\0' )
+ in --;
else
add = "%";
@@ -98,8 +103,10 @@ void irc_send_motd( irc_t *irc )
}
}
irc_send_num( irc, 376, ":End of MOTD" );
- close( fd );
}
+
+ if( fd != -1 )
+ close( fd );
}
void irc_usermsg( irc_t *irc, char *format, ... )