4cc9c6
commit a7e9dbb7742954814643a8562dcad09abb0b0e5d
4cc9c6
Author: Alexandra Hájková <ahajkova@redhat.com>
4cc9c6
Date:   Sat Dec 26 18:45:13 2020 +0100
4cc9c6
4cc9c6
    Add xchdir to libsupport.
4cc9c6
4cc9c6
diff --git a/support/Makefile b/support/Makefile
4cc9c6
index dcf3c4baa2a31070..fb95a69ed9158e78 100644
4cc9c6
--- a/support/Makefile
4cc9c6
+++ b/support/Makefile
4cc9c6
@@ -82,6 +82,7 @@ libsupport-routines = \
4cc9c6
   xasprintf \
4cc9c6
   xbind \
4cc9c6
   xcalloc \
4cc9c6
+  xchdir \
4cc9c6
   xchroot \
4cc9c6
   xclose \
4cc9c6
   xconnect \
4cc9c6
diff --git a/support/xchdir.c b/support/xchdir.c
4cc9c6
new file mode 100644
4cc9c6
index 0000000000000000..beb4feff72832065
4cc9c6
--- /dev/null
4cc9c6
+++ b/support/xchdir.c
4cc9c6
@@ -0,0 +1,28 @@
4cc9c6
+/* chdir with error checking.
4cc9c6
+   Copyright (C) 2020 Free Software Foundation, Inc.
4cc9c6
+   This file is part of the GNU C Library.
4cc9c6
+
4cc9c6
+   The GNU C Library is free software; you can redistribute it and/or
4cc9c6
+   modify it under the terms of the GNU Lesser General Public
4cc9c6
+   License as published by the Free Software Foundation; either
4cc9c6
+   version 2.1 of the License, or (at your option) any later version.
4cc9c6
+
4cc9c6
+   The GNU C Library is distributed in the hope that it will be useful,
4cc9c6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
4cc9c6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4cc9c6
+   Lesser General Public License for more details.
4cc9c6
+
4cc9c6
+   You should have received a copy of the GNU Lesser General Public
4cc9c6
+   License along with the GNU C Library; if not, see
4cc9c6
+   <https://www.gnu.org/licenses/>.  */
4cc9c6
+
4cc9c6
+#include <support/check.h>
4cc9c6
+#include <support/xunistd.h>
4cc9c6
+#include <unistd.h>
4cc9c6
+
4cc9c6
+void
4cc9c6
+xchdir (const char *path)
4cc9c6
+{
4cc9c6
+  if (chdir (path) != 0)
4cc9c6
+    FAIL_EXIT1 ("chdir (\"%s\"): %m", path);
4cc9c6
+}
4cc9c6
diff --git a/support/xunistd.h b/support/xunistd.h
4cc9c6
index f99f362cb4763c5b..74fd2771d12c36fe 100644
4cc9c6
--- a/support/xunistd.h
4cc9c6
+++ b/support/xunistd.h
4cc9c6
@@ -44,6 +44,7 @@ long xsysconf (int name);
4cc9c6
 long long xlseek (int fd, long long offset, int whence);
4cc9c6
 void xftruncate (int fd, long long length);
4cc9c6
 void xsymlink (const char *target, const char *linkpath);
4cc9c6
+void xchdir (const char *path);
4cc9c6
 
4cc9c6
 /* Equivalent of "mkdir -p".  */
4cc9c6
 void xmkdirp (const char *, mode_t);