various fixes, remove an adv_mktemp
authorPierre Habouzit <madcoder@debian.org>
Sat, 25 Nov 2006 00:46:46 +0000 (01:46 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sat, 25 Nov 2006 00:46:46 +0000 (01:46 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
nntp/newsrc.c
postpone.c
recvcmd.c

index bb477f5..349e3e7 100644 (file)
@@ -55,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);
@@ -613,7 +611,7 @@ 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 tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX];
+  char tmpf[_POSIX_PATH_MAX], lnk[_POSIX_PATH_MAX];
   char *c;
   int ext = 0, done = 0, r = 0, l = 0;
 
   char *c;
   int ext = 0, done = 0, r = 0, l = 0;
 
@@ -629,17 +627,17 @@ static int mutt_update_list_file (char *filename, char *section,
     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"))) {
+  ofp = m_tempfile(tmpf, sizeof(tmpf), dirname(buf), filename);
+  if (!ofp) {
     m_fclose(&ifp);
     m_fclose(&ifp);
-    mutt_error (_("Unable to open %s for writing"), tmpfile);
+    mutt_error (_("Unable to open %s for writing"), tmpf);
     return -1;
   }
 
     return -1;
   }
 
@@ -703,16 +701,16 @@ static int mutt_update_list_file (char *filename, char *section,
   m_fclose(&ofp);
   m_fclose(&ifp);
   if (r == EOF) {
   m_fclose(&ofp);
   m_fclose(&ifp);
   if (r == EOF) {
-    unlink (tmpfile);
-    mutt_error (_("Can't write %s"), tmpfile);
+    unlink (tmpf);
+    mutt_error (_("Can't write %s"), tmpf);
     return -1;
   }
     return -1;
   }
-  link[0] = '\0';
-  if ((l = readlink (filename, link, sizeof (link)-1)) > 0)
-    link[l] = '\0';
-  if (rename (tmpfile, l > 0 ? link : filename) < 0) {
-    unlink (tmpfile);
-    mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename);
+  lnk[0] = '\0';
+  if ((l = readlink (filename, lnk, sizeof(lnk)-1)) > 0)
+    lnk[l] = '\0';
+  if (rename (tmpf, l > 0 ? lnk : filename) < 0) {
+    unlink (tmpf);
+    mutt_error (_("Can't rename %s to %s"), tmpf, l > 0 ? lnk : filename);
     return -1;
   }
   return 0;
     return -1;
   }
   return 0;
index d8d8cf5..5fda6ce 100644 (file)
@@ -604,11 +604,10 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
       parameter_delval(&b->parameter, "x-mutt-noconv");
     }
 
       parameter_delval(&b->parameter, "x-mutt-noconv");
     }
 
-    mutt_adv_mktemp (NULL, file, sizeof (file));
-    if ((s.fpout = safe_fopen (file, "w")) == NULL)
+    s.fpout = m_tempfile(file, sizeof(file), NONULL(Tempdir), file);
+    if (!s.fpout)
       goto bail;
 
       goto bail;
 
-
     if (mutt_is_application_pgp (b) & (ENCRYPT | SIGN)) {
 
       mutt_body_handler (b, &s);
     if (mutt_is_application_pgp (b) & (ENCRYPT | SIGN)) {
 
       mutt_body_handler (b, &s);
index f614ec9..45dec59 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -329,8 +329,7 @@ static int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
   if (src->filename) {
     use_disp = 1;
     m_strcpy(tmp, sizeof(tmp), src->filename);
   if (src->filename) {
     use_disp = 1;
     m_strcpy(tmp, sizeof(tmp), src->filename);
-  }
-  else {
+  } else {
     use_disp = 0;
     tmp[0] = '\0';
   }
     use_disp = 0;
     tmp[0] = '\0';
   }