static void __file_dump(const gchar *file_name, void *src_buffer, int size)
{
- int fd;
- gchar *full_path;
+ g_autofree gchar *full_path = NULL;
+ g_autoptr(GError) error = NULL;
RET_IF(!file_name, "file_name is NULL");
RET_IF(!src_buffer, "src_buffer is NULL");
full_path = g_strdup_printf("/tmp/%s", file_name);
- fd = open(full_path, O_WRONLY | O_CREAT, 0644);
- if (fd == -1) {
- g_print("failed to open file[%s]\n", full_path);
- goto end;
- }
-
- if (write(fd, src_buffer, size) == -1)
- g_print("failed to write file[%s]\n", full_path);
-
- g_print("[%s, %d bytes] is ready\n", full_path, size);
-
-end:
- g_free(full_path);
- if (fd != -1)
- close(fd);
+ if (!g_file_set_contents((const gchar *)full_path, (const gchar *)src_buffer, (gssize)size, &error))
+ g_print("__file_dump(), failed to g_file_set_contents[%s], error:%s\n", full_path, error ? error->message : "none");
+ else
+ g_print("__file_dump(), [%s, %d bytes] is ready\n", full_path, size);
}
static int __convert_string_to_gint64(gchar *str, gint64 *result)