www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000041

When Created: 12/08/1995 22:54:13
Against DJGPP version: 2.00.beta3
By whom: sbehrens@contech.demon.co.uk
Abstract: opendir()/readdir() don't work in the face of a chdir()
Open a directory with opendir(), change to it with chdir(), and then try
to get its contents with readdir(). readdir() will fail.
The reason for this is that readdir() uses the string supplied to opendir()
to reference the directory, not an absolute path or unique ID.

Solution added: 01/04/1996 19:49:28
By whom: sbehrens@contech.demon.co.uk
Change opendir.c to create a full path from the full or partial path given.
I cannot test this fix with LFNs; it should work, though, provided that
_fixpath handles LFNs. Could someone verify this, maybe?

diff file for \djgpp\src\libc\posix\dirent\opendir.c below.

5a6,7
> #include <limits.h>
> #include <sys/stat.h>
12a15
> 
16c19
<   dir->name = (char *)malloc(strlen(name)+6);
---
>   dir->name = (char *)malloc(PATH_MAX);
22d24
<   strcpy(dir->name, name);
26,27c28,34
<   /* Append a "." if we got only the device name */
<   if (dir->name[1] == ':' && dir->name[2] == 0)
---
>   /* Make absolute path */
> 
>   _fixpath (name, dir->name);
> 
>   /* Reduce memory footage to amount needed */
>   dir->name = (char *)realloc(dir->name, strlen(dir->name)+5);
>   if (dir->name == 0)
29,30c36,37
<     dir->name[2] = '.';
<     dir->name[3] = 0;
---
>     free(dir);
>     return 0;
53c60
<   dir->name[length++] = 0;
---
>   dir->name[length++] = '\0';

Note added: 01/04/1996 19:51:53
By whom: sbehrens@contech.demon.co.uk
Teach me to use www without understanding it ... the last three lines of
the diff should read:

<   dir->name[length++] = 0;
---
>   dir->name[length++] = '\0';

(That's backslash-zero, in case I got it wrong again)

Note added: 01/08/1996 23:36:15
By whom: sandmann@clio.rice.edu
The realloc is really unnecessary, since the memory saved is trivial
if it was actually released, and it's not.  So this just makes the
code bigger, slower, and more complicated with no real benefit.  Other
than that, it looks like a good fix.  This appears to have been broken
when findfirst was moved from opendir to readdir.

Fixed in version 2.00.beta5 on 01/23/1996 21:51:32
By whom: dj@delorie.com



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