On Mon, Dec 08, 2003 at 10:49:20AM -0800, Wayne Davison wrote: > The other possible fix would be to change trn to not use fgets() in > nntp_gets(), but to instead read every character one at a time Attached is a patch that should implement this. I haven't tested it, though, so feel free to give it a try, if you like. ..wayne..
--- nntpclient.c 30 Sep 2003 22:17:37 -0000 1.2 +++ nntpclient.c 8 Dec 2003 20:13:27 -0000 @@ -248,42 +248,44 @@ return 0; } +/* This returns 1 when it reads a full line, 0 if it reads a partial + * line, and -2 on error/EOF. + */ int nntp_gets(bp, len) char* bp; int len; { - int n; + int ch, n = 0; + char* cp = bp; - read_it: #ifdef HAS_SIGHOLD sighold(SIGINT); #endif - errno = 0; - n = (fgets(bp, len, nntplink.rd_fp) == NULL)? -2 : 0; + while (len > 1) { + do { + errno = 0; + ch = fgetc(nntplink.rd_fp); + } while (errno == EINTR); + if (ch == EOF) { + nntplink.flags |= NNTP_NEW_CMD_OK; + n = -2; + break; + } + if (ch == '\n') { + if (cp != bp && cp[-1] == '\r') + cp--; + n = 1; + break; + } + *cp++ = ch; + len--; + } + *cp = '\0'; #ifdef HAS_SIGHOLD sigrelse(SIGINT); #endif - if (n < 0) { - if (errno == EINTR) - goto read_it; - nntplink.flags |= NNTP_NEW_CMD_OK; - return n; - } - n = strlen(bp); - if (n > 0) { - /* check for CR/LF split across the buffer boundry */ - if (bp[n-1] == '\r') - bp[n-1] = '\0'; - else if (bp[n-1] == '\n') { - if (n > 1 && bp[n-2] == '\r') - bp[n-2] = '\0'; - else - bp[n-1] = '\0'; - return 1; - } - } - return 0; + return n; } void