]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add xfchmod to libsupport
authorAlexandra Hájková <ahajkova@redhat.com>
Sat, 26 Dec 2020 19:44:34 +0000 (20:44 +0100)
committerAlexandra Hájková <ahajkova@redhat.com>
Sun, 10 Jan 2021 17:55:47 +0000 (18:55 +0100)
support/Makefile
support/xfchmod.c [new file with mode: 0644]
support/xunistd.h

index f4d157dded0e246f029b23a28e9b5c1386d0a71e..62d6c6ddaa8d757f671e32b14e08b4be47426d61 100644 (file)
@@ -96,6 +96,7 @@ libsupport-routines = \
   xdlfcn \
   xdlmopen \
   xdup2 \
+  xfchmod \
   xfclose \
   xfopen \
   xfork \
diff --git a/support/xfchmod.c b/support/xfchmod.c
new file mode 100644 (file)
index 0000000..4323b9c
--- /dev/null
@@ -0,0 +1,28 @@
+/* fchmod with error checking.
+   Copyright (C) 2021 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+void
+xfchmod (int fd, mode_t mode)
+{
+  if (fchmod (fd, mode) != 0)
+    FAIL_EXIT1 ("fchmod (%d, 0%o): %m", fd, mode);
+}
index 12a5ab677c2bf923e7ccee2325ad0ca005b42476..eb1b5519ff273ab45b15bd48a64883998e5af226 100644 (file)
@@ -46,6 +46,7 @@ long long xlseek (int fd, long long offset, int whence);
 void xftruncate (int fd, long long length);
 void xsymlink (const char *target, const char *linkpath);
 void xchdir (const char *path);
+void xfchmod (int fd, mode_t mode);
 
 /* Equivalent of "mkdir -p".  */
 void xmkdirp (const char *, mode_t);