c5d972
commit 7a7226543611897103c7483bec160547294dcf0d
c5d972
Author: Alexandra Hájková <ahajkova@redhat.com>
c5d972
Date:   Sat Dec 26 20:44:34 2020 +0100
c5d972
c5d972
     Add xfchmod to libsupport
c5d972
c5d972
diff --git a/support/Makefile b/support/Makefile
c5d972
index d2b95539403e416c..4875f52495ef292d 100644
c5d972
--- a/support/Makefile
c5d972
+++ b/support/Makefile
c5d972
@@ -91,6 +91,7 @@ libsupport-routines = \
c5d972
   xdlfcn \
c5d972
   xdlmopen \
c5d972
   xdup2 \
c5d972
+  xfchmod \
c5d972
   xfclose \
c5d972
   xfopen \
c5d972
   xfork \
c5d972
diff --git a/support/xfchmod.c b/support/xfchmod.c
c5d972
new file mode 100644
c5d972
index 0000000000000000..4323b9ca8e078c98
c5d972
--- /dev/null
c5d972
+++ b/support/xfchmod.c
c5d972
@@ -0,0 +1,28 @@
c5d972
+/* fchmod with error checking.
c5d972
+   Copyright (C) 2021 Free Software Foundation, Inc.
c5d972
+   This file is part of the GNU C Library.
c5d972
+
c5d972
+   The GNU C Library is free software; you can redistribute it and/or
c5d972
+   modify it under the terms of the GNU Lesser General Public
c5d972
+   License as published by the Free Software Foundation; either
c5d972
+   version 2.1 of the License, or (at your option) any later version.
c5d972
+
c5d972
+   The GNU C Library is distributed in the hope that it will be useful,
c5d972
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
c5d972
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c5d972
+   Lesser General Public License for more details.
c5d972
+
c5d972
+   You should have received a copy of the GNU Lesser General Public
c5d972
+   License along with the GNU C Library; if not, see
c5d972
+   <https://www.gnu.org/licenses/>.  */
c5d972
+
c5d972
+#include <support/check.h>
c5d972
+#include <support/xunistd.h>
c5d972
+#include <sys/stat.h>
c5d972
+
c5d972
+void
c5d972
+xfchmod (int fd, mode_t mode)
c5d972
+{
c5d972
+  if (fchmod (fd, mode) != 0)
c5d972
+    FAIL_EXIT1 ("fchmod (%d, 0%o): %m", fd, mode);
c5d972
+}
c5d972
diff --git a/support/xunistd.h b/support/xunistd.h
c5d972
index 74fd2771d12c36fe..ced8cb1dd9ee356c 100644
c5d972
--- a/support/xunistd.h
c5d972
+++ b/support/xunistd.h
c5d972
@@ -45,6 +45,7 @@ long long xlseek (int fd, long long offset, int whence);
c5d972
 void xftruncate (int fd, long long length);
c5d972
 void xsymlink (const char *target, const char *linkpath);
c5d972
 void xchdir (const char *path);
c5d972
+void xfchmod (int fd, mode_t mode);
c5d972
 
c5d972
 /* Equivalent of "mkdir -p".  */
c5d972
 void xmkdirp (const char *, mode_t);