]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
test_json: Remove duplicated static function.
authorNaveen Albert <asterisk@phreaknet.org>
Thu, 10 Nov 2022 12:20:43 +0000 (12:20 +0000)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Mon, 21 Nov 2022 13:43:38 +0000 (07:43 -0600)
Removes the function mkstemp_file and uses
ast_file_mkftemp from file.h instead.

ASTERISK-30295 #close

Change-Id: I7412ec06f88c39ee353bcdb8c976c2fcac546609

tests/test_json.c

index a14ac3a217c3e055599fb3cda0dbddf19d08df13..e1fc0ba29f0da7e0376a636d35710eae7b66ac92 100644 (file)
@@ -41,6 +41,7 @@
 #include "asterisk/json.h"
 #include "asterisk/module.h"
 #include "asterisk/test.h"
+#include "asterisk/file.h"
 
 #include <stdio.h>
 #include <unistd.h>
@@ -1269,27 +1270,6 @@ static int safe_fclose(FILE *f)
        return 0;
 }
 
-static FILE *mkstemp_file(char *template, const char *mode)
-{
-       int fd = mkstemp(template);
-       FILE *file;
-
-       if (fd < 0) {
-               ast_log(LOG_ERROR, "Failed to create temp file: %s\n",
-                       strerror(errno));
-               return NULL;
-       }
-
-       file = fdopen(fd, mode);
-       if (!file) {
-               ast_log(LOG_ERROR, "Failed to create temp file: %s\n",
-                       strerror(errno));
-               return NULL;
-       }
-
-       return file;
-}
-
 AST_TEST_DEFINE(json_test_dump_load_file)
 {
        RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
@@ -1312,7 +1292,7 @@ AST_TEST_DEFINE(json_test_dump_load_file)
 
        /* dump/load file */
        expected = ast_json_pack("{ s: i }", "one", 1);
-       file = mkstemp_file(filename, "w");
+       file = ast_file_mkftemp(filename, 0644);
        ast_test_validate(test, NULL != file);
        uut_res = ast_json_dump_file(expected, file);
        ast_test_validate(test, 0 == uut_res);
@@ -1347,7 +1327,7 @@ AST_TEST_DEFINE(json_test_dump_load_new_file)
 
        /* dump/load filename */
        expected = ast_json_pack("{ s: i }", "one", 1);
-       file = mkstemp_file(filename, "w");
+       file = ast_file_mkftemp(filename, 0644);
        ast_test_validate(test, NULL != file);
        uut_res = ast_json_dump_new_file(expected, filename);
        ast_test_validate(test, 0 == uut_res);
@@ -1378,7 +1358,7 @@ AST_TEST_DEFINE(json_test_dump_load_null)
        /* dump/load NULL tests */
        uut = ast_json_load_string("{ \"one\": 1 }", NULL);
        ast_test_validate(test, NULL != uut);
-       file = mkstemp_file(filename, "w");
+       file = ast_file_mkftemp(filename, 0644);
        ast_test_validate(test, NULL != file);
        ast_test_validate(test, NULL == ast_json_dump_string(NULL));
        ast_test_validate(test, -1 == ast_json_dump_file(NULL, file));