ref: 1b2249dec883624e892a6c2c6187f553adfb3364
parent: e978996babb834efb9d2de465c812e11178cc33a
author: kemal <[email protected]>
date: Mon Nov 15 07:01:34 EST 2021
ircs: inline some functions, "log->fd > 0" should be an assert in logsend
--- a/main.c
+++ b/main.c
@@ -119,35 +119,23 @@
}
static Ch *
-challoc(char *name)
-{
- Ch *c;
- char buf[128];
-
- c = emalloc(sizeof(Ch));
- snprint(c->name, sizeof(c->name), "%s", name);
- if(logdir != nil){
- snprint(buf, sizeof(buf), "%s/%s", logdir, name);
- c->log.fd = create(buf, OWRITE, 0600 | DMAPPEND);
- if(c->log.fd < 0)
- sysfatal("create: %r");
- c->log.mday = 0;
- } else
- c->log.fd = 0;
- c->users = nil;
- return c;
-}
-
-static Ch *
chget(char *name)
{
Ch *c;
Rune key[64];
+ char buf[128];
runesnprint(key, nelem(key), "%s", name);
c = trieget(channels, key);
if(c == nil){
- c = challoc(name);
+ c = emalloc(sizeof(Ch));
+ snprint(c->name, sizeof(c->name), "%s", name);
+ if(logdir != nil){
+ snprint(buf, sizeof(buf), "%s/%s", logdir, name);
+ c->log.fd = create(buf, OWRITE, 0600 | DMAPPEND);
+ if(c->log.fd < 0)
+ sysfatal("create: %r");
+ }
trieadd(channels, key, c);
}
return c;
@@ -167,17 +155,6 @@
}
static User *
-useralloc(char *nick)
-{
- User *u;
-
- u = emalloc(sizeof(User));
- snprint(u->nick, sizeof(u->nick), "%s", nick);
- u->channels = nil;
- return u;
-}
-
-static User *
userget(char *nick)
{
User *u;
@@ -186,7 +163,8 @@
runesnprint(key, nelem(key), "%s", nick);
u = trieget(users, key);
if(u == nil){
- u = useralloc(nick);
+ u = emalloc(sizeof(User));
+ snprint(u->nick, sizeof(u->nick), "%s", nick);
trieadd(users, key, u);
}
return u;
@@ -231,7 +209,8 @@
char buf[Bufsize];
int n;
- if(*msg != 0 && log->fd > 0){
+ assert(log->fd > 0);
+ if(*msg != 0){
if(timestamps){
if(rawlog)
n = snprint(buf, sizeof(buf),