delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/11/08/04:53:54

Date: Sun, 8 Nov 1998 11:51:54 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: djgpp-workers AT delorie DOT com
Subject: Re: readdir and hidden files
In-Reply-To: <199811051725.MAA21468@indy.delorie.com>
Message-ID: <Pine.SUN.3.91.981108115123.12269A-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

On Thu, 5 Nov 1998, DJ Delorie wrote:

> > Does anybody remember why readdir by default skips hidden files?
> 
> Because that's the DOS default for findfirst - hidden files are
> ignored unless you specify otherwise.

Okay, but the user of readdir shouldn't be affected by whatever
defaults finfirst employs.

> We can reverse it, so that you have the option of ignoring hidden
> files.  Then the startup code can use the reversed option to do the
> right thing itself.

Actually, I was wrong: the startup code doesn't use readdir, it calls
findfirst/findnext directly (inside glob).  So the patch below doesn't
change anything in startup behavior and doesn't require any changes
there.  The patch also includes some related docs fixes.

Please look at the way I defined bits in __OPENDIR_FLAGS for
back-compatibility, in case I got it wrong.

*** src/libc/posix/dirent/readdir.c~0	Sun Aug 31 13:12:54 1997
--- src/libc/posix/dirent/readdir.c	Sat Nov  7 11:52:00 1998
*************** readdir(DIR *dir)
*** 33,39 ****
    else
    {
      int ff_flags = FA_ARCH|FA_RDONLY|FA_DIREC|FA_SYSTEM;
!     if (dir->flags & __OPENDIR_FIND_HIDDEN)
        ff_flags |= FA_HIDDEN;
      if (dir->flags & __OPENDIR_FIND_LABEL)
        ff_flags |= FA_LABEL;
--- 33,39 ----
    else
    {
      int ff_flags = FA_ARCH|FA_RDONLY|FA_DIREC|FA_SYSTEM;
!     if (!(dir->flags & __OPENDIR_NO_HIDDEN))
        ff_flags |= FA_HIDDEN;
      if (dir->flags & __OPENDIR_FIND_LABEL)
        ff_flags |= FA_LABEL;
*** include/dirent.h~0	Fri Jun 16 04:54:22 1995
--- include/dirent.h	Sat Nov  7 12:35:26 1998
***************
*** 28,35 ****
  
  extern int __opendir_flags; /* default is zero, used only by opendir */
  #define __OPENDIR_PRESERVE_CASE	0001
! #define __OPENDIR_FIND_HIDDEN	0002
  #define __OPENDIR_FIND_LABEL	0004
  
  void seekdir(DIR *_dir, long _loc);
  long telldir(DIR *_dir);
--- 28,36 ----
  
  extern int __opendir_flags; /* default is zero, used only by opendir */
  #define __OPENDIR_PRESERVE_CASE	0001
! #define __OPENDIR_FIND_HIDDEN	0002 /* ignored; on by default */
  #define __OPENDIR_FIND_LABEL	0004
+ #define __OPENDIR_NO_HIDDEN	0x08 /* NOT 0002 for back-compatibility */
  
  void seekdir(DIR *_dir, long _loc);
  long telldir(DIR *_dir);
*** src/libc/posix/dirent/opendir.t~0	Sun Sep 27 15:22:10 1998
--- src/libc/posix/dirent/opendir.txh	Sat Nov  7 12:26:50 1998
***************
*** 25,38 ****
  Do not change the case of files to lower case.  Just in case Micros*ft
  decides to support case-sensitive file systems some day.
  
  @item __OPENDIR_FIND_HIDDEN
  
! Include hidden files and directories in the search.  By default, these
! are skipped.
  
  @end table
  
! You can simply put "int __opendir_flags = ...;" in your code.  The
  default is to let it get set to zero as an uninitialized variable.
  
  @subheading Return Value
--- 25,54 ----
  Do not change the case of files to lower case.  Just in case Micros*ft
  decides to support case-sensitive file systems some day.
  
+ You can also use this flag if you want the names of files like
+ @file{README} and @file{FAQ} from Unix distributions to be returned in
+ upper-case on Windows 9X filesystems.  @xref{_preserve_fncase}, for
+ other ways of achieving this and for more detailed description of the
+ automatic letter-case conversion by DJGPP library functions.
+ 
+ @item __OPENDIR_NO_HIDDEN
+ 
+ Do not include hidden files and directories in the search.  By default,
+ all files and directories are included.
+ 
  @item __OPENDIR_FIND_HIDDEN
  
! Provided for back-compatibility with previous DJGPP versions, where
! hidden files and directories were by default skipped.  In versions 2.02
! and later, this flag has no effect.
! 
! @item __OPENDIR_FIND_LABEL
! 
! Include volume labels in the search.  By default, these are skipped.
  
  @end table
  
! You can simply put @samp{int __opendir_flags = ...;} in your code.  The
  default is to let it get set to zero as an uninitialized variable.
  
  @subheading Return Value
***************
*** 41,46 ****
--- 57,63 ----
  
  @subheading Portability
  
+ @port-note posix The @code{__opendir_flags} variable is DJGPP-specific.
  @portability !ansi, posix
  
  @subheading Example
*** src/libc/posix/dirent/readdir.t~0	Sun Sep 27 15:22:10 1998
--- src/libc/posix/dirent/readdir.txh	Sat Nov  7 12:26:42 1998
***************
*** 20,31 ****
--- 20,36 ----
  @};
  @end example
  
+ Note that some directory entries might be skipped by @code{readdir},
+ depending on the bits set in the global variable
+ @code{__opendir_flags}.  @xref{opendir, __opendir_flags, opendir}.
+ 
  @subheading Return Value
  
  A pointer to a static buffer that is overwritten with each call.
  
  @subheading Portability
  
+ @port-note posix The @code{__opendir_flags} variable is DJGPP-specific.
  @portability !ansi, posix
  
  @subheading Example
*** src/docs/kb/wc202.t~0	Sun Oct  4 10:47:16 1998
--- src/docs/kb/wc202.txi	Sat Nov  7 12:43:02 1998
***************
*** 477,479 ****
--- 477,487 ----
  @code{select} now correctly zeroes out all the bits in the @code{fd_set}
  arguments when it returns due to expired timeout.
  @findex select
+ 
+ @code{readdir} now includes hidden files and directories in the search
+ by default.  The @code{__OPENDIR_FIND_HIDDEN} bit of the
+ @code{__opendir_flags} variable has no effect, and a new
+ @code{__OPENDIR_NO_HIDDEN} bit is provided to exclude hidden
+ files/directories from the search.
+ @findex opendir
+ @findex readdir

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019