00c0d4
commit 7b9c3260bcca73781dda6bc2ddee84869bedfb8c
00c0d4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
00c0d4
Date:   Mon Dec 14 11:42:33 2020 -0300
00c0d4
00c0d4
    support: Add xchmod wrapper
00c0d4
    
00c0d4
    Checked on x86_64-linux-gnu.
00c0d4
00c0d4
diff --git a/support/xchmod.c b/support/xchmod.c
00c0d4
new file mode 100644
00c0d4
index 0000000000000000..5e403c7cc2705aef
00c0d4
--- /dev/null
00c0d4
+++ b/support/xchmod.c
00c0d4
@@ -0,0 +1,30 @@
00c0d4
+/* chmod with error checking.
00c0d4
+   Copyright (C) 2020 Free Software Foundation, Inc.
00c0d4
+   This file is part of the GNU C Library.
00c0d4
+
00c0d4
+   The GNU C Library is free software; you can redistribute it and/or
00c0d4
+   modify it under the terms of the GNU Lesser General Public
00c0d4
+   License as published by the Free Software Foundation; either
00c0d4
+   version 2.1 of the License, or (at your option) any later version.
00c0d4
+
00c0d4
+   The GNU C Library is distributed in the hope that it will be useful,
00c0d4
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00c0d4
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00c0d4
+   Lesser General Public License for more details.
00c0d4
+
00c0d4
+   You should have received a copy of the GNU Lesser General Public
00c0d4
+   License along with the GNU C Library; if not, see
00c0d4
+   <https://www.gnu.org/licenses/>.  */
00c0d4
+
00c0d4
+#include <support/xunistd.h>
00c0d4
+#include <support/check.h>
00c0d4
+
00c0d4
+#include <sys/stat.h>
00c0d4
+
00c0d4
+void
00c0d4
+xchmod (const char *pathname, mode_t mode)
00c0d4
+{
00c0d4
+  int r = chmod (pathname, mode);
00c0d4
+  if (r < 0)
00c0d4
+    FAIL_EXIT1 ("chmod (%s, %d): %m", pathname, mode);
00c0d4
+}
00c0d4
diff --git a/support/xunistd.h b/support/xunistd.h
00c0d4
index ced8cb1dd9ee356c..e92056c65efe8d6a 100644
00c0d4
--- a/support/xunistd.h
00c0d4
+++ b/support/xunistd.h
00c0d4
@@ -46,6 +46,7 @@ void xftruncate (int fd, long long length);
00c0d4
 void xsymlink (const char *target, const char *linkpath);
00c0d4
 void xchdir (const char *path);
00c0d4
 void xfchmod (int fd, mode_t mode);
00c0d4
+void xchmod (const char *pathname, mode_t mode);
00c0d4
 
00c0d4
 /* Equivalent of "mkdir -p".  */
00c0d4
 void xmkdirp (const char *, mode_t);