1 /*	$NetBSD: dir.h,v 1.4 2014/12/10 04:38:01 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1999-2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: dir.h,v 1.21 2007/06/19 23:47:19 tbox Exp  */
21 
22 /* Principal Authors: DCL */
23 
24 #ifndef ISC_DIR_H
25 #define ISC_DIR_H 1
26 
27 /*! \file */
28 
29 #include <sys/types.h>		/* Required on some systems. */
30 #include <dirent.h>
31 
32 #include <isc/lang.h>
33 #include <isc/result.h>
34 
35 #define ISC_DIR_NAMEMAX 256
36 #define ISC_DIR_PATHMAX 1024
37 
38 /*% Directory Entry */
39 typedef struct isc_direntry {
40 	/*!
41 	 * Ideally, this should be NAME_MAX, but AIX does not define it by
42 	 * default and dynamically allocating the space based on pathconf()
43 	 * complicates things undesirably, as does adding special conditionals
44 	 * just for AIX.  So a comfortably sized buffer is chosen instead.
45 	 */
46 	char 		name[ISC_DIR_NAMEMAX];
47 	unsigned int	length;
48 } isc_direntry_t;
49 
50 /*% Directory */
51 typedef struct isc_dir {
52 	unsigned int	magic;
53 	/*!
54 	 * As with isc_direntry_t->name, making this "right" for all systems
55 	 * is slightly problematic because AIX does not define PATH_MAX.
56 	 */
57 	char		dirname[ISC_DIR_PATHMAX];
58 	isc_direntry_t	entry;
59 	DIR *		handle;
60 } isc_dir_t;
61 
62 ISC_LANG_BEGINDECLS
63 
64 void
65 isc_dir_init(isc_dir_t *dir);
66 
67 isc_result_t
68 isc_dir_open(isc_dir_t *dir, const char *dirname);
69 
70 isc_result_t
71 isc_dir_read(isc_dir_t *dir);
72 
73 isc_result_t
74 isc_dir_reset(isc_dir_t *dir);
75 
76 void
77 isc_dir_close(isc_dir_t *dir);
78 
79 isc_result_t
80 isc_dir_chdir(const char *dirname);
81 
82 isc_result_t
83 isc_dir_chroot(const char *dirname);
84 
85 isc_result_t
86 isc_dir_createunique(char *templet);
87 /*!<
88  * Use a templet (such as from isc_file_mktemplate()) to create a uniquely
89  * named, empty directory.  The templet string is modified in place.
90  * If result == ISC_R_SUCCESS, it is the name of the directory that was
91  * created.
92  */
93 
94 ISC_LANG_ENDDECLS
95 
96 #endif /* ISC_DIR_H */
97