~ubuntu-branches/ubuntu/raring/vice/raring

1 by Zed Pobre
Import upstream version 1.8.0
1
/****************************************************************************
2
3
	Directory.h
4
5
	This file contains the C definitions and declarations for the
6
	Directory.c directory iteration code.
7
8
	This code is intended to be used as a convenient, machine
9
	independent interface to iterate through the contents of a
10
	directory.
11
12
 ****************************************************************************/
13
14
/*
15
 * Author:
16
 * 	Brian Totty
17
 * 	Department of Computer Science
18
 * 	University Of Illinois at Urbana-Champaign
19
 *	1304 West Springfield Avenue
20
 * 	Urbana, IL 61801
21
 * 
22
 * 	totty@cs.uiuc.edu
23
 * 	
24
 */ 
25
26
#ifndef _FWF_DIRECTORY_H_
27
#define _FWF_DIRECTORY_H_
28
1.1.3 by Zed Pobre
Import upstream version 1.19
29
#ifdef MINIXVMD
30
#undef NAME_MAX
31
#define NAME_MAX 60
32
#endif
33
1 by Zed Pobre
Import upstream version 1.8.0
34
#include <stdio.h>
35
#include <string.h>
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
36
37
#ifndef VMS
1 by Zed Pobre
Import upstream version 1.8.0
38
#include <sys/param.h>
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
39
#endif
40
1 by Zed Pobre
Import upstream version 1.8.0
41
#include <sys/types.h>
42
#include <sys/stat.h>
43
1.1.3 by Zed Pobre
Import upstream version 1.19
44
#ifndef PATH_MAX
45
#  ifdef MAX_PATH
46
#    define PATH_MAX MAX_PATH
47
#  else
48
#    define PATH_MAX 1024
49
#  endif
50
#endif
51
52
#ifndef MAXPATHLEN
53
#define MAXPATHLEN PATH_MAX
54
#endif
55
1 by Zed Pobre
Import upstream version 1.8.0
56
#if defined(SYSV) || defined(SVR4)
57
#define getwd(path) getcwd(path, MAXPATHLEN)
58
#endif
59
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
60
#ifdef VMS
61
struct __dirdesc {
62
  unsigned long dd_fd;
63
  long dd_loc;
64
  long dd_size;
65
  long dd_bsize;
66
  long dd_off;
67
  char *dd_buf;
68
  char d_name[256];
69
};
70
71
typedef struct __dirdesc DIR;
72
73
struct dirent {
74
  long d_off;
75
  unsigned long d_fileno;
76
  unsigned short d_reclen;
77
  unsigned short d_namlen;
78
  char d_name[255+1];
79
};
80
81
extern DIR *opendir(char *dirname);
82
extern int closedir(DIR *dirp);
83
extern long telldir(DIR *dirp);
84
extern void seekdir(DIR *dirp, int loc);
85
extern struct dirent *readdir(DIR *dirp);
86
#else
1 by Zed Pobre
Import upstream version 1.8.0
87
#ifndef	NO_DIRENT
88
#include <dirent.h>
89
#else
90
#include <sys/dir.h>
91
#define	dirent direct
92
#endif
1.2.2 by Laszlo Boszormenyi (GCS)
Import upstream version 2.1.dfsg
93
#endif
94
95
#ifdef __NeXT__
96
#ifdef HAVE_SYS_DIR_H
97
#include <sys/dir.h>
98
#endif
99
#define dirent direct
100
#endif
1 by Zed Pobre
Import upstream version 1.8.0
101
102
#define NeedFunctionPrototypes 1
103
1.1.3 by Zed Pobre
Import upstream version 1.19
104
#ifndef HAVE_U_SHORT
105
#define u_short unsigned short
106
#endif
107
1 by Zed Pobre
Import upstream version 1.8.0
108
#ifndef NAME_MAX  /* was _SYS_NAME_MAX, but doesn't compile with `gcc -ansi' */
109
110
#ifndef MAXNAMLEN
111
#define MAX_NAME_LENGTH 1024	/* ettore@comm2000.it 03.14.97 */
112
#else
113
#define	MAX_NAME_LENGTH	MAXNAMLEN
114
#endif
115
#else
116
#define	MAX_NAME_LENGTH	NAME_MAX
117
#endif
118
119
#ifndef TRUE
120
#define TRUE				1
121
#endif
122
123
#ifndef FALSE
124
#define	FALSE				0
125
#endif
126
127
#define	PERM_READ			4
128
#define	PERM_WRITE			2	
129
#define	PERM_EXECUTE			1
130
131
#define	F_TYPE_DIR			1
132
#define	F_TYPE_FILE			2
133
#define	F_TYPE_CHAR_SPECIAL		3
134
#define	F_TYPE_BLOCK_SPECIAL		4
135
#define	F_TYPE_SYM_LINK			5
136
#define	F_TYPE_SOCKET			6
137
#define	F_TYPE_FIFO			7
138
139
/*--------------------------------------------------------------------------*
140
141
            D A T A    T Y P E    A C C E S S    M A C R O S
142
143
 *--------------------------------------------------------------------------*/
