root/libltdl/lt__dirent.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. closedir
  2. opendir
  3. readdir

   1 /* lt__dirent.c -- internal directory entry scanning interface
   2 
   3    Copyright (C) 2001, 2004, 2011-2019, 2021-2022 Free Software
   4    Foundation, Inc.
   5    Written by Bob Friesenhahn, 2001
   6 
   7    NOTE: The canonical source of this file is maintained with the
   8    GNU Libtool package.  Report bugs to bug-libtool@gnu.org.
   9 
  10 GNU Libltdl is free software; you can redistribute it and/or
  11 modify it under the terms of the GNU Lesser General Public
  12 License as published by the Free Software Foundation; either
  13 version 2 of the License, or (at your option) any later version.
  14 
  15 As a special exception to the GNU Lesser General Public License,
  16 if you distribute this file as part of a program or library that
  17 is built using GNU Libtool, you may include this file under the
  18 same distribution terms that you use for the rest of that program.
  19 
  20 GNU Libltdl is distributed in the hope that it will be useful,
  21 but WITHOUT ANY WARRANTY; without even the implied warranty of
  22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23 GNU Lesser General Public License for more details.
  24 
  25 You should have received a copy of the GNU Lesser General Public
  26 License along with GNU Libltdl; see the file COPYING.LIB.  If not, a
  27 copy can be downloaded from  http://www.gnu.org/licenses/lgpl.html,
  28 or obtained by writing to the Free Software Foundation, Inc.,
  29 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  30 */
  31 
  32 #include "lt__private.h"
  33 
  34 #include <assert.h>
  35 
  36 #include "lt__dirent.h"
  37 
  38 #if defined __WINDOWS__
  39 
  40 void
  41 closedir (DIR *entry)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43   assert (entry != (DIR *) NULL);
  44   FindClose (entry->hSearch);
  45   free (entry);
  46 }
  47 
  48 
  49 DIR *
  50 opendir (const char *path)
     /* [previous][next][first][last][top][bottom][index][help] */
  51 {
  52   char file_spec[LT_FILENAME_MAX];
  53   DIR *entry;
  54 
  55   assert (path != (char *) 0);
  56   if (lt_strlcpy (file_spec, path, sizeof file_spec) >= sizeof file_spec
  57       || lt_strlcat (file_spec, "\\", sizeof file_spec) >= sizeof file_spec)
  58     return (DIR *) 0;
  59   entry = (DIR *) malloc (sizeof(DIR));
  60   if (entry != (DIR *) 0)
  61     {
  62       entry->firsttime = TRUE;
  63       entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
  64 
  65       if (entry->hSearch == INVALID_HANDLE_VALUE)
  66         {
  67           if (lt_strlcat (file_spec, "\\*.*", sizeof file_spec) < sizeof file_spec)
  68             {
  69               entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
  70             }
  71 
  72           if (entry->hSearch == INVALID_HANDLE_VALUE)
  73             {
  74               entry = (free (entry), (DIR *) 0);
  75             }
  76         }
  77     }
  78 
  79   return entry;
  80 }
  81 
  82 
  83 struct dirent *
  84 readdir (DIR *entry)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86   int status;
  87 
  88   if (entry == (DIR *) 0)
  89     return (struct dirent *) 0;
  90 
  91   if (!entry->firsttime)
  92     {
  93       status = FindNextFile (entry->hSearch, &entry->Win32FindData);
  94       if (status == 0)
  95         return (struct dirent *) 0;
  96     }
  97 
  98   entry->firsttime = FALSE;
  99   if (lt_strlcpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
 100         sizeof entry->file_info.d_name) >= sizeof entry->file_info.d_name)
 101     return (struct dirent *) 0;
 102   entry->file_info.d_namlen = strlen (entry->file_info.d_name);
 103 
 104   return &entry->file_info;
 105 }
 106 
 107 #endif /*defined __WINDOWS__*/

/* [previous][next][first][last][top][bottom][index][help] */