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