diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2015-08-10 11:47:44 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-10 12:57:14 -0700 |
commit | 99397152a345011c99497b93f8518c7981e811a5 (patch) | |
tree | 94413563c2fcdfa2ccbcfd38ca29a3e4e3a2620d /tempfile.c | |
parent | 354ab1120665f691c17b21fdb04c4362c8088dfa (diff) | |
download | git-99397152a345011c99497b93f8518c7981e811a5.tar.gz git-99397152a345011c99497b93f8518c7981e811a5.tar.xz |
register_tempfile(): new function to handle an existing temporary file
Allow an existing file to be registered with the tempfile-handling
infrastructure; in particular, arrange for it to be deleted on program
exit. This can be used if the temporary file has to be created in a
more complicated way than just open(). For example:
* If the file itself needs to be created via the lockfile API
* If it is not a regular file (e.g., a socket)
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tempfile.c')
-rw-r--r-- | tempfile.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tempfile.c b/tempfile.c index 0b5d8ce92..0af7ebf01 100644 --- a/tempfile.c +++ b/tempfile.c @@ -137,6 +137,14 @@ int create_tempfile(struct tempfile *tempfile, const char *path) return tempfile->fd; } +void register_tempfile(struct tempfile *tempfile, const char *path) +{ + prepare_tempfile_object(tempfile); + strbuf_add_absolute_path(&tempfile->filename, path); + tempfile->owner = getpid(); + tempfile->active = 1; +} + int mks_tempfile_sm(struct tempfile *tempfile, const char *template, int suffixlen, int mode) { |