This source file includes following definitions.
- AT_FUNC_NAME
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "filename.h"
20
21 #ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
22 # include <errno.h>
23 # ifndef ENOTSUP
24 # define ENOTSUP EINVAL
25 # endif
26 #else
27 # include "openat.h"
28 # include "openat-priv.h"
29 # include "save-cwd.h"
30 #endif
31
32 #ifdef AT_FUNC_USE_F1_COND
33 # define CALL_FUNC(F) \
34 (flag == AT_FUNC_USE_F1_COND \
35 ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \
36 : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS))
37 # define VALIDATE_FLAG(F) \
38 if (flag & ~AT_FUNC_USE_F1_COND) \
39 { \
40 errno = EINVAL; \
41 return FUNC_FAIL; \
42 }
43 #else
44 # define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS))
45 # define VALIDATE_FLAG(F)
46 #endif
47
48 #ifdef AT_FUNC_RESULT
49 # define FUNC_RESULT AT_FUNC_RESULT
50 #else
51 # define FUNC_RESULT int
52 #endif
53
54 #ifdef AT_FUNC_FAIL
55 # define FUNC_FAIL AT_FUNC_FAIL
56 #else
57 # define FUNC_FAIL -1
58 #endif
59
60
61
62
63
64
65
66
67
68
69 FUNC_RESULT
70 AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
71 {
72 VALIDATE_FLAG (flag);
73
74 if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file))
75 return CALL_FUNC (file);
76
77 #ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
78 errno = ENOTSUP;
79 return FUNC_FAIL;
80 #else
81 {
82
83
84 struct saved_cwd saved_cwd;
85 int saved_errno;
86 FUNC_RESULT err;
87
88 {
89 char proc_buf[OPENAT_BUFFER_SIZE];
90 char *proc_file = openat_proc_name (proc_buf, fd, file);
91 if (proc_file)
92 {
93 FUNC_RESULT proc_result = CALL_FUNC (proc_file);
94 int proc_errno = errno;
95 if (proc_file != proc_buf)
96 free (proc_file);
97
98
99
100 if (FUNC_FAIL != proc_result)
101 return proc_result;
102 if (! EXPECTED_ERRNO (proc_errno))
103 {
104 errno = proc_errno;
105 return proc_result;
106 }
107 }
108 }
109
110 if (save_cwd (&saved_cwd) != 0)
111 openat_save_fail (errno);
112 if (0 <= fd && fd == saved_cwd.desc)
113 {
114
115
116
117 free_cwd (&saved_cwd);
118 errno = EBADF;
119 return FUNC_FAIL;
120 }
121
122 if (fchdir (fd) != 0)
123 {
124 saved_errno = errno;
125 free_cwd (&saved_cwd);
126 errno = saved_errno;
127 return FUNC_FAIL;
128 }
129
130 err = CALL_FUNC (file);
131 saved_errno = (err == FUNC_FAIL ? errno : 0);
132
133 if (restore_cwd (&saved_cwd) != 0)
134 openat_restore_fail (errno);
135
136 free_cwd (&saved_cwd);
137
138 if (saved_errno)
139 errno = saved_errno;
140 return err;
141 }
142 #endif
143 }
144 #undef CALL_FUNC
145 #undef FUNC_RESULT
146 #undef FUNC_FAIL