projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
oops, ascii_strncasecmp tried to compare one byte too far
[apps/madmutt.git]
/
nntp
/
newsrc.c
diff --git
a/nntp/newsrc.c
b/nntp/newsrc.c
index
3b8e1fa
..
178594e
100644
(file)
--- a/
nntp/newsrc.c
+++ b/
nntp/newsrc.c
@@
-9,29
+9,16
@@
* please see the file GPL in the top level source directory.
*/
* please see the file GPL in the top level source directory.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <libgen.h>
-#include <sys/stat.h>
+#include <lib-lib/lib-lib.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/file.h>
-#include <lib-lib/macros.h>
+#include <libgen.h>
#include <lib-mime/mime.h>
#include <lib-mime/mime.h>
-
#include <lib-ui/curses.h>
#include <lib-ui/curses.h>
+#include <lib-mx/mx.h>
#include "mutt.h"
#include "sort.h"
#include "mutt.h"
#include "sort.h"
-#include "mx.h"
#include "nntp.h"
void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
#include "nntp.h"
void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
@@
-68,9
+55,7
@@
static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
p++;
if (!*p)
return -1;
p++;
if (!*p)
return -1;
- len = p + 1 - line;
- if (len > sizeof (group))
- len = sizeof (group);
+ len = MIN(p + 1 - line, ssizeof(group));
m_strcpy(group, len, line);
if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
m_strcpy(group, len, line);
if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1);
@@
-142,7
+127,7
@@
static int slurp_newsrc (NNTP_SERVER * news)
return -1;
/* hmm, should we use dotlock? */
if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
return -1;
/* hmm, should we use dotlock? */
if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) {
-
fclose (
fp);
+
m_fclose(&
fp);
return -1;
}
return -1;
}
@@
-152,7
+137,7
@@
static int slurp_newsrc (NNTP_SERVER * news)
p_delete(&buf);
mx_unlock_file (news->newsrc, fileno (fp), 0);
p_delete(&buf);
mx_unlock_file (news->newsrc, fileno (fp), 0);
-
fclose (
fp);
+
m_fclose(&
fp);
return 0;
}
return 0;
}
@@
-248,7
+233,7
@@
static int nntp_parse_cacheindex (NNTP_SERVER * news)
mutt_newsgroup_stat (data);
}
}
mutt_newsgroup_stat (data);
}
}
-
fclose (
idx);
+
m_fclose(&
idx);
return 0;
}
return 0;
}
@@
-257,7
+242,7
@@
const char *nntp_format_str (char *dest, ssize_t destlen, char op,
const char *ifstring, const char *elsestring,
unsigned long data, format_flag flags)
{
const char *ifstring, const char *elsestring,
unsigned long data, format_flag flags)
{
- char fn[S
HORT_STRING], tmp[SHORT_
STRING];
+ char fn[S
TRING], tmp[
STRING];
switch (op) {
case 's':
switch (op) {
case 's':
@@
-526,15
+511,6
@@
static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
len--;
}
len--;
}
-#if 0
- if (data->entries[x].first == data->entries[x].last)
- snprintf (line, len, "%d%n", data->entries[x].first, &i);
- else
- snprintf (line, len, "%d-%d%n",
- data->entries[x].first, data->entries[x].last, &i);
- len -= i;
- line += i;
-#else
i = puti (line, data->entries[x].first);
line += i;
len -= i;
i = puti (line, data->entries[x].first);
line += i;
len -= i;
@@
-545,7
+521,6
@@
static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
line += i;
len -= i;
}
line += i;
len -= i;
}
-#endif
}
*line++ = '\n';
*line = '\0';
}
*line++ = '\n';
*line = '\0';
@@
-626,33
+601,33
@@
static int mutt_update_list_file (char *filename, char *section,
FILE *ifp;
FILE *ofp;
char buf[HUGE_STRING];
FILE *ifp;
FILE *ofp;
char buf[HUGE_STRING];
- char tmpf
ile[_POSIX_PATH_MAX], li
nk[_POSIX_PATH_MAX];
+ char tmpf
[_POSIX_PATH_MAX], l
nk[_POSIX_PATH_MAX];
char *c;
int ext = 0, done = 0, r = 0, l = 0;
/* if file not exist, create it */
if ((ifp = safe_fopen (filename, "a")))
char *c;
int ext = 0, done = 0, r = 0, l = 0;
/* if file not exist, create it */
if ((ifp = safe_fopen (filename, "a")))
-
fclose (
ifp);
+
m_fclose(&
ifp);
if (!(ifp = safe_fopen (filename, "r"))) {
mutt_error (_("Unable to open %s for reading"), filename);
return -1;
}
if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
if (!(ifp = safe_fopen (filename, "r"))) {
mutt_error (_("Unable to open %s for reading"), filename);
return -1;
}
if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) {
-
fclose (
ifp);
+
m_fclose(&
ifp);
mutt_error (_("Unable to lock %s"), filename);
return -1;
}
mutt_error (_("Unable to lock %s"), filename);
return -1;
}
- /* use mutt_adv_mktemp() to get a tempfile in the same
+
+ /* use m_tempfile() to get a tempfile in the same
* directory as filename is so that we can follow symlinks
* via rename(2); as dirname(2) may modify its argument,
* temporarily use buf as copy of it
*/
m_strcpy(buf, sizeof(buf), filename);
* directory as filename is so that we can follow symlinks
* via rename(2); as dirname(2) may modify its argument,
* temporarily use buf as copy of it
*/
m_strcpy(buf, sizeof(buf), filename);
- m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
- mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
- if (!(ofp = fopen (tmpfile, "w"))) {
- fclose (ifp);
- mutt_error (_("Unable to open %s for writing"), tmpfile);
+ ofp = m_tempfile(tmpf, sizeof(tmpf), dirname(buf), filename);
+ if (!ofp) {
+ m_fclose(&ifp);
+ mutt_error (_("Unable to open %s for writing"), tmpf);
return -1;
}
return -1;
}
@@
-713,19
+688,19
@@
static int mutt_update_list_file (char *filename, char *section,
r = fputc ('\n', ofp);
}
mx_unlock_file (filename, fileno (ifp), 0);
r = fputc ('\n', ofp);
}
mx_unlock_file (filename, fileno (ifp), 0);
-
fclose (
ofp);
-
fclose (
ifp);
+
m_fclose(&
ofp);
+
m_fclose(&
ifp);
if (r == EOF) {
if (r == EOF) {
- unlink (tmpf
ile
);
- mutt_error (_("Can't write %s"), tmpf
ile
);
+ unlink (tmpf);
+ mutt_error (_("Can't write %s"), tmpf);
return -1;
}
return -1;
}
- l
i
nk[0] = '\0';
- if ((l = readlink (filename, l
ink, sizeof (li
nk)-1)) > 0)
- l
i
nk[l] = '\0';
- if (rename (tmpf
ile, l > 0 ? li
nk : filename) < 0) {
- unlink (tmpf
ile
);
- mutt_error (_("Can't rename %s to %s"), tmpf
ile, l > 0 ? li
nk : filename);
+ lnk[0] = '\0';
+ if ((l = readlink (filename, l
nk, sizeof(l
nk)-1)) > 0)
+ lnk[l] = '\0';
+ if (rename (tmpf
, l > 0 ? l
nk : filename) < 0) {
+ unlink (tmpf);
+ mutt_error (_("Can't rename %s to %s"), tmpf
, l > 0 ? l
nk : filename);
return -1;
}
return 0;
return -1;
}
return 0;
@@
-861,13
+836,13
@@
int nntp_save_cache_index (NNTP_SERVER * news)
snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
if (fputs (buf, f) == EOF) {
snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
if (fputs (buf, f) == EOF) {
-
fclose (
f);
+
m_fclose(&
f);
unlink (file);
return -1;
}
}
}
unlink (file);
return -1;
}
}
}
-
fclose (
f);
+
m_fclose(&
f);
if (nntp_update_cacheindex (news, NULL)) {
unlink (file);
if (nntp_update_cacheindex (news, NULL)) {
unlink (file);
@@
-921,7
+896,7
@@
int nntp_save_cache_group (CONTEXT * ctx)
if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
h = ctx->hdrs[i];
addr[0] = 0;
if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) {
h = ctx->hdrs[i];
addr[0] = 0;
- rfc822_
write_address (addr, sizeof
(addr), h->env->from, 0);
+ rfc822_
addrcat(addr, sizeof
(addr), h->env->from, 0);
tm = gmtime (&h->date_sent);
snprintf (buf, sizeof (buf),
"%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
tm = gmtime (&h->date_sent);
snprintf (buf, sizeof (buf),
"%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
@@
-934,7
+909,7
@@
int nntp_save_cache_group (CONTEXT * ctx)
snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
h->content->length, h->lines, NONULL (h->env->xref));
if (fputs (buf, f) == EOF) {
snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n",
h->content->length, h->lines, NONULL (h->env->xref));
if (fputs (buf, f) == EOF) {
-
fclose (
f);
+
m_fclose(&
f);
unlink (file);
return -1;
}
unlink (file);
return -1;
}
@@
-946,7
+921,7
@@
int nntp_save_cache_group (CONTEXT * ctx)
Sort = save;
mutt_sort_headers (ctx, 0);
}
Sort = save;
mutt_sort_headers (ctx, 0);
}
-
fclose (
f);
+
m_fclose(&
f);
if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
(NNTP_DATA *) ctx->data)) {
if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv,
(NNTP_DATA *) ctx->data)) {