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