File: fileutil.h

package info (click to toggle)
afbackup 3.3.6pl4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,872 kB
  • ctags: 3,143
  • sloc: ansic: 44,316; tcl: 4,189; sh: 2,263; csh: 2,077; makefile: 566; sed: 93; perl: 80
file content (240 lines) | stat: -rw-r--r-- 7,603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/****************** Start of $RCSfile: fileutil.h,v $  ****************
*
* $Source: /home/alb/afbackup/afbackup-3.3.6/RCS/fileutil.h,v $
* $Id: fileutil.h,v 1.2 2002/02/27 10:17:11 alb Exp alb $
* $Date: 2002/02/27 10:17:11 $
* $Author: alb $
*
*
******* description ***********************************************
*
*
*
*******************************************************************/

#ifndef	__FILE_UTIL_H
#define	__FILE_UTIL_H	__FILE_UTIL_H

#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <x_types.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>

#ifndef	O_BINARY
#define	O_BINARY	0
#endif

typedef	enum	_x_type	{
  TypeReal64, TypeReal32, TypeInt32, TypeUns32,
  TypeInt16, TypeUns16, TypeUChar, TypeSChar, TypeFlag,
  TypeReal64PTR, TypeReal32PTR, TypeInt32PTR, TypeUns32PTR,
  TypeInt16PTR, TypeUns16PTR, TypeUCharPTR, TypeSCharPTR
}	X_Type;

typedef	struct _param_file_entry {
  void		*entry_ptr;
  Uns32		*num_entries;  
  UChar		*pattern;
  X_Type	type;
} ParamFileEntry;

typedef struct _find_params {
  UChar		**excl_dirs;
  UChar		**names;
  UChar		**excl_names;
  Uns32		options;
  time_t	newer_than;
  time_t	older_than;
  Int32		(*errfunc)(UChar *, void *);
  void		*errfunc_param;
  UChar		*excl_filename;
  UChar		**fstypes_to_search;
  UChar		**fstypes_to_skip;
  UChar		**fstypes_to_prune;
  Flag		*interrupted;
} FindParams;

#define	FIND_NO_DIRS		1
#define	FIND_NO_FILES		(FIND_NO_DIRS << 1)
#define	FIND_NO_SLINKS		(FIND_NO_DIRS << 2)
#define	FIND_NO_CDEVS		(FIND_NO_DIRS << 3)
#define	FIND_NO_BDEVS		(FIND_NO_DIRS << 4)
#define	FIND_NO_FIFOS		(FIND_NO_DIRS << 5)
#define	FIND_NO_SOCKS		(FIND_NO_DIRS << 6)
#define	FIND_FOLLOW_SLINKS	(FIND_NO_DIRS << 7)
#define	FIND_LOCAL_DEV		(FIND_NO_DIRS << 8)
#define	FIND_DEPTH		(FIND_NO_DIRS << 9)
#define	FIND_CMP_CTIME		(FIND_NO_DIRS << 10)

#define	FIND_ONLY_DIRS		(FIND_NO_FILES | FIND_NO_SLINKS	\
				| FIND_NO_CDEVS | FIND_NO_BDEVS \
				| FIND_NO_FIFOS | FIND_NO_SOCKS)

typedef struct _key_value_pair_ {
  UChar		*key;
  UChar		*value;
} KeyValuePair;

#define	KFILE_SORT	1
#define	KFILE_SORTN	(1 << 1)
#define	KFILE_LOCKED	(1 << 10)

