Bug 000219

When Created: 05/08/1998 08:31:02
Against DJGPP version: 2.01
By whom:
Abstract: opendir/readdir/rewinddir/closedir LFN search handle close problem

I'm using plain DOS with a Win95 LFN-API simulator
(check and found a
bug in connection with the POSIX compliant libc functions
closedir and rewinddir.

I assume, LFN's are in use and a directory was opened with opendir.

1. If I use the function rewinddir after readdir and then readdir
   again, the new readdir call allocates _a new_ LFN search handle,
   but doesn't use the old.

2. If I use the function closedir after a readdir call, the
   closedir function doesn't close the used LFN search handle.


PS: bugfix proposion follows

Solution added: 05/08/1998 08:35:36
By whom:
I think, the functions rewinddir and closedir have to
be patched as follows:

  // If the directory entry search (readdir) is in the middle of the
  // directory (dir->num != 0) and it should be closed, then we have
  // additionally to check, if there is an open LFN search handle
  // and we have to close it before destroying the DIR-structure.
  // rewinddir has also to be patched, so I decided to apply the
  // patch into rewinddir and to use this function in closedir.

#include <dpmi.h>

closedir(DIR *dir)
  rewinddir(dir);       // rewinddir includes the test for
                        // unclosed LFN search handles
  return 0;

rewinddir(DIR *dir)
  __dpmi_regs r;
  int use_lfn = _USE_LFN;

  if(dir->num_read && use_lfn && (dir->ff.lfn_handle!=0))
    r.x.bx = dir->ff.lfn_handle; = 0x71a1;
    __dpmi_int(0x21, &r);
  dir->num_read = 0;


Fixed in version on 04/12/1999 10:00:35
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010