1/* Internals for openat-like functions.
2
3   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18/* written by Jim Meyering */
19
20#include <errno.h>
21#include <stdlib.h>
22
23#define OPENAT_BUFFER_SIZE 512
24char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file);
25
26/* Some systems don't have ENOSYS.  */
27#ifndef ENOSYS
28# ifdef ENOTSUP
29#  define ENOSYS ENOTSUP
30# else
31/* Some systems don't have ENOTSUP either.  */
32#  define ENOSYS EINVAL
33# endif
34#endif
35
36/* Some systems don't have EOPNOTSUPP.  */
37#ifndef EOPNOTSUPP
38# ifdef ENOTSUP
39#  define EOPNOTSUPP ENOTSUP
40# else
41/* Some systems don't have ENOTSUP either.  */
42#  define EOPNOTSUPP EINVAL
43# endif
44#endif
45
46/* Trying to access a BUILD_PROC_NAME file will fail on systems without
47   /proc support, and even on systems *with* ProcFS support.  Return
48   nonzero if the failure may be legitimate, e.g., because /proc is not
49   readable, or the particular .../fd/N directory is not present.  */
50#define EXPECTED_ERRNO(Errno)			\
51  ((Errno) == ENOTDIR || (Errno) == ENOENT	\
52   || (Errno) == EPERM || (Errno) == EACCES	\
53   || (Errno) == ENOSYS /* Solaris 8 */		\
54   || (Errno) == EOPNOTSUPP /* FreeBSD */)
55