Article View: comp.bugs.sys5
Article #100Re: Bug in closedir
From: Doug Gwyn
Date: Sat, 16 Sep 1989 23:20
Date: Sat, 16 Sep 1989 23:20
48 lines
1647 bytes
1647 bytes
In article <1989Sep16.025206.5915@twwells.com> bill@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 );
}
Technical Details
Message-ID:
<11081@smoke.BRL.MIL>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwynReferences:
<1989Sep16.025206.5915@twwells.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.bugs.sys5 Subject: Re: Bug in closedir Message-ID: <11081@smoke.BRL.MIL> Date: 16 Sep 89 23:20:33 GMT References: <1989Sep16.025206.5915@twwells.com> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 48