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