Bug in closedir
Doug Gwyn
gwyn at smoke.BRL.MIL
Sun Sep 17 09:20:33 AEST 1989
In article <1989Sep16.025206.5915 at twwells.com> bill at twwells.com (T. William Wells) writes:
>Closedir, on my Microport SysV/386 3.0e, frees the DIR structure
>and then closes the file using the first field of that structure.
>... No doubt this bogosity is present throughout the library.
I don't know about the last statement. I suspect Microport is using AT&T's
closedir() implementation, the SVR3.0 version of which was derived from one
of my earlier public-domain implementations. R. Salz pointed out the bug
to me and I fixed it long ago; here is my current version:
/*
closedir -- close a directory stream
last edit: 11-Nov-1988 D A Gwyn
*/
#include <sys/errno.h>
#include <sys/types.h>
#include <dirent.h>
typedef char *pointer; /* (void *) if you have it */
extern void free();
extern int close();
extern int errno;
#ifndef NULL
#define NULL 0
#endif
int
closedir( dirp )
register DIR *dirp; /* stream from opendir() */
{
register int fd;
if ( dirp == NULL || dirp->dd_buf == NULL )
{
errno = EFAULT;
return -1; /* invalid pointer */
}
fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
free( (pointer)dirp->dd_buf );
free( (pointer)dirp );
return close( fd );
}
More information about the Comp.bugs.sys5
mailing list