mirror of
https://github.com/git/git.git
synced 2024-05-12 05:56:09 +02:00
prepare_tempfile_object(): new function, extracted from create_tempfile()
This makes the next step easier. The old code used to use "path" to set the initial length of tempfile->filename. This was not helpful because path was usually relative whereas the value stored to filename will be absolute. So just initialize the length to 0. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1a9d15db25
commit
7eba6ce5c7
20
tempfile.c
20
tempfile.c
|
@ -85,11 +85,11 @@ static void remove_tempfiles_on_signal(int signo)
|
||||||
raise(signo);
|
raise(signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure errno contains a meaningful value on error */
|
/*
|
||||||
int create_tempfile(struct tempfile *tempfile, const char *path)
|
* Initialize *tempfile if necessary and add it to tempfile_list.
|
||||||
|
*/
|
||||||
|
static void prepare_tempfile_object(struct tempfile *tempfile)
|
||||||
{
|
{
|
||||||
size_t pathlen = strlen(path);
|
|
||||||
|
|
||||||
if (!tempfile_list) {
|
if (!tempfile_list) {
|
||||||
/* One-time initialization */
|
/* One-time initialization */
|
||||||
sigchain_push_common(remove_tempfiles_on_signal);
|
sigchain_push_common(remove_tempfiles_on_signal);
|
||||||
|
@ -97,21 +97,27 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempfile->active)
|
if (tempfile->active)
|
||||||
die("BUG: create_tempfile called for active object");
|
die("BUG: prepare_tempfile_object called for active object");
|
||||||
if (!tempfile->on_list) {
|
if (!tempfile->on_list) {
|
||||||
/* Initialize *tempfile and add it to tempfile_list: */
|
/* Initialize *tempfile and add it to tempfile_list: */
|
||||||
tempfile->fd = -1;
|
tempfile->fd = -1;
|
||||||
tempfile->fp = NULL;
|
tempfile->fp = NULL;
|
||||||
tempfile->active = 0;
|
tempfile->active = 0;
|
||||||
tempfile->owner = 0;
|
tempfile->owner = 0;
|
||||||
strbuf_init(&tempfile->filename, pathlen);
|
strbuf_init(&tempfile->filename, 0);
|
||||||
tempfile->next = tempfile_list;
|
tempfile->next = tempfile_list;
|
||||||
tempfile_list = tempfile;
|
tempfile_list = tempfile;
|
||||||
tempfile->on_list = 1;
|
tempfile->on_list = 1;
|
||||||
} else if (tempfile->filename.len) {
|
} else if (tempfile->filename.len) {
|
||||||
/* This shouldn't happen, but better safe than sorry. */
|
/* This shouldn't happen, but better safe than sorry. */
|
||||||
die("BUG: create_tempfile called for improperly-reset object");
|
die("BUG: prepare_tempfile_object called for improperly-reset object");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure errno contains a meaningful value on error */
|
||||||
|
int create_tempfile(struct tempfile *tempfile, const char *path)
|
||||||
|
{
|
||||||
|
prepare_tempfile_object(tempfile);
|
||||||
|
|
||||||
strbuf_add_absolute_path(&tempfile->filename, path);
|
strbuf_add_absolute_path(&tempfile->filename, path);
|
||||||
tempfile->fd = open(tempfile->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);
|
tempfile->fd = open(tempfile->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);
|
||||||
|
|
Loading…
Reference in New Issue