projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
style
[apps/madmutt.git]
/
nntp.c
diff --git
a/nntp.c
b/nntp.c
index
9319c38
..
78935ce
100644
(file)
--- 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)
{
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)
}
static void nntp_cache_expand (char *dst, const char *src)