Advertisement
tm512

irc_getln

Jan 10th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. int irc_getln (ircclient_t *cl, char *buf)
  2. {
  3.     char *pos = NULL;
  4.     char tmpbuf [MAXBUF] = { 0 };
  5.  
  6.     while ((pos = strstr (cl->rbuf, "\r\n")) == NULL)
  7.     {
  8.         memset (tmpbuf, 0, MAXBUF);
  9.  
  10.         if (net_recv (cl->s, tmpbuf, MAXBUF - strlen (cl->rbuf)) <= 0) // failed to recieve anything
  11.             return 1;
  12.  
  13.         // Copy tmpbuf into the recvbuf
  14.         memcpy (cl->rbuf + strlen (cl->rbuf), tmpbuf, MAXBUF - strlen (cl->rbuf));
  15.     }
  16.  
  17.     // Copy line to buf, add \0
  18.     memcpy (buf, cl->rbuf, pos + 2 - cl->rbuf);
  19.     strstr (buf, "\r\n") [2] = '\0';
  20.  
  21.     // shift the recvbuf back
  22.     memset (tmpbuf, 0, MAXBUF);
  23.     memcpy (tmpbuf, pos + 2, MAXBUF - (pos + 2 - cl->rbuf));
  24.     memcpy (cl->rbuf, tmpbuf, MAXBUF);
  25.  
  26.     return strlen (buf);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement