#ifndef sys_dir_h
#define sys_dir_h
/*
* There are two flavors of directory packages common. They can usually
* be  distinguished  by whether they use <direct.h> or <dirent.h>, and
* there are other differences. We try to straighten them out here, but
* this can be expected to cause problems on new systems.  Note the use
* of the dirlen() macro as a portable way to get  the  length  of  the
* name of a directory entry.
*
#include <sys/dir.h>	-- You may need this, but usually not.
*/


#if USE_direct
/*
* Systems with direct.h supply the d_namlen field:
*/
#include <direct.h>
static char id_sys_dir[] = "USE_direct sys_dir.h";
#define dirlen(p) p->d_namlen
#ifndef DIRE
#define DIRE struct direct
#endif
#endif

#if USE_dirent
/*
* Systems with dirent.h generally don't have d_namlen, but strlen
* works to get the length of the entry:
*/
#include <dirent.h>
static char id_sys_dir[] = "USE_dirent sys_dir.h";
#define dirlen(p) strlen(p->d_name)
#ifndef DIRE
#define DIRE struct dirent
#endif
#endif

#ifdef OSF1
/* 
* OSF1 seems to be especially perverse here, in that it uses the  name
* "dirent"  but  the  struct  looks  like the one in direct.h on other
* systems. <direct.h> doesn't exist, and if we call strlen(p->d_name),
* we may bomb due to a lack of a null chr.
*/
static char id_sys_dir[] = "OSF1 sys_dir.h";
#include <dirent.h>
#define dirlen(p) p->d_namlen
#ifndef DIRE
#define DIRE struct dirent
#endif
#endif

#define Opendir(n) opendir((char*)(n))
#define Readdir(d,e) (e = readdir((DIR*)(d)))
#define ReaddirR(d,e) readdir_r((DIR*)(d),(DIRE*)(e))

#endif
