syscalls/chown01: Fix test file creation

There is a bug in the code to create the file and the code is
very intricate. So replace it with SAFE_FILE_PRINTF().

Signed-off-by: jungsoo.son <jungsoo.son@lge.com>
Reviewed-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
diff --git a/testcases/kernel/syscalls/chown/chown01.c b/testcases/kernel/syscalls/chown/chown01.c
index 50b9ea5..d95564e 100644
--- a/testcases/kernel/syscalls/chown/chown01.c
+++ b/testcases/kernel/syscalls/chown/chown01.c
@@ -116,9 +116,7 @@
 #include <signal.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "chown01";
 int TST_TOTAL = 1;
@@ -126,8 +124,10 @@
 int exp_enos[] = { 0, 0 };
 
 char fname[255];
-int fd, uid, gid;
-char *buf = "davef";
+int uid, gid;
+
+static void setup(void);
+static void cleanup(void);
 
 int main(int ac, char **av)
 {
@@ -163,7 +163,7 @@
 
 }
 
-void setup()
+static void setup(void)
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -176,17 +176,11 @@
 	gid = getegid();
 
 	sprintf(fname, "t_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	else if (write(fd, &buf, strlen(buf)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "write(%s, &buf, strlen(buf)) failed", fname);
-	else if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", fname);
+
+	SAFE_FILE_PRINTF(cleanup, fname, "davef");
 }
 
-void cleanup()
+static void cleanup(void)
 {
 	TEST_CLEANUP;