From: Michael Haggerty Date: Mon, 08 Jun 2015 09:07:36 GMT Subject: [PATCH 05/14] register_tempfile_object(): new function, extracted from create_tempfile() Message-ID: <608b8507531b9184f0cf01de084390633e4506d5.1433751986.git.mhagger@alum.mit.edu> In-Reply-To: This makes the next step easier. Signed-off-by: Michael Haggerty --- tempfile.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tempfile.c b/tempfile.c index bde7fd3..f76bc07 100644 --- a/tempfile.c +++ b/tempfile.c @@ -31,11 +31,8 @@ static void remove_tempfiles_on_signal(int signo) raise(signo); } -/* Make sure errno contains a meaningful value on error */ -int create_tempfile(struct tempfile *tempfile, const char *path) +static void register_tempfile_object(struct tempfile *tempfile, const char *path) { - size_t pathlen = strlen(path); - if (!tempfile_list) { /* One-time initialization */ sigchain_push_common(remove_tempfiles_on_signal); @@ -51,7 +48,7 @@ int create_tempfile(struct tempfile *tempfile, const char *path) tempfile->fp = NULL; tempfile->active = 0; tempfile->owner = 0; - strbuf_init(&tempfile->filename, pathlen); + strbuf_init(&tempfile->filename, strlen(path)); tempfile->next = tempfile_list; tempfile_list = tempfile; tempfile->on_list = 1; @@ -60,6 +57,12 @@ int create_tempfile(struct tempfile *tempfile, const char *path) die("BUG: tempfile(\"%s\") called with improperly-reset tempfile object", path); } +} + +/* Make sure errno contains a meaningful value on error */ +int create_tempfile(struct tempfile *tempfile, const char *path) +{ + register_tempfile_object(tempfile, path); strbuf_add_absolute_path(&tempfile->filename, path); tempfile->fd = open(tempfile->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666); -- 2.1.4