From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com
Subject: [PATCH 1/2] Factor out make_temp_file
Date: Tue, 01 Jan 2019 00:00:00 -0000 [thread overview]
Message-ID: <20190215111143.GA30045@delia> (raw)
Hi,
Factor out new function make_temp_file from main, making main easier to read
and the temporary file handling easier to maintain.
OK for trunk?
Thanks,
- Tom
Factor out make_temp_file
2019-02-15 Tom de Vries <tdevries@suse.de>
* dwz.c (make_temp_file): New function, factor out of ...
(main): ... here.
---
dwz.c | 50 +++++++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/dwz.c b/dwz.c
index d348418..c8ada61 100644
--- a/dwz.c
+++ b/dwz.c
@@ -11794,6 +11794,30 @@ version (void)
exit (0);
}
+/* Create a temporary file using TEMPLATE. Return the corresponding file
+ descriptor if successful, otherwise return -1. */
+static int
+make_temp_file (const char *template)
+{
+ char buf[sizeof "/tmp/dwz.debug_abbrev.XXXXXX"];
+ int fd;
+ size_t template_len;
+
+ template_len = strlen (template);
+ assert (template_len + 1 <= sizeof buf);
+ strncpy (buf, template, sizeof buf);
+
+ fd = mkstemp (buf);
+ if (fd == -1)
+ return fd;
+
+ /* Unlink the filename, such that the file is disposed of once the file
+ descriptor is closed. */
+ unlink (buf);
+
+ return fd;
+}
+
int
main (int argc, char *argv[])
{
@@ -11897,27 +11921,11 @@ main (int argc, char *argv[])
error (1, 0, "-o option not allowed for multiple files");
if (multifile)
{
- char buf[sizeof "/tmp/dwz.debug_abbrev.XXXXXX"];
- strcpy (buf, "/tmp/dwz.debug_info.XXXXXX");
- multi_info_fd = mkstemp (buf);
- if (multi_info_fd != -1)
- unlink (buf);
- strcpy (buf, "/tmp/dwz.debug_abbrev.XXXXXX");
- multi_abbrev_fd = mkstemp (buf);
- if (multi_abbrev_fd != -1)
- unlink (buf);
- strcpy (buf, "/tmp/dwz.debug_line.XXXXXX");
- multi_line_fd = mkstemp (buf);
- if (multi_line_fd != -1)
- unlink (buf);
- strcpy (buf, "/tmp/dwz.debug_str.XXXXXX");
- multi_str_fd = mkstemp (buf);
- if (multi_str_fd != -1)
- unlink (buf);
- strcpy (buf, "/tmp/dwz.debug_macro.XXXXXX");
- multi_macro_fd = mkstemp (buf);
- if (multi_macro_fd != -1)
- unlink (buf);
+ multi_info_fd = make_temp_file ("/tmp/dwz.debug_info.XXXXXX");
+ multi_abbrev_fd = make_temp_file ("/tmp/dwz.debug_abbrev.XXXXXX");
+ multi_line_fd = make_temp_file ("/tmp/dwz.debug_line.XXXXXX");
+ multi_str_fd = make_temp_file ("/tmp/dwz.debug_str.XXXXXX");
+ multi_macro_fd = make_temp_file ("/tmp/dwz.debug_macro.XXXXXX");
if (multi_info_fd == -1
|| multi_abbrev_fd == -1
|| multi_line_fd == -1
reply other threads:[~2019-02-15 11:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190215111143.GA30045@delia \
--to=tdevries@suse.de \
--cc=dwz@sourceware.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).