Use xmkstemp() instead of mkstemp()
xmkstemp() performs error checking and prints a standard error message when an error occur. Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f21a47b27c
commit
7647b17f1d
@ -586,7 +586,7 @@ static off_t write_one(struct sha1file *f,
|
|||||||
static int open_object_dir_tmp(const char *path)
|
static int open_object_dir_tmp(const char *path)
|
||||||
{
|
{
|
||||||
snprintf(tmpname, sizeof(tmpname), "%s/%s", get_object_directory(), path);
|
snprintf(tmpname, sizeof(tmpname), "%s/%s", get_object_directory(), path);
|
||||||
return mkstemp(tmpname);
|
return xmkstemp(tmpname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* forward declaration for write_pack_file */
|
/* forward declaration for write_pack_file */
|
||||||
@ -612,8 +612,6 @@ static void write_pack_file(void)
|
|||||||
f = sha1fd(1, "<stdout>");
|
f = sha1fd(1, "<stdout>");
|
||||||
} else {
|
} else {
|
||||||
int fd = open_object_dir_tmp("tmp_pack_XXXXXX");
|
int fd = open_object_dir_tmp("tmp_pack_XXXXXX");
|
||||||
if (fd < 0)
|
|
||||||
die("unable to create %s: %s\n", tmpname, strerror(errno));
|
|
||||||
pack_tmp_name = xstrdup(tmpname);
|
pack_tmp_name = xstrdup(tmpname);
|
||||||
f = sha1fd(fd, pack_tmp_name);
|
f = sha1fd(fd, pack_tmp_name);
|
||||||
}
|
}
|
||||||
|
@ -663,9 +663,7 @@ static void start_packfile(void)
|
|||||||
|
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
snprintf(tmpfile, sizeof(tmpfile),
|
||||||
"%s/tmp_pack_XXXXXX", get_object_directory());
|
"%s/tmp_pack_XXXXXX", get_object_directory());
|
||||||
pack_fd = mkstemp(tmpfile);
|
pack_fd = xmkstemp(tmpfile);
|
||||||
if (pack_fd < 0)
|
|
||||||
die("Can't create %s: %s", tmpfile, strerror(errno));
|
|
||||||
p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
|
p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
|
||||||
strcpy(p->pack_name, tmpfile);
|
strcpy(p->pack_name, tmpfile);
|
||||||
p->pack_fd = pack_fd;
|
p->pack_fd = pack_fd;
|
||||||
@ -727,9 +725,7 @@ static char *create_index(void)
|
|||||||
|
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
snprintf(tmpfile, sizeof(tmpfile),
|
||||||
"%s/tmp_idx_XXXXXX", get_object_directory());
|
"%s/tmp_idx_XXXXXX", get_object_directory());
|
||||||
idx_fd = mkstemp(tmpfile);
|
idx_fd = xmkstemp(tmpfile);
|
||||||
if (idx_fd < 0)
|
|
||||||
die("Can't create %s: %s", tmpfile, strerror(errno));
|
|
||||||
f = sha1fd(idx_fd, tmpfile);
|
f = sha1fd(idx_fd, tmpfile);
|
||||||
sha1write(f, array, 256 * sizeof(int));
|
sha1write(f, array, 256 * sizeof(int));
|
||||||
SHA1_Init(&ctx);
|
SHA1_Init(&ctx);
|
||||||
|
@ -114,7 +114,7 @@ static const char *open_pack_file(const char *pack_name)
|
|||||||
static char tmpfile[PATH_MAX];
|
static char tmpfile[PATH_MAX];
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
snprintf(tmpfile, sizeof(tmpfile),
|
||||||
"%s/tmp_pack_XXXXXX", get_object_directory());
|
"%s/tmp_pack_XXXXXX", get_object_directory());
|
||||||
output_fd = mkstemp(tmpfile);
|
output_fd = xmkstemp(tmpfile);
|
||||||
pack_name = xstrdup(tmpfile);
|
pack_name = xstrdup(tmpfile);
|
||||||
} else
|
} else
|
||||||
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
|
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
|
||||||
|
@ -782,9 +782,7 @@ static void create_temp(mmfile_t *src, char *path)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
strcpy(path, ".merge_file_XXXXXX");
|
strcpy(path, ".merge_file_XXXXXX");
|
||||||
fd = mkstemp(path);
|
fd = xmkstemp(path);
|
||||||
if (fd < 0)
|
|
||||||
die("unable to create temp-file");
|
|
||||||
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
||||||
die("unable to write temp-file");
|
die("unable to write temp-file");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -45,7 +45,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
|
|||||||
static char tmpfile[PATH_MAX];
|
static char tmpfile[PATH_MAX];
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
snprintf(tmpfile, sizeof(tmpfile),
|
||||||
"%s/tmp_idx_XXXXXX", get_object_directory());
|
"%s/tmp_idx_XXXXXX", get_object_directory());
|
||||||
fd = mkstemp(tmpfile);
|
fd = xmkstemp(tmpfile);
|
||||||
index_name = xstrdup(tmpfile);
|
index_name = xstrdup(tmpfile);
|
||||||
} else {
|
} else {
|
||||||
unlink(index_name);
|
unlink(index_name);
|
||||||
|
@ -14,9 +14,7 @@ static char *create_temp_file(unsigned char *sha1)
|
|||||||
die("unable to read blob object %s", sha1_to_hex(sha1));
|
die("unable to read blob object %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
strcpy(path, ".merge_file_XXXXXX");
|
strcpy(path, ".merge_file_XXXXXX");
|
||||||
fd = mkstemp(path);
|
fd = xmkstemp(path);
|
||||||
if (fd < 0)
|
|
||||||
die("unable to create temp-file");
|
|
||||||
if (write_in_full(fd, buf, size) != size)
|
if (write_in_full(fd, buf, size) != size)
|
||||||
die("unable to write temp-file");
|
die("unable to write temp-file");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Reference in New Issue
Block a user