1999-10-31 18:42:01 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-10-31 18:42:01 +00:00
|
|
|
*/
|
1999-10-08 22:57:20 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file
|
|
|
|
* \brief
|
1999-10-08 22:57:20 +00:00
|
|
|
* This file is responsible for defining two operations that are not
|
|
|
|
* directly portable between Unix-like systems and Windows NT, option
|
|
|
|
* parsing and directory scanning. It is here because it was decided
|
|
|
|
* that the "gen" build utility was not to depend on libisc.a, so
|
2009-01-17 14:45:17 +00:00
|
|
|
* the functions declared in isc/commandline.h and isc/dir.h could not
|
1999-10-08 22:57:20 +00:00
|
|
|
* be used.
|
|
|
|
*
|
|
|
|
* The commandline stuff is really just a wrapper around getopt().
|
|
|
|
* The dir stuff was shrunk to fit the needs of gen.c.
|
|
|
|
*/
|
|
|
|
|
2000-04-29 02:02:38 +00:00
|
|
|
#ifndef DNS_GEN_UNIX_H
|
|
|
|
#define DNS_GEN_UNIX_H 1
|
|
|
|
|
1999-10-08 22:57:20 +00:00
|
|
|
#include <dirent.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <errno.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2019-05-21 17:56:58 +00:00
|
|
|
#include <stdlib.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <unistd.h> /* XXXDCL Required for ?. */
|
1999-10-08 22:57:20 +00:00
|
|
|
|
2000-05-01 17:59:10 +00:00
|
|
|
#include <isc/lang.h>
|
1999-10-08 22:57:20 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sys/types.h> /* Required on some systems for dirent.h. */
|
|
|
|
|
2005-06-08 02:09:18 +00:00
|
|
|
#ifdef NEED_OPTARG
|
|
|
|
extern char *optarg;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef NEED_OPTARG */
|
2005-06-08 02:09:18 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define isc_commandline_parse getopt
|
2020-02-12 13:59:18 +01:00
|
|
|
#define isc_commandline_argument optarg
|
1999-10-08 22:57:20 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2020-02-14 08:14:03 +01:00
|
|
|
DIR *handle;
|
1999-10-08 22:57:20 +00:00
|
|
|
char *filename;
|
|
|
|
} isc_dir_t;
|
|
|
|
|
2000-05-01 17:59:10 +00:00
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
start_directory(const char *path, isc_dir_t *dir) {
|
1999-10-08 22:57:20 +00:00
|
|
|
dir->handle = opendir(path);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dir->handle != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
next_file(isc_dir_t *dir) {
|
1999-10-08 22:57:20 +00:00
|
|
|
struct dirent *dirent;
|
|
|
|
|
|
|
|
dir->filename = NULL;
|
|
|
|
|
|
|
|
if (dir->handle != NULL) {
|
2019-05-21 17:56:58 +00:00
|
|
|
errno = 0;
|
1999-10-08 22:57:20 +00:00
|
|
|
dirent = readdir(dir->handle);
|
2019-05-21 17:56:58 +00:00
|
|
|
if (dirent != NULL) {
|
1999-10-08 22:57:20 +00:00
|
|
|
dir->filename = dirent->d_name;
|
2019-05-21 17:56:58 +00:00
|
|
|
} else {
|
|
|
|
if (errno != 0) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dir->filename != NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
end_directory(isc_dir_t *dir) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dir->handle != NULL) {
|
2001-11-30 01:59:49 +00:00
|
|
|
(void)closedir(dir->handle);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
|
|
|
|
dir->handle = NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-01 17:59:10 +00:00
|
|
|
ISC_LANG_ENDDECLS
|
|
|
|
|
2000-04-29 02:02:38 +00:00
|
|
|
#endif /* DNS_GEN_UNIX_H */
|