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