directory routine bug

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Nov 12 13:39:22 AEST 1988


Please replace closedir.c in my recent posting of the public-domain
directory access routine sources with the following:

/*
	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.sources.bugs mailing list