diff --git a/README.md b/README.md index 8fb2faa42ffb8ee804ca572ae4cf962c5ca51876..f2ae6ae31b46d672427dbc62275ee5e242385510 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ applicable. For local allocation macros, you should start using the `g_auto` macros from GLib. A backport is included in libglnx. There are a few -APIs not defined in GLib yet, such as `glnx_fd_close`. +APIs not defined in GLib yet, such as `glnx_autofd`. `gs_transfer_out_value` is replaced by `g_steal_pointer`. diff --git a/glnx-dirfd.c b/glnx-dirfd.c index e6c3319c1b876edbabd88e808aea5468bb158d9c..e0c244cfc4c0338454e54c7e4a49fab185d68268 100644 --- a/glnx-dirfd.c +++ b/glnx-dirfd.c @@ -99,7 +99,7 @@ glnx_dirfd_iterator_init_at (int dfd, GLnxDirFdIterator *out_dfd_iter, GError **error) { - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; if (!glnx_opendirat (dfd, path, follow, &fd, error)) return FALSE; @@ -326,7 +326,7 @@ glnx_mkdtempat (int dfd, const char *tmpl, int mode, } /* And open it */ - glnx_fd_close int ret_dfd = -1; + glnx_autofd int ret_dfd = -1; if (!glnx_opendirat (dfd, path, FALSE, &ret_dfd, error)) { /* If we fail to open, let's try to clean up */ diff --git a/glnx-fdio.c b/glnx-fdio.c index 892be2a7d84856994490c8ada334c99c095a53b9..b24d03f2fed1a87d6369eb5563363cc5ac157fe9 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -175,11 +175,7 @@ glnx_tmpfile_clear (GLnxTmpfile *tmpf) return; if (!tmpf->initialized) return; - if (tmpf->fd != -1) - { - if (close (tmpf->fd) < 0) - g_assert (errno != EBADF); - } + glnx_close_fd (&tmpf->fd); /* If ->path is set, we're likely aborting due to an error. Clean it up */ if (tmpf->path) { @@ -196,7 +192,7 @@ open_tmpfile_core (int dfd, const char *subpath, GError **error) { const guint mode = 0600; - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; int count; dfd = glnx_dirfd_canonicalize (dfd); @@ -576,7 +572,7 @@ glnx_file_get_contents_utf8_at (int dfd, { dfd = glnx_dirfd_canonicalize (dfd); - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dfd, subpath, TRUE, &fd, error)) return NULL; @@ -933,7 +929,7 @@ glnx_file_copy_at (int src_dfd, /* Regular file path below here */ - glnx_fd_close int src_fd = -1; + glnx_autofd int src_fd = -1; if (!glnx_openat_rdonly (src_dfd, src_subpath, FALSE, &src_fd, error)) return FALSE; diff --git a/glnx-lockfile.c b/glnx-lockfile.c index 2956edafe0557e0cd877150c57b30ab484695f62..f1d52dee30ff2ebb2e0fb50d0036a446329c2cc1 100644 --- a/glnx-lockfile.c +++ b/glnx-lockfile.c @@ -61,7 +61,7 @@ */ gboolean glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_lock, GError **error) { - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; g_autofree char *t = NULL; int r; diff --git a/glnx-shutil.c b/glnx-shutil.c index 8438b5da5fec1937d38b2004f29e2493da99f5bc..8014c0cd29e9ed21035b1ae214bb7c37ff2bb11c 100644 --- a/glnx-shutil.c +++ b/glnx-shutil.c @@ -84,7 +84,7 @@ glnx_shutil_rm_rf_at (int dfd, GCancellable *cancellable, GError **error) { - glnx_fd_close int target_dfd = -1; + glnx_autofd int target_dfd = -1; g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; dfd = glnx_dirfd_canonicalize (dfd); diff --git a/tests/test-libglnx-fdio.c b/tests/test-libglnx-fdio.c index c5ff9492545974ed48b3939916caf6a7c2d6cce5..81636e59cb74ee91056eb15a3c41c99ff54c624b 100644 --- a/tests/test-libglnx-fdio.c +++ b/tests/test-libglnx-fdio.c @@ -32,8 +32,8 @@ static gboolean renameat_test_setup (int *out_srcfd, int *out_destfd, GError **error) { - glnx_fd_close int srcfd = -1; - glnx_fd_close int destfd = -1; + glnx_autofd int srcfd = -1; + glnx_autofd int destfd = -1; (void) glnx_shutil_rm_rf_at (AT_FDCWD, "srcdir", NULL, NULL); if (mkdir ("srcdir", 0755) < 0) @@ -62,8 +62,8 @@ static void test_renameat2_noreplace (void) { _GLNX_TEST_DECLARE_ERROR(local_error, error); - glnx_fd_close int srcfd = -1; - glnx_fd_close int destfd = -1; + glnx_autofd int srcfd = -1; + glnx_autofd int destfd = -1; struct stat stbuf; if (!renameat_test_setup (&srcfd, &destfd, error)) @@ -92,8 +92,8 @@ test_renameat2_exchange (void) { _GLNX_TEST_DECLARE_ERROR(local_error, error); - glnx_fd_close int srcfd = -1; - glnx_fd_close int destfd = -1; + glnx_autofd int srcfd = -1; + glnx_autofd int destfd = -1; if (!renameat_test_setup (&srcfd, &destfd, error)) return; diff --git a/tests/test-libglnx-shutil.c b/tests/test-libglnx-shutil.c index 39f261b8977b69f2e289221ebdb6d0e7d243c1ad..6917b89096879b296f8ea70c293cc202b2190048 100644 --- a/tests/test-libglnx-shutil.c +++ b/tests/test-libglnx-shutil.c @@ -32,7 +32,7 @@ static void test_mkdir_p_enoent (void) { _GLNX_TEST_DECLARE_ERROR(local_error, error); - glnx_fd_close int dfd = -1; + glnx_autofd int dfd = -1; if (!glnx_ensure_dir (AT_FDCWD, "test", 0755, error)) return; diff --git a/tests/test-libglnx-xattrs.c b/tests/test-libglnx-xattrs.c index 0076b71263fff494d0b83538f75973a8e56c5a62..63e12314a332ddd94e7b5b3c17fbec7c761e1350 100644 --- a/tests/test-libglnx-xattrs.c +++ b/tests/test-libglnx-xattrs.c @@ -82,7 +82,7 @@ do_write_run (GLnxDirFdIterator *dfd_iter, GError **error) { guint32 randname_v = g_random_int (); g_autofree char *randname = g_strdup_printf ("file%u", randname_v); - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; again: fd = openat (dfd_iter->fd, randname, O_CREAT | O_EXCL, 0644); @@ -113,7 +113,7 @@ do_write_run (GLnxDirFdIterator *dfd_iter, GError **error) if (!dent) break; - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error)) return FALSE; @@ -157,7 +157,7 @@ do_read_run (GLnxDirFdIterator *dfd_iter, if (!dent) break; - glnx_fd_close int fd = -1; + glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error)) return FALSE;