18dffb485Schristos /* Report a save- or restore-cwd failure in our openat replacement and then exit.
28dffb485Schristos
3*4b169a6bSchristos Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
48dffb485Schristos
58dffb485Schristos This program is free software: you can redistribute it and/or modify
68dffb485Schristos it under the terms of the GNU General Public License as published by
7*4b169a6bSchristos the Free Software Foundation, either version 3 of the License, or
88dffb485Schristos (at your option) any later version.
98dffb485Schristos
108dffb485Schristos This program is distributed in the hope that it will be useful,
118dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
128dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138dffb485Schristos GNU General Public License for more details.
148dffb485Schristos
158dffb485Schristos You should have received a copy of the GNU General Public License
168dffb485Schristos along with this program. If not, see <https://www.gnu.org/licenses/>. */
178dffb485Schristos
188dffb485Schristos #include <config.h>
198dffb485Schristos
208dffb485Schristos #include "openat.h"
218dffb485Schristos
228dffb485Schristos #include <stdlib.h>
238dffb485Schristos
248dffb485Schristos #ifndef GNULIB_LIBPOSIX
258dffb485Schristos # include "error.h"
268dffb485Schristos #endif
278dffb485Schristos
288dffb485Schristos #include "exitfail.h"
298dffb485Schristos
308dffb485Schristos #include "gettext.h"
318dffb485Schristos #define _(msgid) gettext (msgid)
328dffb485Schristos
338dffb485Schristos _Noreturn void
openat_save_fail(int errnum)348dffb485Schristos openat_save_fail (int errnum)
358dffb485Schristos {
368dffb485Schristos #ifndef GNULIB_LIBPOSIX
378dffb485Schristos error (exit_failure, errnum,
388dffb485Schristos _("unable to record current working directory"));
398dffb485Schristos #endif
408dffb485Schristos /* _Noreturn cannot be applied to error, since it returns
418dffb485Schristos when its first argument is 0. To help compilers understand that this
428dffb485Schristos function does not return, call abort. Also, the abort is a
438dffb485Schristos safety feature if exit_failure is 0 (which shouldn't happen). */
448dffb485Schristos abort ();
458dffb485Schristos }
468dffb485Schristos
478dffb485Schristos
488dffb485Schristos /* Exit with an error about failure to restore the working directory
498dffb485Schristos during an openat emulation. The caller must ensure that fd 2 is
508dffb485Schristos not a just-opened fd, even when openat_safer is not in use. */
518dffb485Schristos
528dffb485Schristos _Noreturn void
openat_restore_fail(int errnum)538dffb485Schristos openat_restore_fail (int errnum)
548dffb485Schristos {
558dffb485Schristos #ifndef GNULIB_LIBPOSIX
568dffb485Schristos error (exit_failure, errnum,
578dffb485Schristos _("failed to return to initial working directory"));
588dffb485Schristos #endif
598dffb485Schristos
608dffb485Schristos /* As above. */
618dffb485Schristos abort ();
628dffb485Schristos }
63