#ifdef	__cplusplus
extern	"C"	{
#endif

extern	Int32	save_insert(UChar *, UChar *,
				Int32 (*)(FILE *, void *), void *);
extern	Int32	read_param_file(UChar *, ParamFileEntry *, Int32,
				UChar *, UChar *);
extern	Int32	sscanXValue(UChar *, void *, X_Type, Int32 *);
extern	Int32	fscanXValue(FILE *, void *, X_Type, Int32 *);
extern	UChar	*find_program(UChar *);
extern	Int32	cleanpath(UChar *);
extern	Int32	cleanpath__(UChar *);
extern	UChar	*mkabspath(UChar *, UChar *);
extern	Int32	mkrelpath(UChar *);
extern	UChar	*resolve_path(UChar *, UChar *);
extern	UChar	*resolve_path__(UChar *, UChar *);
extern	Int32	find1(UChar *, FindParams *,
			Int32 (*)(UChar *, void *, struct stat *), void *);
extern	Int32	find(UChar **, FindParams *,
			Int32 (*)(UChar *, void *, struct stat *), void *);
extern	UChar	**fnglob1(UChar *);
extern	UChar	**fnglob(UChar *);
extern	Int32	copy_file(UChar *, UChar *);
extern	UChar	*hidden_filename(UChar *);
extern	Int32	make_dirpath(UChar *, Uns32, uid_t, gid_t);
extern	Int32	kfile_insert(UChar *, UChar *, UChar *, Uns32);
extern	Int32	kfile_delete(UChar *, UChar *, Uns32);
extern	UChar	*kfile_get(UChar *, UChar *, Uns32);
extern	KeyValuePair	*kfile_getall(UChar *, Int32 *, Uns32);
extern	void	kfile_freeall(KeyValuePair *, Int32);
extern	Int32	add_to_int_list_file(UChar *, Int32);
extern	Int32	*get_list_from_int_list_file(UChar *, Int32 *);
extern	UChar	*tmp_name(UChar *);
extern	int	tmp_file(UChar *);
extern	UChar	*check_commands_executable(Flag, UChar *, ...);
extern	Int32	mkbasedir(UChar *, mode_t, uid_t, gid_t);
extern	Int32	mkdirpath(UChar *, mode_t, uid_t, gid_t);

#ifdef	__cplusplus
}
#endif

#ifdef	unix

#define	FN_DIRSEPCHR		'/'
#define	FN_DIRSEPSTR		"/"
#define	FN_CURDIR		"."
#define	FN_PARENTDIR		".."
#define	FN_ISPATH(s)		(strchr((s), FN_DIRSEPCHR))
#define	FN_ISABSPATH(s)		(*(s) == FN_DIRSEPCHR)
#define	FN_LASTDIRDELIM(s)	(strrchr((s), FN_DIRSEPCHR))
#define	FN_BASENAME(s)		(strrchr((s), FN_DIRSEPCHR) ? 		\
				(UChar *) strrchr((s), FN_DIRSEPCHR) + 1 : (s))
#define	FN_STRDBLDIRSEP(s)	(strstr((s), "//"))
#define	FN_STREMPTYDIRSEP(s)	(strstr((s), "/./"))
#define	FN_ISDIRSEP(c)		((c) == FN_DIRSEPCHR)
#define	FN_ISROOTDIR(s)		(FN_ISDIRSEP(*(s)) && ! *((s) + 1))
#define	FN_LEADINGDUMMY(s)	(*(s) == '.' && FN_ISDIRSEP(*((s) + 1)))
#define	FN_TRAILINGDUMMY(s)	(strlen(s) >= 2 &&	\
				*((s) + strlen(s) - 1) == '.' &&	\
				FN_ISDIRSEP(*((s) + strlen(s) - 2)))
#define	FN_FIRSTDIRSEP(s)	(strchr((s), FN_DIRSEPCHR))

#define	ENV_PATHSEPCHR		':'

#define	ESCAPE_CHARACTER	'\\'

#define	NULLFILE		"/dev/null"
#define	FN_TMPDIR		"/tmp"

#endif	/* defined(unix) */

#ifdef	WINDOWS_LIKE

#define	FN_DIRSEPCHR		'\\'
#define	FN_DIRSEPSTR		"\\"
#define	FN_CURDIR		"."
#define	FN_PARENTDIR		".."
#define	FN_ISDIRSEP(c)	((c) == '/' || (c) == '\\')
#define	FN_ISPATH(s)	(strchr((s), '\\') || strchr((s), '/') ||	\
				(isalpha(*(s)) && *((s) + 1) == ':'))
