/*
 *   Copyright (C) 1988-2006 Lucent Technologies Inc. and others.
 *   All Rights Reserved.
 */

/* This file defines a common set of directory reading macros based on the
 * Berkeley library functions, so define statdir() for all and opendir(),
 * readdir(), rewinddir(), and closedir() for System V Release 2.
 */
#ifdef SVR2
/* allow for a terminating null on the name, which must be the last structure 
   member */
#undef	DIRSIZ
#define DIRSIZ		15
/* can't use sizeof(_dirstruct) - 1 because it may be padded to a word boundry */
#define REALDIRSIZE	(sizeof(ushort) + DIRSIZ - 1)
#include <sys/dir.h>		/* must be after DIRSIZ definition */
#define MAXNAMLEN	DIRSIZ - 1
#define	DIR		FILE
#define	dirent		direct
#define opendir(name)		fopen(name, "r")
#define closedir(file)		(void) fclose(file)
#define rewinddir(file)		rewind(file)
#define	statdir(file, statp)	fstat(fileno(file), statp)
#define readdir(file)		\
	(fread((char *) &_dirstruct, REALDIRSIZE, 1, file) == 1 ? \
	&_dirstruct : (struct direct *) NULL)
static	struct	direct	_dirstruct;
#else /* !SVR2 */
#ifdef alliant
#include <dir.h>
#define	dirent	direct
#else
#ifdef RESEARCH
#include <ndir.h>
#define	dirent	direct
#else
#if defined(FOR_WIN32)
#include "dirent.h"
#else
#include <dirent.h>
#endif
#endif
#endif
#if ilinux || cygwin
#define	statdir(file, statp)	stat(file, statp)
#else
#define	statdir(file, statp)	fstat(file->dd_fd, statp)
#endif
#endif
