diff options
author | René Scharfe <l.s.r@web.de> | 2022-04-20 23:26:09 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-04-21 02:17:33 +0300 |
commit | 2c2db194bd9e2f2dda7f1a47d26a1f86b3dd635a (patch) | |
tree | 9502d330ff313ff1c774945203bb10c843deb615 /tempfile.h | |
parent | 6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e (diff) |
tempfile: add mks_tempfile_dt()
Add a function to create a temporary file with a certain name in a
temporary directory created using mkdtemp(3). Its result is more
sightly than the paths created by mks_tempfile_ts(), which include
a random prefix. That's useful for files passed to a program that
displays their name, e.g. an external diff tool.
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tempfile.h')
-rw-r--r-- | tempfile.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tempfile.h b/tempfile.h index 4de3bc77d2..d7804a214a 100644 --- a/tempfile.h +++ b/tempfile.h @@ -82,6 +82,7 @@ struct tempfile { FILE *volatile fp; volatile pid_t owner; struct strbuf filename; + size_t directorylen; }; /* @@ -199,6 +200,18 @@ static inline struct tempfile *xmks_tempfile(const char *filename_template) } /* + * Attempt to create a temporary directory in $TMPDIR and to create and + * open a file in that new directory. Derive the directory name from the + * template in the manner of mkdtemp(). Arrange for directory and file + * to be deleted if the program exits before they are deleted + * explicitly. On success return a tempfile whose "filename" member + * contains the full path of the file and its "fd" member is open for + * writing the file. On error return NULL and set errno appropriately. + */ +struct tempfile *mks_tempfile_dt(const char *directory_template, + const char *filename); + +/* * Associate a stdio stream with the temporary file (which must still * be open). Return `NULL` (*without* deleting the file) on error. The * stream is closed automatically when `close_tempfile_gently()` is called or |