/*
 * Copyright (c) 1996-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * dirent.h : directory definitions
 */


#ifndef __DIRENT_H
#ifdef __cplusplus
extern "C" {
#endif
#define __DIRENT_H

/* POSIX, SVR3, BSD  include file */


/* --- Required -- */
#ifndef _POSIX_SOURCE
#include <sys/types.h>
#endif

/*
 * The kernel defines the format of directory entries returned by 
 * the getdirentries(2) system call.
 */
#include <sys/dirent.h>

/* definitions for library routines operating on directories. */
#define	DIRBLKSIZ	1024

/* --- Types --- */
#ifdef _POSIX_SOURCE
typedef void *	DIR;
#else

#define	d_ino		d_fileno	/* backward compatibility */

typedef struct _dirdesc {
    int		dd_fd;		/* file descriptor */
    long	dd_loc;		/* offset in block */
    long	dd_size;	/* amount of valid data */
    char	*dd_buf;	/* -> directory block */
    int		dd_len;		/* size of data buffer */
    long	dd_seek;	/* magic cookie from getdirentries */
    long	dd_rewind;	/* magic cookie for rewinding */
    int		dd_flags;	/* flags for readdir */
} DIR;			/* stream data from opendir() */

#define	dirfd(dirp)	((dirp)->dd_fd)

/* flags for opendir2 */
#define DTF_HIDEW	0x0001	/* hide whiteout entries */
#define DTF_NODUP	0x0002	/* don't return duplicate names */
#define DTF_REWIND	0x0004	/* rewind after reading union stack */
#define __DTF_READALL	0x0008	/* everything has been read */

#endif

/* --- Prototypes --- */
DIR	*opendir	(const char *);
struct dirent *readdir	(DIR *);
int	readdir_r	(DIR *, struct dirent *, struct dirent **);
void	rewinddir	(DIR *);
int	closedir	(DIR *);

#ifndef _POSIX_SOURCE
/* --- non POSIX --- */
int	getdirentries	(int, char *, int, long *);
long	telldir		(const DIR *);
void	seekdir		(DIR *, long);
int	scandir		(const char *, struct dirent ***,
			 int (*)(struct dirent *), 
			 int (*)(const void *, const void *));
int	alphasort 	(const void *, const void *);
#endif

#ifdef __cplusplus
}
#endif
#endif /* !defined __DIRENT_H */
