[PATCH 1/5] support: Add xfchdir
Florian Weimer
fweimer@redhat.com
Tue Dec 9 17:30:37 GMT 2025
---
support/Makefile | 1 +
support/xfchdir.c | 28 ++++++++++++++++++++++++++++
support/xunistd.h | 2 ++
3 files changed, 31 insertions(+)
create mode 100644 support/xfchdir.c
diff --git a/support/Makefile b/support/Makefile
index a7b1b39782..93d9735135 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -132,6 +132,7 @@ libsupport-routines = \
xdlmopen \
xdup \
xdup2 \
+ xfchdir \
xfchmod \
xfclose \
xfdopendir \
diff --git a/support/xfchdir.c b/support/xfchdir.c
new file mode 100644
index 0000000000..577233d6c8
--- /dev/null
+++ b/support/xfchdir.c
@@ -0,0 +1,28 @@
+/* fchdir with error checking.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+void
+xfchdir (int fd)
+{
+ if (fchdir (fd) != 0)
+ FAIL_EXIT1 ("fchdir (%d): %m", fd);
+}
diff --git a/support/xunistd.h b/support/xunistd.h
index 55afa4362b..8f6dd4fd1d 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -53,6 +53,8 @@ void support_check_stat_path (const char *name, const char *path, int result);
(support_check_stat_path ("lstat64", (path), lstat64 ((path), (st))))
void xstatx (int, const char *, int, unsigned int, struct statx *);
void xmkdir (const char *path, mode_t);
+void xchdir (const char *path);
+void xfchdir (int);
void xchroot (const char *path);
void xunlink (const char *path);
long xsysconf (int name);
--
2.52.0
More information about the Libc-alpha
mailing list