From: Pierre Habouzit Date: Sun, 27 May 2007 20:29:47 +0000 (+0200) Subject: style X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=e3c03b4252d4d86369538dd2fab3f023639dfb35;p=apps%2Fmadmutt.git style Signed-off-by: Pierre Habouzit --- 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)