From: Theodore Ts'o Date: Sat, 3 May 2003 20:39:50 +0000 (-0400) Subject: tst_badblocks.c (file_test): Use tmpfile() instead of mktemp(). X-Git-Tag: E2FSPROGS-1_34-WIP-0521~30 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=68dbdc2f1d717faa73c61e5f2ed5c3c9d6128dd6;p=tools%2Fe2fsprogs.git tst_badblocks.c (file_test): Use tmpfile() instead of mktemp(). --- diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 6f1e0e4..fdc10c8 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,7 @@ +2003-05-03 Theodore Ts'o + + * tst_badblocks.c (file_test): Use tmpfile() instead of mktemp(). + 2003-04-29 Theodore Ts'o * getsize.c (ext2fs_get_device_size): Allow windows code to get diff --git a/lib/ext2fs/tst_badblocks.c b/lib/ext2fs/tst_badblocks.c index cad6efd..2ae3585 100644 --- a/lib/ext2fs/tst_badblocks.c +++ b/lib/ext2fs/tst_badblocks.c @@ -120,18 +120,14 @@ static void validate_test_seq(badblocks_list bb, blk_t *vec) int file_test(badblocks_list bb) { - char tmp_filename[20] = "#testXXXXXX"; badblocks_list new_bb = 0; errcode_t retval; FILE *f; - mktemp(tmp_filename); - - unlink(tmp_filename); - f = fopen(tmp_filename, "w"); + f = tmpfile(); if (!f) { - fprintf(stderr, "Error opening temp file %s: %s\n", - tmp_filename, error_message(errno)); + fprintf(stderr, "Error opening temp file: %s\n", + error_message(errno)); return 1; } retval = ext2fs_write_bb_FILE(bb, 0, f); @@ -139,14 +135,8 @@ int file_test(badblocks_list bb) com_err("file_test", retval, "while writing bad blocks"); return 1; } - fclose(f); - f = fopen(tmp_filename, "r"); - if (!f) { - fprintf(stderr, "Error re-opening temp file %s: %s\n", - tmp_filename, error_message(errno)); - return 1; - } + rewind(f); retval = ext2fs_read_bb_FILE2(0, f, &new_bb, 0, 0); if (retval) { com_err("file_test", retval, "while reading bad blocks");