144
145
	/* Directory: Directory Iterator */
146
147
#define	DirectoryDir(dp)		((dp)->filep)
148
#define	DirectoryPath(dp)		((dp)->path)
149
150
	/* FileInfo: Information About A File Or Link */
151
152
#define	FileInfoProt(fi)		((fi)->protections)
153
#define FileInfoOrigMode(fi)		((fi)->orig_mode)
154
#define	FileInfoUserID(fi)		((fi)->user_id)
155
#define	FileInfoGroupID(fi)		((fi)->group_id)
156
#define	FileInfoFileSize(fi)		((fi)->size)
157
#define	FileInfoLastAccess(fi)		((fi)->last_access)
158
#define	FileInfoLastModify(fi)		((fi)->last_modify)
159
#define	FileInfoLastStatusChange(fi)	((fi)->last_status_change)
160
161
#define	FIProt(fi)			FileInfoProt(fi)
162
#define FIOrigMode(fi)			FileInfoOrigMode(fi)
163
#define	FIUserID(fi)			FileInfoUserID(fi)
164
#define	FIGroupID(fi)			FileInfoGroupID(fi)
165
#define	FIFileSize(fi)			FileInfoFileSize(fi)
166
#define	FILastAccess(fi)		FileInfoLastAccess(fi)
167
#define	FILastModify(fi)		FileInfoLastModify(fi)
168
#define	FILastStatusChange(fi)		FileInfoLastStatusChange(fi)
169
170
	/* FType: File Type Macros */
171
172
#define	FTypeIsDir(ft)			((ft) == F_TYPE_DIR)
173
#define	FTypeIsFile(ft)			((ft) == F_TYPE_FILE)
174
#define	FTypeIsCharSpecial(ft)		((ft) == F_TYPE_CHAR_SPECIAL)
175
#define	FTypeIsBlockSpecial(ft)		((ft) == F_TYPE_BLOCK_SPECIAL)
176
#define	FTypeIsSymLink(ft)		((ft) == F_TYPE_SYM_LINK)
177
#define	FTypeIsSocket(ft)		((ft) == F_TYPE_SOCKET)
178
#define	FTypeIsFifo(ft)			((ft) == F_TYPE_FIFO)
179
180
	/* DirEntry: Information About A Item In A Directory */
