[Asterisk-code-review] test_json: Remove duplicated static function. (asterisk[master])

N A asteriskteam at digium.com
Thu Nov 10 06:22:04 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19478 )


Change subject: test_json: Remove duplicated static function.
......................................................................

test_json: Remove duplicated static function.

Removes the function mkstemp_file and uses
ast_file_mkftemp from file.h instead.

ASTERISK-30295 #close

Change-Id: I7412ec06f88c39ee353bcdb8c976c2fcac546609
---
M tests/test_json.c
1 file changed, 18 insertions(+), 24 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/78/19478/1

diff --git a/tests/test_json.c b/tests/test_json.c
index a14ac3a..e1fc0ba 100644
--- a/tests/test_json.c
+++ b/tests/test_json.c
@@ -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 @@
 	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 @@
 
 	/* 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 @@
 
 	/* 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 @@
 	/* 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));

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19478
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I7412ec06f88c39ee353bcdb8c976c2fcac546609
Gerrit-Change-Number: 19478
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221110/05acf794/attachment.html>


More information about the asterisk-code-review mailing list