From e3c03b4252d4d86369538dd2fab3f023639dfb35 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 27 May 2007 22:29:47 +0200 Subject: [PATCH] style Signed-off-by: Pierre Habouzit --- nntp.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) 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) -- 2.20.1