{"thread":{"id":"9526","subject":"[PATCH 2/2] Use xmkstemp() instead of mkstemp()","startedAt":"2007-08-14T19:45:58Z","lastAt":"2007-08-14T19:45:58Z","messageCount":1,"participants":["Luiz Fernando N. Capitulino"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"50723","messageId":"20070814164558.1a627475@localhost","threadId":"9526","inReplyTo":null,"subject":"[PATCH 2/2] Use xmkstemp() instead of mkstemp()","fromName":"Luiz Fernando N. Capitulino","fromEmail":"lcapitulino@mandriva.com.br","sentAt":"2007-08-14T19:45:58Z","receivedAt":"2007-08-14T19:45:58Z","isPatch":true,"sender":{"key":"lcapitulino@mandriva.com.br","avatar":null},"body":"\nxmkstemp() performs error checking and prints a standard error message when\nan error occur.\n\nSigned-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>\n---\n builtin-pack-objects.c |    4 +---\n fast-import.c          |    8 ++------\n index-pack.c           |    2 +-\n merge-recursive.c      |    4 +---\n pack-write.c           |    2 +-\n unpack-file.c          |    4 +---\n 6 files changed, 7 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 5e9d1fd..51a850e 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -586,7 +586,7 @@ static off_t write_one(struct sha1file *f,\n static int open_object_dir_tmp(const char *path)\n {\n     snprintf(tmpname, sizeof(tmpname), \"%s/%s\", get_object_directory(), path);\n-    return mkstemp(tmpname);\n+    return xmkstemp(tmpname);\n }\n \n /* forward declaration for write_pack_file */\n@@ -612,8 +612,6 @@ static void write_pack_file(void)\n \t\t\tf = sha1fd(1, \"<stdout>\");\n \t\t} else {\n \t\t\tint fd = open_object_dir_tmp(\"tmp_pack_XXXXXX\");\n-\t\t\tif (fd < 0)\n-\t\t\t\tdie(\"unable to create %s: %s\\n\", tmpname, strerror(errno));\n \t\t\tpack_tmp_name = xstrdup(tmpname);\n \t\t\tf = sha1fd(fd, pack_tmp_name);\n \t\t}\ndiff --git a/fast-import.c b/fast-import.c\nindex 99a19d8..170cccd 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -663,9 +663,7 @@ static void start_packfile(void)\n \n \tsnprintf(tmpfile, sizeof(tmpfile),\n \t\t\"%s/tmp_pack_XXXXXX\", get_object_directory());\n-\tpack_fd = mkstemp(tmpfile);\n-\tif (pack_fd < 0)\n-\t\tdie(\"Can't create %s: %s\", tmpfile, strerror(errno));\n+\tpack_fd = xmkstemp(tmpfile);\n \tp = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);\n \tstrcpy(p->pack_name, tmpfile);\n \tp->pack_fd = pack_fd;\n@@ -727,9 +725,7 @@ static char *create_index(void)\n \n \tsnprintf(tmpfile, sizeof(tmpfile),\n \t\t\"%s/tmp_idx_XXXXXX\", get_object_directory());\n-\tidx_fd = mkstemp(tmpfile);\n-\tif (idx_fd < 0)\n-\t\tdie(\"Can't create %s: %s\", tmpfile, strerror(errno));\n+\tidx_fd = xmkstemp(tmpfile);\n \tf = sha1fd(idx_fd, tmpfile);\n \tsha1write(f, array, 256 * sizeof(int));\n \tSHA1_Init(&ctx);\ndiff --git a/index-pack.c b/index-pack.c\nindex 8403c36..db58e05 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -114,7 +114,7 @@ static const char *open_pack_file(const char *pack_name)\n \t\t\tstatic char tmpfile[PATH_MAX];\n \t\t\tsnprintf(tmpfile, sizeof(tmpfile),\n \t\t\t\t \"%s/tmp_pack_XXXXXX\", get_object_directory());\n-\t\t\toutput_fd = mkstemp(tmpfile);\n+\t\t\toutput_fd = xmkstemp(tmpfile);\n \t\t\tpack_name = xstrdup(tmpfile);\n \t\t} else\n \t\t\toutput_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex f7d1b84..ca77cdb 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -777,9 +777,7 @@ static void create_temp(mmfile_t *src, char *path)\n \tint fd;\n \n \tstrcpy(path, \".merge_file_XXXXXX\");\n-\tfd = mkstemp(path);\n-\tif (fd < 0)\n-\t\tdie(\"unable to create temp-file\");\n+\tfd = xmkstemp(path);\n \tif (write_in_full(fd, src->ptr, src->size) != src->size)\n \t\tdie(\"unable to write temp-file\");\n \tclose(fd);\ndiff --git a/pack-write.c b/pack-write.c\nindex 1cf5f7c..e59b197 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -45,7 +45,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tstatic char tmpfile[PATH_MAX];\n \t\tsnprintf(tmpfile, sizeof(tmpfile),\n \t\t\t \"%s/tmp_idx_XXXXXX\", get_object_directory());\n-\t\tfd = mkstemp(tmpfile);\n+\t\tfd = xmkstemp(tmpfile);\n \t\tindex_name = xstrdup(tmpfile);\n \t} else {\n \t\tunlink(index_name);\ndiff --git a/unpack-file.c b/unpack-file.c\nindex 25c56b3..65c66eb 100644\n--- a/unpack-file.c\n+++ b/unpack-file.c\n@@ -14,9 +14,7 @@ static char *create_temp_file(unsigned char *sha1)\n \t\tdie(\"unable to read blob object %s\", sha1_to_hex(sha1));\n \n \tstrcpy(path, \".merge_file_XXXXXX\");\n-\tfd = mkstemp(path);\n-\tif (fd < 0)\n-\t\tdie(\"unable to create temp-file\");\n+\tfd = xmkstemp(path);\n \tif (write_in_full(fd, buf, size) != size)\n \t\tdie(\"unable to write temp-file\");\n \tclose(fd);\n-- \n1.5.3.GIT\n\n\n\n-- \nLuiz Fernando N. Capitulino\n"}]}