[PATCH 2/4] Clean up tempdir definitions and file locations.

"Kevin J. McCarthy" <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <[email protected]>
Group all the tempdir protos together in protos.h and definitions in
muttlib.c.

Add underscore prefix to mutt_buffer_mktemp_pfx_sfx(), to make it
obvious that there are no, and shouldn't be any, external direct
callers to this function.

All external callers should use either mutt_adv_mktemp() with a
template parameter or else mutt_buffer_mktemp().
---
 muttlib.c | 32 ++++++++++++++++----------------
 protos.h  |  9 +++++----
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/muttlib.c b/muttlib.c
index 8c5b94a3..2022ee61 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -88,13 +88,28 @@ void mutt_adv_mktemp (BUFFER *buf)
       *suffix = 0;
       ++suffix;
     }
-    mutt_buffer_mktemp_pfx_sfx (buf, mutt_b2s (prefix), suffix);
+    _mutt_buffer_mktemp_pfx_sfx (buf, mutt_b2s (prefix), suffix);
 
   out:
     mutt_buffer_pool_release (&prefix);
   }
 }
 
+void _mutt_buffer_mktemp (BUFFER *buf, const char *prefix, const char *suffix,
+                          const char *src, int line)
+{
+  RANDOM64 random64;
+  mutt_random_bytes(random64.char_array, sizeof(random64));
+
+  mutt_buffer_printf (buf, "%s/%s-%s-%d-%d-%"PRIu64"%s%s",
+                      NONULL (Tempdir), NONULL (prefix), NONULL (Hostname),
+                      (int) getuid (), (int) getpid (), random64.int_64,
+                      suffix ? "." : "", NONULL (suffix));
+  muttdbg(3, "%s:%d: mutt_mktemp returns \"%s\".", src, line, mutt_b2s (buf));
+  if (unlink (mutt_b2s (buf)) && errno != ENOENT)
+    mutt_errno_dbg(1, "%s:%d: ERROR: unlink(\"%s\")", src, line, mutt_b2s (buf));
+}
+
 /* create a send-mode duplicate from a receive-mode body */
 
 int mutt_copy_body (FILE *fp, BODY **tgt, BODY *src)
@@ -959,21 +974,6 @@ void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
   mutt_free_envelope(extra);
 }
 
-void _mutt_buffer_mktemp (BUFFER *buf, const char *prefix, const char *suffix,
-                          const char *src, int line)
-{
-  RANDOM64 random64;
-  mutt_random_bytes(random64.char_array, sizeof(random64));
-
-  mutt_buffer_printf (buf, "%s/%s-%s-%d-%d-%"PRIu64"%s%s",
-                      NONULL (Tempdir), NONULL (prefix), NONULL (Hostname),
-                      (int) getuid (), (int) getpid (), random64.int_64,
-                      suffix ? "." : "", NONULL (suffix));
-  muttdbg(3, "%s:%d: mutt_mktemp returns \"%s\".", src, line, mutt_b2s (buf));
-  if (unlink (mutt_b2s (buf)) && errno != ENOENT)
-    mutt_errno_dbg(1, "%s:%d: ERROR: unlink(\"%s\")", src, line, mutt_b2s (buf));
-}
-
 /* these characters must be escaped in regular expressions */
 
 static const char rx_special_chars[] = "^.[$()|*+?{\\";
diff --git a/protos.h b/protos.h
index 10689e7a..2c6b1aef 100644
--- a/protos.h
+++ b/protos.h
@@ -172,8 +172,12 @@ group_t *mutt_pattern_group (const char *);
 
 REGEXP *mutt_compile_regexp (const char *, int);
 
-void mutt_account_hook (const char* url);
 void mutt_adv_mktemp (BUFFER *);
+#define mutt_buffer_mktemp(a) _mutt_buffer_mktemp_pfx_sfx (a, "mutt", NULL)
+#define _mutt_buffer_mktemp_pfx_sfx(a,b,c)  _mutt_buffer_mktemp (a, b, c, __FILE__, __LINE__)
+void _mutt_buffer_mktemp (BUFFER *, const char *, const char *, const char *, int);
+
+void mutt_account_hook (const char* url);
 void mutt_alias_menu (char *, size_t, ALIAS *);
 void mutt_allow_interrupt (int);
 void mutt_auto_subscribe (const char *);
@@ -246,9 +250,6 @@ void mutt_list_menu (CONTEXT *ctx, HEADER *cur);
 void mutt_make_help (char *, size_t, const char *, int, int);
 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra);
 void mutt_message_to_7bit (BODY *, FILE *);
-#define mutt_buffer_mktemp(a) mutt_buffer_mktemp_pfx_sfx (a, "mutt", NULL)
-#define mutt_buffer_mktemp_pfx_sfx(a,b,c)  _mutt_buffer_mktemp (a, b, c, __FILE__, __LINE__)
-void _mutt_buffer_mktemp (BUFFER *, const char *, const char *, const char *, int);
 void mutt_normalize_time (struct tm *);
 void mutt_paddstr (int, const char *);
 void mutt_parse_mime_message (CONTEXT *ctx, HEADER *);
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.