Merge from vendor branch NETGRAPH:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / gen-unix.h
1 /*
2  * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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: gen-unix.h,v 1.12.12.5 2005/06/09 23:54:29 marka Exp $ */
19
20 /*
21  * This file is responsible for defining two operations that are not
22  * directly portable between Unix-like systems and Windows NT, option
23  * parsing and directory scanning.  It is here because it was decided
24  * that the "gen" build utility was not to depend on libisc.a, so
25  * the functions delcared in isc/commandline.h and isc/dir.h could not
26  * be used.
27  *
28  * The commandline stuff is really just a wrapper around getopt().
29  * The dir stuff was shrunk to fit the needs of gen.c.
30  */
31
32 #ifndef DNS_GEN_UNIX_H
33 #define DNS_GEN_UNIX_H 1
34
35 #include <sys/types.h>          /* Required on some systems for dirent.h. */
36
37 #include <dirent.h>
38 #include <unistd.h>             /* XXXDCL Required for ?. */
39
40 #include <isc/boolean.h>
41 #include <isc/lang.h>
42
43 #ifdef NEED_OPTARG
44 extern char *optarg;
45 #endif
46
47 #define isc_commandline_parse           getopt
48 #define isc_commandline_argument        optarg
49
50 typedef struct {
51         DIR *handle;
52         char *filename;
53 } isc_dir_t;
54
55 ISC_LANG_BEGINDECLS
56
57 static isc_boolean_t
58 start_directory(const char *path, isc_dir_t *dir) {
59         dir->handle = opendir(path);
60
61         if (dir->handle != NULL)
62                 return (ISC_TRUE);
63         else
64                 return (ISC_FALSE);
65
66 }
67
68 static isc_boolean_t
69 next_file(isc_dir_t *dir) {
70         struct dirent *dirent;
71
72         dir->filename = NULL;
73
74         if (dir->handle != NULL) {
75                 dirent = readdir(dir->handle);
76                 if (dirent != NULL)
77                         dir->filename = dirent->d_name;
78         }
79
80         if (dir->filename != NULL)
81                 return (ISC_TRUE);
82         else
83                 return (ISC_FALSE);
84 }
85
86 static void
87 end_directory(isc_dir_t *dir) {
88         if (dir->handle != NULL)
89                 (void)closedir(dir->handle);
90
91         dir->handle = NULL;
92 }
93
94 ISC_LANG_ENDDECLS
95
96 #endif /* DNS_GEN_UNIX_H */