+ else if(strncmp("PING", cmd, 4) == 0 && txt != NULL) {
+ snprintf(bufout, sizeof bufout, "PONG %s\r\n", txt);
+ write(srv, bufout, strlen(bufout));
+ }
+ else {
+ if (txt != NULL)
+ (void) snprintf(bufout, sizeof bufout, ">< %s: %s", cmd, txt);
+ else
+ (void) snprintf(bufout, sizeof bufout, ">< %s: ", cmd);
+ printl(usr, bufout);
+ if(strncmp("NICK", cmd, 4) == 0 && strncmp(usr, nick, sizeof nick) == 0 && txt != NULL)
+ strncpy(nick, txt, sizeof nick - 1);
+ }
+}
+
+int
+readl(int fd, unsigned int len, char *buf) {
+ unsigned int i = 0;
+ char c = '\0';
+
+ do {
+ if(read(fd, &c, sizeof(char)) != (ssize_t) sizeof(char))
+ return -1;
+ buf[i++] = c;
+ }
+ while(c != '\n' && i < len);
+ buf[i - 1] = '\0';
+ return 0;