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>
Luiz Fernando N. Capitulino committed
Aug 14, 2007 at 16:45 UTC
7647b17f1d7a98362f8bdbe48b30d94ed655229c
6 files changed
+7
-17
builtin-pack-objects.c
+1
-3
@@ -586,7 +586,7 @@ static off_t write_one(struct sha1file *f,
586
static int open_object_dir_tmp(const char *path)
587
{
588
snprintf(tmpname, sizeof(tmpname), "%s/%s", get_object_directory(), path);
589
- return mkstemp(tmpname);
589
+ return xmkstemp(tmpname);
590
}
591
592
/* forward declaration for write_pack_file */
@@ -612,8 +612,6 @@ static void write_pack_file(void)
612
f = sha1fd(1, "<stdout>");
613
} else {
614
int fd = open_object_dir_tmp("tmp_pack_XXXXXX");
615
- if (fd < 0)
616
- die("unable to create %s: %s\n", tmpname, strerror(errno));
615
pack_tmp_name = xstrdup(tmpname);
616
f = sha1fd(fd, pack_tmp_name);
617
}
fast-import.c
+2
-6
@@ -663,9 +663,7 @@ static void start_packfile(void)
663
664
snprintf(tmpfile, sizeof(tmpfile),
665
"%s/tmp_pack_XXXXXX", get_object_directory());
666
- pack_fd = mkstemp(tmpfile);
667
- if (pack_fd < 0)
668
- die("Can't create %s: %s", tmpfile, strerror(errno));
666
+ pack_fd = xmkstemp(tmpfile);
667
p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
668
strcpy(p->pack_name, tmpfile);
669
p->pack_fd = pack_fd;
@@ -727,9 +725,7 @@ static char *create_index(void)
725
726
snprintf(tmpfile, sizeof(tmpfile),
727
"%s/tmp_idx_XXXXXX", get_object_directory());
730
- idx_fd = mkstemp(tmpfile);
731
- if (idx_fd < 0)
732
- die("Can't create %s: %s", tmpfile, strerror(errno));
728
+ idx_fd = xmkstemp(tmpfile);
729
f = sha1fd(idx_fd, tmpfile);
730
sha1write(f, array, 256 * sizeof(int));
731
SHA1_Init(&ctx);
index-pack.c
+1
-1
@@ -114,7 +114,7 @@ static const char *open_pack_file(const char *pack_name)
114
static char tmpfile[PATH_MAX];
115
snprintf(tmpfile, sizeof(tmpfile),
116
"%s/tmp_pack_XXXXXX", get_object_directory());
117
- output_fd = mkstemp(tmpfile);
117
+ output_fd = xmkstemp(tmpfile);
118
pack_name = xstrdup(tmpfile);
119
} else
120
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
merge-recursive.c
+1
-3
@@ -782,9 +782,7 @@ static void create_temp(mmfile_t *src, char *path)
782
int fd;
783
784
strcpy(path, ".merge_file_XXXXXX");
785
- fd = mkstemp(path);
786
- if (fd < 0)
787
- die("unable to create temp-file");
785
+ fd = xmkstemp(path);
786
if (write_in_full(fd, src->ptr, src->size) != src->size)
787
die("unable to write temp-file");
788
close(fd);
pack-write.c
+1
-1
@@ -45,7 +45,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
45
static char tmpfile[PATH_MAX];
46
snprintf(tmpfile, sizeof(tmpfile),
47
"%s/tmp_idx_XXXXXX", get_object_directory());
48
- fd = mkstemp(tmpfile);
48
+ fd = xmkstemp(tmpfile);
49
index_name = xstrdup(tmpfile);
50
} else {
51
unlink(index_name);
unpack-file.c
+1
-3
@@ -14,9 +14,7 @@ static char *create_temp_file(unsigned char *sha1)
14
die("unable to read blob object %s", sha1_to_hex(sha1));
15
16
strcpy(path, ".merge_file_XXXXXX");
17
- fd = mkstemp(path);
18
- if (fd < 0)
19
- die("unable to create temp-file");
17
+ fd = xmkstemp(path);
18
if (write_in_full(fd, buf, size) != size)
19
die("unable to write temp-file");
20
close(fd);