X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp.c;h=78935ce01d78092ebb4fc31fe16a5febc1495f1d;hp=9319c38ce48e8876f68113de5b9683ed0452bffa;hb=e3c03b4252d4d86369538dd2fab3f023639dfb35;hpb=7768c028980b5fb468decf4fbfbd640082c321b2 diff --git a/nntp.c b/nntp.c index 9319c38..78935ce 100644 --- a/nntp.c +++ b/nntp.c @@ -105,30 +105,32 @@ static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) static int slurp_newsrc (nntp_server_t * news) { - FILE *fp; - char *buf; - struct stat sb; + FILE *fp; + char *buf = NULL; + size_t n = 0; + struct stat sb; - news->stat = stat (news->newsrc, &sb); - news->size = sb.st_size; - news->mtime = sb.st_mtime; + news->stat = stat(news->newsrc, &sb); + news->size = sb.st_size; + news->mtime = sb.st_mtime; - if ((fp = safe_fopen (news->newsrc, "r")) == NULL) - return -1; - /* hmm, should we use dotlock? */ - if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) { - m_fclose(&fp); - return -1; - } + if ((fp = safe_fopen(news->newsrc, "r")) == NULL) + return -1; - buf = p_new(char, sb.st_size + 1); - while (fgets(buf, sb.st_size + 1, fp)) - nntp_parse_newsrc_line(news, buf); - p_delete(&buf); + /* hmm, should we use dotlock? */ + if (mx_lock_file(news->newsrc, fileno (fp), 0, 0, 1)) { + m_fclose(&fp); + return -1; + } - mx_unlock_file (news->newsrc, fileno (fp), 0); - m_fclose(&fp); - return 0; + while (getline(&buf, &n, fp)) { + nntp_parse_newsrc_line(news, buf); + } + p_delete(&buf); + + mx_unlock_file (news->newsrc, fileno (fp), 0); + m_fclose(&fp); + return 0; } static void nntp_cache_expand (char *dst, const char *src)