c5d972
commit 7b9c3260bcca73781dda6bc2ddee84869bedfb8c
c5d972
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
c5d972
Date:   Mon Dec 14 11:42:33 2020 -0300
c5d972
c5d972
    support: Add xchmod wrapper
c5d972
    
c5d972
    Checked on x86_64-linux-gnu.
c5d972
c5d972
diff --git a/support/xchmod.c b/support/xchmod.c
c5d972
new file mode 100644
c5d972
index 0000000000000000..5e403c7cc2705aef
c5d972
--- /dev/null
c5d972
+++ b/support/xchmod.c
c5d972
@@ -0,0 +1,30 @@
c5d972
+/* chmod with error checking.
c5d972
+   Copyright (C) 2020 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/xunistd.h>
c5d972
+#include <support/check.h>
c5d972
+
c5d972
+#include <sys/stat.h>
c5d972
+
c5d972
+void
c5d972
+xchmod (const char *pathname, mode_t mode)
c5d972
+{
c5d972
+  int r = chmod (pathname, mode);
c5d972
+  if (r < 0)
c5d972
+    FAIL_EXIT1 ("chmod (%s, %d): %m", pathname, mode);
c5d972
+}
c5d972
diff --git a/support/xunistd.h b/support/xunistd.h
c5d972
index ced8cb1dd9ee356c..e92056c65efe8d6a 100644
c5d972
--- a/support/xunistd.h
c5d972
+++ b/support/xunistd.h
c5d972
@@ -46,6 +46,7 @@ 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
+void xchmod (const char *pathname, mode_t mode);
c5d972
 
c5d972
 /* Equivalent of "mkdir -p".  */
c5d972
 void xmkdirp (const char *, mode_t);