Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos # serial 26   -*- Autoconf -*-
      2      1.1  christos 
      3      1.1  christos dnl Find out how to get the file descriptor associated with an open DIR*.
      4      1.1  christos 
      5  1.1.1.2  christos # Copyright (C) 2001-2006, 2008-2022 Free Software Foundation, Inc.
      6      1.1  christos # This file is free software; the Free Software Foundation
      7      1.1  christos # gives unlimited permission to copy and/or distribute it,
      8      1.1  christos # with or without modifications, as long as this notice is preserved.
      9      1.1  christos 
     10      1.1  christos dnl From Jim Meyering
     11      1.1  christos 
     12      1.1  christos AC_DEFUN([gl_FUNC_DIRFD],
     13      1.1  christos [
     14      1.1  christos   AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
     15      1.1  christos   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
     16      1.1  christos 
     17      1.1  christos   dnl Persuade glibc <dirent.h> to declare dirfd().
     18      1.1  christos   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
     19      1.1  christos 
     20      1.1  christos   AC_CHECK_FUNCS([dirfd])
     21      1.1  christos   AC_CHECK_DECLS([dirfd], , ,
     22      1.1  christos     [[#include <sys/types.h>
     23      1.1  christos       #include <dirent.h>]])
     24      1.1  christos   if test $ac_cv_have_decl_dirfd = no; then
     25      1.1  christos     HAVE_DECL_DIRFD=0
     26      1.1  christos   fi
     27      1.1  christos 
     28      1.1  christos   AC_CACHE_CHECK([whether dirfd is a macro],
     29      1.1  christos     [gl_cv_func_dirfd_macro],
     30      1.1  christos     [AC_EGREP_CPP([dirent_header_defines_dirfd], [
     31      1.1  christos #include <sys/types.h>
     32      1.1  christos #include <dirent.h>
     33      1.1  christos #ifdef dirfd
     34      1.1  christos  dirent_header_defines_dirfd
     35      1.1  christos #endif],
     36      1.1  christos        [gl_cv_func_dirfd_macro=yes],
     37      1.1  christos        [gl_cv_func_dirfd_macro=no])])
     38      1.1  christos 
     39      1.1  christos   # Use the replacement if we have no function or macro with that name,
     40      1.1  christos   # or if OS/2 kLIBC whose dirfd() does not work.
     41      1.1  christos   # Replace only if the system declares dirfd already.
     42      1.1  christos   case $ac_cv_func_dirfd,$gl_cv_func_dirfd_macro,$host_os,$ac_cv_have_decl_dirfd in
     43      1.1  christos     no,no,*,yes | *,*,os2*,yes)
     44      1.1  christos       REPLACE_DIRFD=1
     45      1.1  christos       AC_DEFINE([REPLACE_DIRFD], [1],
     46      1.1  christos         [Define to 1 if gnulib's dirfd() replacement is used.]);;
     47      1.1  christos   esac
     48      1.1  christos ])
     49      1.1  christos 
     50      1.1  christos dnl Prerequisites of lib/dirfd.c.
     51      1.1  christos AC_DEFUN([gl_PREREQ_DIRFD],
     52      1.1  christos [
     53      1.1  christos   AC_CACHE_CHECK([how to get the file descriptor associated with an open DIR*],
     54      1.1  christos                  [gl_cv_sys_dir_fd_member_name],
     55      1.1  christos     [
     56      1.1  christos       dirfd_save_CFLAGS=$CFLAGS
     57      1.1  christos       for ac_expr in d_fd dd_fd; do
     58      1.1  christos 
     59      1.1  christos         CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
     60      1.1  christos         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
     61      1.1  christos            #include <sys/types.h>
     62      1.1  christos            #include <dirent.h>]],
     63      1.1  christos           [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])],
     64      1.1  christos           [dir_fd_found=yes]
     65      1.1  christos         )
     66      1.1  christos         CFLAGS=$dirfd_save_CFLAGS
     67      1.1  christos         test "$dir_fd_found" = yes && break
     68      1.1  christos       done
     69      1.1  christos       test "$dir_fd_found" = yes || ac_expr=no_such_member
     70      1.1  christos 
     71      1.1  christos       gl_cv_sys_dir_fd_member_name=$ac_expr
     72      1.1  christos     ]
     73      1.1  christos   )
     74      1.1  christos   if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
     75      1.1  christos     AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME],
     76      1.1  christos       [$gl_cv_sys_dir_fd_member_name],
     77      1.1  christos       [the name of the file descriptor member of DIR])
     78      1.1  christos   fi
     79      1.1  christos   AH_VERBATIM([DIR_TO_FD],
     80      1.1  christos               [#ifdef DIR_FD_MEMBER_NAME
     81      1.1  christos # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
     82      1.1  christos #else
     83      1.1  christos # define DIR_TO_FD(Dir_p) -1
     84      1.1  christos #endif
     85      1.1  christos ])
     86      1.1  christos ])
     87