xref: /original-bsd/include/dirent.h (revision f5cc5b3e)
1 /*-
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)dirent.h	5.13 (Berkeley) 06/24/90
8  */
9 
10 #ifndef _DIRENT_
11 #define _DIRENT_
12 
13 /*
14  * A directory entry has a struct direct at the front of it, containing its
15  * inode number, the length of the entry, and the length of the name
16  * contained in the entry.  These are followed by the name padded to a 4
17  * byte boundary with null bytes.  All names are guaranteed null terminated.
18  * The maximum length of a name in a directory is MAXNAMLEN.
19  */
20 
21 struct dirent {
22 	u_long	d_fileno;		/* file number of entry */
23 	u_short	d_reclen;		/* length of this record */
24 	u_short	d_namlen;		/* length of string in d_name */
25 #ifdef _POSIX_SOURCE
26 	char	d_name[255 + 1];	/* name must be no longer than this */
27 #else
28 #define	MAXNAMLEN	255
29 	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
30 #endif
31 };
32 
33 #ifdef _POSIX_SOURCE
34 typedef void *	DIR;
35 #else
36 
37 #define	d_ino		d_fileno	/* backward compatibility */
38 
39 /* definitions for library routines operating on directories. */
40 #define	DIRBLKSIZ	1024
41 
42 /* structure describing an open directory. */
43 typedef struct _dirdesc {
44 	int	dd_fd;		/* file descriptor associated with directory */
45 	long	dd_loc;		/* offset in current buffer */
46 	long	dd_size;	/* amount of data returned by getdirentries */
47 	char	*dd_buf;	/* data buffer */
48 	int	dd_len;		/* size of data buffer */
49 	long	dd_seek;	/* magic cookie returned by getdirentries */
50 } DIR;
51 
52 #define	dirfd(dirp)	((dirp)->dd_fd)
53 
54 #ifndef NULL
55 #define	NULL	0
56 #endif
57 
58 #endif /* _POSIX_SOURCE */
59 
60 #if __STDC__ || c_plusplus
61 extern DIR *opendir(const char *);
62 extern struct dirent *readdir(DIR *);
63 extern void rewinddir(DIR *);
64 extern int closedir(DIR *);
65 #ifndef _POSIX_SOURCE
66 extern long telldir(const DIR *);
67 extern void seekdir(DIR *, long);
68 extern int scandir(const char *, struct direct ***,
69     int (* )(struct direct *), int (* )(void *, void *));
70 extern int alphasort(const void *, const void *);
71 #endif
72 #else
73 extern DIR *opendir();
74 extern struct dirent *readdir();
75 extern void rewinddir();
76 extern int closedir();
77 #ifndef _POSIX_SOURCE
78 extern long telldir();
79 extern void seekdir();
80 extern int scandir();
81 extern int alphasort();
82 #endif
83 #endif
84 #endif /* _DIRENT_ */
85