From f24b26188d466a090a85f56681d797f22bf1122d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 25 Jan 2022 10:43:41 +0100 Subject: [PATCH] Merge lib/dns/gen.h contents to lib/dns/gen.c Formerly, the gen.h header contained a compatibility layer between Win32 and POSIX platforms. Since we have already dropped the Win32 build, we can merged gen.h into gen.c as the header file is not used elsewhere. --- lib/dns/Makefile.am | 5 +-- lib/dns/gen.c | 74 ++++++++++++++++++++++++++----- lib/dns/gen.h | 103 -------------------------------------------- 3 files changed, 65 insertions(+), 117 deletions(-) delete mode 100644 lib/dns/gen.h diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index d16dd51764..bce920c99f 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -19,13 +19,12 @@ CLEANFILES = \ $(nodist_libdns_la_SOURCES) \ gen$(BUILD_EXEEXT) -gen$(BUILD_EXEEXT): gen.c gen.h - $(CC_FOR_BUILD) -g -I. $(GEN_NEED_OPTARG) $(srcdir)/gen.c -o $@ +gen$(BUILD_EXEEXT): gen.c + $(CC_FOR_BUILD) -g -I. $(srcdir)/gen.c -o $@ EXTRA_DIST = \ dnstap.proto \ gen.c \ - gen.h \ rdata/* include/dns/enumtype.h: gen Makefile diff --git a/lib/dns/gen.c b/lib/dns/gen.c index ddc9a75b9c..e96a0adafb 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -14,21 +14,22 @@ /*! \file */ #include +#include #include #include +#include #include #include #include #include #include #include +#include #ifndef PATH_MAX #define PATH_MAX 1024 #endif /* ifndef PATH_MAX */ -#include "gen.h" - #ifndef ULLONG_MAX #define ULLONG_MAX (~0ULL) #endif /* ifndef ULLONG_MAX */ @@ -157,6 +158,11 @@ static struct ttnam { static int maxtype = -1; +typedef struct { + DIR *handle; + char *filename; +} isc_dir_t; + static char * upper(char *); static char * @@ -171,6 +177,54 @@ sd(unsigned int, const char *, const char *, char); static void insert_into_typenames(int, const char *, const char *); +static bool +start_directory(const char *path, isc_dir_t *dir) { + dir->handle = opendir(path); + + if (dir->handle != NULL) { + return (true); + } else { + return (false); + } +} + +static bool +next_file(isc_dir_t *dir) { + struct dirent *dirent; + + dir->filename = NULL; + + if (dir->handle != NULL) { + errno = 0; + dirent = readdir(dir->handle); + if (dirent != NULL) { + dir->filename = dirent->d_name; + } else { + if (errno != 0) { + fprintf(stderr, + "Error: reading directory: %s\n", + strerror(errno)); + exit(1); + } + } + } + + if (dir->filename != NULL) { + return (true); + } else { + return (false); + } +} + +static void +end_directory(isc_dir_t *dir) { + if (dir->handle != NULL) { + (void)closedir(dir->handle); + } + + dir->handle = NULL; +} + /*% * If you use more than 10 of these in, say, a printf(), you'll have problems. */ @@ -560,7 +614,7 @@ main(int argc, char **argv) { } srcdir[0] = '\0'; - while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1) { + while ((c = getopt(argc, argv, "cdits:F:P:S:")) != -1) { switch (c) { case 'c': code = 0; @@ -595,26 +649,24 @@ main(int argc, char **argv) { filetype = 'h'; break; case 's': - if (strlen(isc_commandline_argument) > + if (strlen(optarg) > PATH_MAX - 2 * TYPECLASSLEN - sizeof("/rdata/_65535_65535")) { - fprintf(stderr, "\"%s\" too long\n", - isc_commandline_argument); + fprintf(stderr, "\"%s\" too long\n", optarg); exit(1); } - n = snprintf(srcdir, sizeof(srcdir), "%s/", - isc_commandline_argument); + n = snprintf(srcdir, sizeof(srcdir), "%s/", optarg); INSIST(n > 0 && (unsigned)n < sizeof(srcdir)); break; case 'F': - file = isc_commandline_argument; + file = optarg; break; case 'P': - prefix = isc_commandline_argument; + prefix = optarg; break; case 'S': - suffix = isc_commandline_argument; + suffix = optarg; break; case '?': exit(1); diff --git a/lib/dns/gen.h b/lib/dns/gen.h deleted file mode 100644 index 1f676ca9d3..0000000000 --- a/lib/dns/gen.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * SPDX-License-Identifier: MPL-2.0 - * - * 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 https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -/*! \file - * \brief - * 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 - * the functions declared in isc/commandline.h and isc/dir.h could not - * be used. - * - * The commandline stuff is really just a wrapper around getopt(). - * The dir stuff was shrunk to fit the needs of gen.c. - */ - -#pragma once - -#include -#include -#include -#include -#include /* Required on some systems for dirent.h. */ -#include /* XXXDCL Required for ?. */ - -#ifdef __cplusplus -#define ISC_LANG_BEGINDECLS extern "C" { -#define ISC_LANG_ENDDECLS } -#else /* ifdef __cplusplus */ -#define ISC_LANG_BEGINDECLS -#define ISC_LANG_ENDDECLS -#endif /* ifdef __cplusplus */ - -#ifdef NEED_OPTARG -extern char *optarg; -#endif /* ifdef NEED_OPTARG */ - -#define isc_commandline_parse getopt -#define isc_commandline_argument optarg - -typedef struct { - DIR *handle; - char *filename; -} isc_dir_t; - -ISC_LANG_BEGINDECLS - -static bool -start_directory(const char *path, isc_dir_t *dir) { - dir->handle = opendir(path); - - if (dir->handle != NULL) { - return (true); - } else { - return (false); - } -} - -static bool -next_file(isc_dir_t *dir) { - struct dirent *dirent; - - dir->filename = NULL; - - if (dir->handle != NULL) { - errno = 0; - dirent = readdir(dir->handle); - if (dirent != NULL) { - dir->filename = dirent->d_name; - } else { - if (errno != 0) { - exit(1); - } - } - } - - if (dir->filename != NULL) { - return (true); - } else { - return (false); - } -} - -static void -end_directory(isc_dir_t *dir) { - if (dir->handle != NULL) { - (void)closedir(dir->handle); - } - - dir->handle = NULL; -} - -ISC_LANG_ENDDECLS