181
182
#define	DirEntryFileName(fi)		((fi)->filename)
183
#define	DirEntryType(fi)		((fi)->file_type)
184
#define	DirEntrySelfInfo(fi)		(&((fi)->self_info))
185
#define	DirEntryActualInfo(fi)		(&((fi)->actual_info))
186
187
#define	DirEntryIsBrokenLink(fi)	((fi)->broken_link)
188
#define	DirEntryIsDirectoryLink(fi)	((fi)->directory_link)
189
#define	DirEntryIsDir(fi)		(FTypeIsDir(DirEntryType(fi)))
190
#define	DirEntryIsFile(fi)		(FTypeIsFile(DirEntryType(fi)))
191
#define	DirEntryIsCharSpecial(fi)	(FTypeIsCharSpecial(DirEntryType(fi)))
192
#define	DirEntryIsBlockSpecial(fi)	(FTypeIsBlockSpecial(DirEntryType(fi)))
193
#define	DirEntryIsSymLink(fi)		(FTypeIsSymLink(DirEntryType(fi)))
194
#define	DirEntryIsSocket(fi)		(FTypeIsSocket(DirEntryType(fi)))
195
#define	DirEntryIsFifo(fi)		(FTypeIsFifo(DirEntryType(fi)))
196
#define	DirEntryLeadsToDir(fi)		(DirEntryIsDir(fi) ||		\
197
					 DirEntryIsDirectoryLink(fi))
198
199
#define	DirEntryProt(d)			FIProt(DirEntrySelfInfo(d))
200
#define DirEntryOrigMode(d)		FIOrigMode(DirEntrySelfInfo(d))
201
#define	DirEntryUserID(d)		FIUserID(DirEntrySelfInfo(d))
202
#define	DirEntryGroupID(d)		FIGroupID(DirEntrySelfInfo(d))
203
#define	DirEntryFileSize(d)		FIFileSize(DirEntrySelfInfo(d))
204
#define	DirEntryLastAccess(d)		FILastAccess(DirEntrySelfInfo(d))
205
#define	DirEntryLastModify(d)		FILastModify(DirEntrySelfInfo(d))
206
#define	DirEntryLastStatusChange(d)	FILastStatusChange(DirEntrySelfInfo(d))
207
208
/*--------------------------------------------------------------------------*
209
210
             D A T A    T Y P E    D E F I N I T I O N S
211
212
 *--------------------------------------------------------------------------*/
213
214
	/* Directory: Directory Iterator */
215
216
typedef struct
217
{
218
	DIR *filep;
219
	char path[MAXPATHLEN + 2];
220
} DIRECTORY;
221
222
typedef DIRECTORY Directory;
223
224
	/* FileInfo: Information About A File Or Link */
225
226
typedef struct
227
{
228
	short protections;
229
	short orig_mode;
230
	short user_id;
231
	short group_id;
232
	long size;
233
	time_t last_access;
234
	time_t last_modify;
235
	time_t last_status_change;
236
} FILE_INFO;
237
238
typedef	FILE_INFO FileInfo;
239
240
	/* DirEntry: Information About A Item In A Directory */
241
242
typedef struct
243
{
244
	char filename[MAX_NAME_LENGTH + 1];
245
	short file_type;
246
	short broken_link;
247
	short directory_link;
248
	FileInfo self_info;
249
	FileInfo actual_info;
250
} DIR_ENTRY;
251
252
typedef DIR_ENTRY DirEntry;
253
254
/*--------------------------------------------------------------------------*
255
256
        L O W    L E V E L    D I R E C T O R Y    I N T E R F A C E
257
258
 *--------------------------------------------------------------------------*/
259
260
#if (!NeedFunctionPrototypes)
261
262
int	DirectoryOpen();
263
void	DirectoryRestart();
264
void	DirectoryClose();
265
long	DirectoryTellPosition();
266
void	DirectorySetPosition();
267
int	DirectoryReadNextEntry();
268
char *	DirectoryPathExpand();
269
void	DirEntryDump();
270
271
#else
272
273
int	DirectoryOpen(char *dir_name, Directory *dp);
274
void	DirectoryRestart(Directory *dp);
275
void	DirectoryClose(Directory *dp);
276
long	DirectoryTellPosition(Directory *dp);
277
void	DirectorySetPosition(Directory *dp, long int pos);
278
int	DirectoryReadNextEntry(Directory *dp, DirEntry *de);
279
char *	DirectoryPathExpand(char *old_path, char *new_path);
280
void	DirEntryDump(FILE *fp, DirEntry *de);
281
282
#endif
283
284
#endif
285
286