#define	FN_ISABSPATH(s)	(FN_ISDIRSEP(*(s)) ||				\
				(isalpha(*(s)) && *((s) + 1) == ':' &&	\
				FN_ISDIRSEP(*((s) + 2))))
#define	FN_LASTDIRDELIM(s)	(strrchr(s, '/') ? strrchr(s, '/') :	\
				(strrchr(s, '\\') ? strrchr(s, '\\') :	\
				(isalpha(*(s)) && *((s) + 1) == ':') ?	\
				s + 2 : NULL))
#define	FN_BASENAME(s)	(strrchr(s, '/') ? strrchr(s, '/') + 1 :	\
			(strrchr(s, '\\') ? strrchr(s, '\\') + 1 :	\
			(isalpha(*(s)) && *((s) + 1) == ':') ? s + 2 : (s)))
#define	FN_STRDBLDIRSEP(s)						\
		(strstr((s), "//") ? strstr((s), "//") : strstr((s), "\\\\"))
#define	FN_STREMPTYDIRSEP(s)	(strstr((s), "/./") ? strstr((s), "/./") : \
				(strstr((s), "/.\\") ? strstr((s), "/.\\") : \
				(strstr((s), "\\./") ? strstr((s), "\\./") : \
				strstr((s), "\\.\\"))))
#define	FN_ISROOTDIR(s)	((FN_ISDIRSEP(*(s)) && ! *((s) + 1)) ||		\
				(isalpha(*(s)) && *((s) + 1) == ':'	\
				&& FN_ISDIRSEP(*((s) + 2)) && ! *((s) + 3)))
#define	FN_LEADINGDUMMY(s)	(*(s) == '.' && FN_ISDIRSEP(*((s) + 1)))
#define	FN_TRAILINGDUMMY(s)	(strlen(s) >= 2 &&	\
				*((s) + strlen(s) - 1) == '.' &&	\
				FN_ISDIRSEP(*((s) + strlen(s) - 2)))
#define	FN_FIRSTDIRSEP(s)	(strchr((s), '/') ? strchr((s), '/') :	\
					strchr((s), '\\'))

#define	ENV_PATHSEPCHR		';'

#define	ESCAPE_CHARACTER	'\t'	/* don't know, what to do here */

#define	NULLFILE		"nul"
#define	FN_TMPDIR		"c:\\temp"

#endif	/* defined(WINDOWS_LIKE) */

#endif	/* ! __FILE_UTIL_H */

#ifndef	_FN_MATCH_H

#define	_FN_MATCH_H	_FN_MATCH_H

/* Bits set in the FLAGS argument to `fn_match'.  */
#define	GFNM_PATHNAME	(1 << 0) /* No wildcard can ever match `/'.  */
#define	GFNM_NOESCAPE	(1 << 1) /* Backslashes don't quote special chars.  */
#define	GFNM_PERIOD	(1 << 2) /* Leading `.' is matched only explicitly.  */

#define	GFNM_FILE_NAME	GFNM_PATHNAME /* Preferred GNU name.  */
#define	GFNM_LEADING_DIR	(1 << 3) /* Ignore `/...' after a match.  */
#define	GFNM_CASEFOLD	(1 << 4) /* Compare without regard to case.  */

/* Value returned by `fn_match' if STRING does not match PATTERN.  */
#define	GFNM_NOMATCH	1

#ifdef	__cplusplus
extern "C" {
#endif

/* Match STRING against the filename pattern PATTERN,
   returning zero if it matches, GFNM_NOMATCH if not.  */
extern Int32 fn_match(UChar *, UChar *, Int32);

#ifdef	__cplusplus
}
#endif

#if !defined(GFNM_CASEFOLD) && defined(GFNM_IGNORECASE)
#define GFNM_CASEFOLD    GFNM_IGNORECASE
#endif

#endif /* defined(_FN_MATCH_H) */

/************ end of $RCSfile: fileutil.h,v $ ******************/