#include <config.h>
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "sort.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
+#include <libgen.h>
#include <sys/stat.h>
void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
nntp_add_to_list (news, data);
}
else
- mem_free ((void **) &data->entries);
+ p_delete(&data->entries);
data->rc = 1;
data->entries = mem_calloc (x * 2, sizeof (NEWSRC_ENTRY));
return -1;
}
- buf = mem_malloc (sb.st_size + 1);
+ buf = p_new(char, sb.st_size + 1);
while (fgets (buf, sb.st_size + 1, fp))
nntp_parse_newsrc_line (news, buf);
- mem_free (&buf);
+ p_delete(&buf);
mx_unlock_file (news->newsrc, fileno (fp), 0);
fclose (fp);
set_option (OPTNEWSCACHE);
- mem_free (&news->cache);
+ p_delete(&news->cache);
snprintf (buf, sizeof (buf), "%s/.index", dir);
if (!(index = safe_fopen (buf, "a+")))
return 0;
ret = mutt_account_fromurl (acct, &url);
}
- mem_free (&c);
+ p_delete(&c);
return ret;
}
url.path = str_dup (line);
mutt_account_tourl (acct, &url);
url_ciss_tostring (&url, line, len, 0);
- mem_free (&url.path);
+ p_delete(&url.path);
}
/*
NNTP_SERVER *serv;
CONNECTION *conn;
+ memset (&acct, 0, sizeof (ACCOUNT));
+
if (!server || !*server) {
mutt_error _("No newsserver defined!");
strcpy (p, server);
if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
- mem_free (&buf);
+ p_delete(&buf);
mutt_error (_("%s is an invalid newsserver specification!"), server);
return NULL;
}
- mem_free (&buf);
+ p_delete(&buf);
conn = mutt_conn_find (NULL, &acct);
if (!conn)
for (list = serv->list; list; list = list->next)
list->data = NULL;
mutt_free_list (&serv->list);
- mem_free (&serv->newsrc);
- mem_free (&serv->cache);
- mem_free (&serv);
+ p_delete(&serv->newsrc);
+ p_delete(&serv->cache);
+ p_delete(&serv);
return NULL;
}
nntp_clear_cacheindex (serv);
FILE *ifp;
FILE *ofp;
char buf[HUGE_STRING];
- char tmpfile[_POSIX_PATH_MAX];
+ char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
char *c;
- int ext = 0, done = 0, r = 0;
+ int ext = 0, done = 0, r = 0, l = 0;
/* if file not exist, create it */
if ((ifp = safe_fopen (filename, "a")))
mutt_error (_("Unable to lock %s"), filename);
return -1;
}
- snprintf (tmpfile, sizeof(tmpfile), "%s.tmp", filename);
+ /* use mutt_adv_mktemp() 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
+ */
+ strncpy (buf, filename, sizeof (buf));
+ strncpy (tmpfile, basename (filename), sizeof (tmpfile));
+ mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
debug_print (1, ("Opening %s\n", tmpfile));
if (!(ofp = fopen (tmpfile, "w"))) {
fclose (ifp);
mutt_error (_("Can't write %s"), tmpfile);
return -1;
}
- if (rename (tmpfile, filename) < 0) {
+ link[0] = '\0';
+ if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
+ link[l] = '\0';
+ debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename));
+ if (rename (tmpfile, l > 0 ? link : filename) < 0) {
unlink (tmpfile);
- mutt_error (_("Can't rename %s to %s"), tmpfile, filename);
+ mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
return -1;
}
return 0;
news->size = st.st_size;
news->mtime = st.st_mtime;
}
- mem_free (&buf);
+ p_delete(&buf);
return r;
}
fputs (buf, f);
if (h->env->references)
mutt_write_references (h->env->references, f);
- snprintf (buf, sizeof (buf), "\t%ld\t%d\tXref: %s\n",
+ 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);
nntp_cache_expand (buf, data->cache);
unlink (buf);
- mem_free (&data->cache);
+ p_delete(&data->cache);
data->lastCached = 0;
nntp_cache_expand (buf, ".index");
mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
NNTP_DATA *data = (NNTP_DATA *) list->data;
if (data && data->subscribed && data->unread &&
Context && Context->magic == M_NNTP &&
- str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0)
+ str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
+ list = list->next;
break;
+ }
}
*dst = '\0';