[PATCH 2/5] support: Add xgetresgid and xgetresuid
Florian Weimer
fweimer@redhat.com
Tue Dec 9 17:30:51 GMT 2025
---
support/Makefile | 2 ++
support/xgetresgid.c | 27 +++++++++++++++++++++++++++
support/xgetresuid.c | 27 +++++++++++++++++++++++++++
support/xunistd.h | 2 ++
4 files changed, 58 insertions(+)
create mode 100644 support/xgetresgid.c
create mode 100644 support/xgetresuid.c
diff --git a/support/Makefile b/support/Makefile
index 93d9735135..e6e3589158 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -145,6 +145,8 @@ libsupport-routines = \
xftruncate \
xgetline \
xgetpeername \
+ xgetresgid \
+ xgetresuid \
xgetsockname \
xlisten \
xlseek \
diff --git a/support/xgetresgid.c b/support/xgetresgid.c
new file mode 100644
index 0000000000..54df2a04f9
--- /dev/null
+++ b/support/xgetresgid.c
@@ -0,0 +1,27 @@
+/* getresgid 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>
+
+void
+xgetresgid (gid_t *real, gid_t *effective, gid_t *saved)
+{
+ if (getresgid (real, effective, saved) != 0)
+ FAIL_EXIT1 ("getresgid: %m");
+}
diff --git a/support/xgetresuid.c b/support/xgetresuid.c
new file mode 100644
index 0000000000..e22fe0923a
--- /dev/null
+++ b/support/xgetresuid.c
@@ -0,0 +1,27 @@
+/* getresuid 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>
+
+void
+xgetresuid (uid_t *real, uid_t *effective, uid_t *saved)
+{
+ if (getresuid (real, effective, saved) != 0)
+ FAIL_EXIT1 ("getresuid: %m");
+}
diff --git a/support/xunistd.h b/support/xunistd.h
index 8f6dd4fd1d..1a5aa58125 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -65,6 +65,8 @@ void xchdir (const char *path);
void xfchmod (int fd, mode_t mode);
void xchmod (const char *pathname, mode_t mode);
void xmkfifo (const char *pathname, mode_t mode);
+void xgetresuid (uid_t *, uid_t *, uid_t *);
+void xgetresgid (gid_t *, gid_t *, gid_t *);
/* Equivalent of "mkdir -p". */
void xmkdirp (const char *, mode_t);
--
2.52.0
More information about the Libc-alpha
mailing list