157 |
# |
# |
158 |
# dirfd |
# dirfd |
159 |
# |
# |
160 |
|
dnl Find out how to get the file descriptor associated with an open DIR*. |
161 |
|
dnl From Jim Meyering |
162 |
|
|
163 |
|
AC_DEFUN([UTILS_FUNC_DIRFD], |
164 |
|
[ |
165 |
|
|
166 |
|
AC_HEADER_DIRENT |
167 |
|
dirfd_headers=' |
168 |
|
#if HAVE_DIRENT_H |
169 |
|
# include <dirent.h> |
170 |
|
#else /* not HAVE_DIRENT_H */ |
171 |
|
# define dirent direct |
172 |
|
# if HAVE_SYS_NDIR_H |
173 |
|
# include <sys/ndir.h> |
174 |
|
# endif /* HAVE_SYS_NDIR_H */ |
175 |
|
# if HAVE_SYS_DIR_H |
176 |
|
# include <sys/dir.h> |
177 |
|
# endif /* HAVE_SYS_DIR_H */ |
178 |
|
# if HAVE_NDIR_H |
179 |
|
# include <ndir.h> |
180 |
|
# endif /* HAVE_NDIR_H */ |
181 |
|
#endif /* HAVE_DIRENT_H */ |
182 |
|
' |
183 |
|
AC_CHECK_FUNCS(dirfd) |
184 |
|
AC_CHECK_DECLS([dirfd], , , $dirfd_headers) |
185 |
|
|
186 |
|
AC_CACHE_CHECK([whether dirfd is a macro], |
187 |
|
jm_cv_func_dirfd_macro, |
188 |
|
[AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers |
189 |
|
#ifdef dirfd |
190 |
|
dirent_header_defines_dirfd |
191 |
|
#endif], |
192 |
|
jm_cv_func_dirfd_macro=yes, |
193 |
|
jm_cv_func_dirfd_macro=no)]) |
194 |
|
|
195 |
|
# Use the replacement only if we have no function, macro, |
196 |
|
# or declaration with that name. |
197 |
|
if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$jm_cv_func_dirfd_macro \ |
198 |
|
= no,no,no; then |
199 |
|
AC_REPLACE_FUNCS([dirfd]) |
200 |
|
AC_CACHE_CHECK( |
201 |
|
[how to get the file descriptor associated with an open DIR*], |
202 |
|
gl_cv_sys_dir_fd_member_name, |
203 |
|
[ |
204 |
|
dirfd_save_CFLAGS=$CFLAGS |
205 |
|
for ac_expr in d_fd dd_fd; do |
206 |
|
|
207 |
|
CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr" |
208 |
|
AC_TRY_COMPILE( |
209 |
|
[$dirfd_headers |
210 |
|
], |
211 |
|
[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;], |
212 |
|
dir_fd_found=yes |
213 |
|
) |
214 |
|
CFLAGS=$dirfd_save_CFLAGS |
215 |
|
test "$dir_fd_found" = yes && break |
216 |
|
done |
217 |
|
test "$dir_fd_found" = yes || ac_expr=no_such_member |
218 |
|
|
219 |
|
gl_cv_sys_dir_fd_member_name=$ac_expr |
220 |
|
] |
221 |
|
) |
222 |
|
if test $gl_cv_sys_dir_fd_member_name != no_such_member; then |
223 |
|
AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME, |
224 |
|
$gl_cv_sys_dir_fd_member_name, |
225 |
|
[the name of the file descriptor member of DIR]) |
226 |
|
fi |
227 |
|
AH_VERBATIM(DIR_TO_FD, |
228 |
|
[#ifdef DIR_FD_MEMBER_NAME |
229 |
|
# define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME) |
230 |
|
#else |
231 |
|
# define DIR_TO_FD(Dir_p) -1 |
232 |
|
#endif |
233 |
|
] |
234 |
|
) |
235 |
|
fi |
236 |
|
]) |
237 |
|
|
238 |
UTILS_FUNC_DIRFD |
UTILS_FUNC_DIRFD |
239 |
|
|
240 |
# |
# |