(root)/
gawk-5.2.2/
extension/
gawkdirfd.h
       1  /* dirfd.c -- return the file descriptor associated with an open DIR*
       2  
       3     Copyright (C) 2001, 2006, 2008-2013 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  /* Modified for gawk */
      21  
      22  #include <config.h>
      23  
      24  #ifndef ENOTSUP
      25  # define ENOTSUP ENOSYS
      26  #endif
      27  
      28  /*
      29   * This is for fake directory file descriptors on systems that don't
      30   * allow to open() a directory.
      31   *
      32   * Including a header from the main gawk source to share the definition
      33   * of FAKE_FD_VALUE is the least of all evils that I can see.
      34   *
      35   * Unlike the main gawk code base, this include is NOT dependant
      36   * upon MinGW or EMX.
      37   */
      38  #ifndef __VMS
      39  #include "../nonposix.h"
      40  #else
      41  #include "nonposix.h"
      42  #endif
      43  
      44  #ifndef DIR_TO_FD
      45  # define DIR_TO_FD(d) (FAKE_FD_VALUE)
      46  #endif
      47  
      48  #if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0)
      49  int
      50  dirfd (DIR *dir_p)
      51  {
      52    int fd = DIR_TO_FD (dir_p);
      53    if (fd == -1)
      54      errno = ENOTSUP;
      55    return fd;
      56  }
      57  #endif /* HAVE_DIRFD */