1cf28ed85SJohn Marino /* Report a save- or restore-cwd failure in our openat replacement and then exit.
2cf28ed85SJohn Marino
3*09d4459fSDaniel Fojt Copyright (C) 2005-2006, 2008-2020 Free Software Foundation, Inc.
4cf28ed85SJohn Marino
5cf28ed85SJohn Marino This program is free software: you can redistribute it and/or modify
6cf28ed85SJohn Marino it under the terms of the GNU General Public License as published by
7cf28ed85SJohn Marino the Free Software Foundation; either version 3 of the License, or
8cf28ed85SJohn Marino (at your option) any later version.
9cf28ed85SJohn Marino
10cf28ed85SJohn Marino This program is distributed in the hope that it will be useful,
11cf28ed85SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
12cf28ed85SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13cf28ed85SJohn Marino GNU General Public License for more details.
14cf28ed85SJohn Marino
15cf28ed85SJohn Marino You should have received a copy of the GNU General Public License
16*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */
17cf28ed85SJohn Marino
18cf28ed85SJohn Marino #include <config.h>
19cf28ed85SJohn Marino
20cf28ed85SJohn Marino #include "openat.h"
21cf28ed85SJohn Marino
22cf28ed85SJohn Marino #include <stdlib.h>
23cf28ed85SJohn Marino
24cf28ed85SJohn Marino #ifndef GNULIB_LIBPOSIX
25cf28ed85SJohn Marino # include "error.h"
26cf28ed85SJohn Marino #endif
27cf28ed85SJohn Marino
28cf28ed85SJohn Marino #include "exitfail.h"
29cf28ed85SJohn Marino
30cf28ed85SJohn Marino #include "gettext.h"
31cf28ed85SJohn Marino #define _(msgid) gettext (msgid)
32cf28ed85SJohn Marino
33dc7c36e4SJohn Marino _Noreturn void
openat_save_fail(int errnum)34cf28ed85SJohn Marino openat_save_fail (int errnum)
35cf28ed85SJohn Marino {
36cf28ed85SJohn Marino #ifndef GNULIB_LIBPOSIX
37cf28ed85SJohn Marino error (exit_failure, errnum,
38cf28ed85SJohn Marino _("unable to record current working directory"));
39cf28ed85SJohn Marino #endif
40cf28ed85SJohn Marino /* _Noreturn cannot be applied to error, since it returns
41cf28ed85SJohn Marino when its first argument is 0. To help compilers understand that this
42cf28ed85SJohn Marino function does not return, call abort. Also, the abort is a
43cf28ed85SJohn Marino safety feature if exit_failure is 0 (which shouldn't happen). */
44cf28ed85SJohn Marino abort ();
45cf28ed85SJohn Marino }
46cf28ed85SJohn Marino
47cf28ed85SJohn Marino
48cf28ed85SJohn Marino /* Exit with an error about failure to restore the working directory
49cf28ed85SJohn Marino during an openat emulation. The caller must ensure that fd 2 is
50cf28ed85SJohn Marino not a just-opened fd, even when openat_safer is not in use. */
51cf28ed85SJohn Marino
52dc7c36e4SJohn Marino _Noreturn void
openat_restore_fail(int errnum)53cf28ed85SJohn Marino openat_restore_fail (int errnum)
54cf28ed85SJohn Marino {
55cf28ed85SJohn Marino #ifndef GNULIB_LIBPOSIX
56cf28ed85SJohn Marino error (exit_failure, errnum,
57cf28ed85SJohn Marino _("failed to return to initial working directory"));
58cf28ed85SJohn Marino #endif
59cf28ed85SJohn Marino
60cf28ed85SJohn Marino /* As above. */
61cf28ed85SJohn Marino abort ();
62cf28ed85SJohn Marino }
63