delorie.com/djgpp/bugs/show.cgi   search  
Bug 000219

When Created: 05/08/1998 08:31:02
Against DJGPP version: 2.01
By whom: womo@mindless.com
Abstract: opendir/readdir/rewinddir/closedir LFN search handle close problem
Hi,

I'm using plain DOS with a Win95 LFN-API simulator
(check http://ludens.elte.hu/~sta/lfndos.html) 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.

Womo

PS: bugfix proposion follows

Solution added: 05/08/1998 08:35:36
By whom: womo@mindless.com
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>

int
closedir(DIR *dir)
{
  rewinddir(dir);       // rewinddir includes the test for
                        // unclosed LFN search handles
  free(dir->name);
  free(dir);
  return 0;
}

void
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;
    r.x.ax = 0x71a1;
    __dpmi_int(0x21, &r);
    }
  dir->num_read = 0;
}



Womo.

Fixed in version on 04/12/1999 10:00:35
By whom: eliz@is.elta.co.il



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