tests: Use g_clear_fd()

This commit is contained in:
Benjamin Otte 2023-04-17 14:20:52 +02:00 committed by Philip Withnall
parent e8254f14fd
commit 77c35415a3

View File

@ -6,6 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <gio/gfiledescriptorbased.h> #include <gio/gfiledescriptorbased.h>
#include <glib/gstdio.h>
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
@ -2855,7 +2856,8 @@ test_load_bytes (void)
len = strlen ("test_load_bytes"); len = strlen ("test_load_bytes");
ret = write (fd, "test_load_bytes", len); ret = write (fd, "test_load_bytes", len);
g_assert_cmpint (ret, ==, len); g_assert_cmpint (ret, ==, len);
close (fd); g_clear_fd (&fd, &error);
g_assert_no_error (error);
file = g_file_new_for_path (filename); file = g_file_new_for_path (filename);
bytes = g_file_load_bytes (file, NULL, NULL, &error); bytes = g_file_load_bytes (file, NULL, NULL, &error);
@ -2898,6 +2900,7 @@ test_load_bytes_async (void)
{ {
LoadBytesAsyncData data = { 0 }; LoadBytesAsyncData data = { 0 };
gchar filename[] = "g_file_load_bytes_XXXXXX"; gchar filename[] = "g_file_load_bytes_XXXXXX";
GError *error = NULL;
int len; int len;
int fd; int fd;
int ret; int ret;
@ -2907,7 +2910,8 @@ test_load_bytes_async (void)
len = strlen ("test_load_bytes_async"); len = strlen ("test_load_bytes_async");
ret = write (fd, "test_load_bytes_async", len); ret = write (fd, "test_load_bytes_async", len);
g_assert_cmpint (ret, ==, len); g_assert_cmpint (ret, ==, len);
close (fd); g_clear_fd (&fd, &error);
g_assert_no_error (error);
data.main_loop = g_main_loop_new (NULL, FALSE); data.main_loop = g_main_loop_new (NULL, FALSE);
data.file = g_file_new_for_path (filename); data.file = g_file_new_for_path (filename);