gen-win32.h revision ec5347e2c775f027573ce5648b910361aa926c01
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * copyright notice and this permission notice appear in all copies.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * PERFORMANCE OF THIS SOFTWARE.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * Copyright (c) 1987, 1993, 1994
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * The Regents of the University of California. All rights reserved.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * Redistribution and use in source and binary forms, with or without
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * modification, are permitted provided that the following conditions
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * are met:
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * 1. Redistributions of source code must retain the above copyright
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * notice, this list of conditions and the following disclaimer.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * 2. Redistributions in binary form must reproduce the above copyright
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * notice, this list of conditions and the following disclaimer in the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * documentation and/or other materials provided with the distribution.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * 3. All advertising materials mentioning features or use of this software
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * must display the following acknowledgement:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * This product includes software developed by the University of
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * California, Berkeley and its contributors.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * 4. Neither the name of the University nor the names of its contributors
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * may be used to endorse or promote products derived from this software
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * without specific prior written permission.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * SUCH DAMAGE.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister/* $Id: gen-win32.h,v 1.22 2007/06/18 23:47:40 tbox Exp $ */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister/*! \file
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * \author Principal Authors: Computer Systems Research Group at UC Berkeley
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * \author Principal ISC caretaker: DCL
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
3d2332d68f7d7461a083049be33e0f903c34cc3fMichael Graff
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister/*
a6ad80dd084a217fcfd93c8e4976b6ac7410ccbfEvan Hunt * \note This file was adapted from the NetBSD project's source tree, RCS ID:
a6ad80dd084a217fcfd93c8e4976b6ac7410ccbfEvan Hunt * NetBSD: getopt.c,v 1.15 1999/09/20 04:39:37 lukem Exp
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * The primary change has been to rename items to the ISC namespace
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * and format in the ISC coding style.
1e5fd07d1669ec0c9474f345bc7ca1642dc072dfMark Andrews *
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * This file is responsible for defining two operations that are not
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * directly portable between Unix-like systems and Windows NT, option
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * parsing and directory scanning. It is here because it was decided
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * that the "gen" build utility was not to depend on libisc.a, so
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * the functions delcared in isc/commandline.h and isc/dir.h could not
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * be used.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * The commandline stuff is pretty much a straight copy from the initial
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * isc/commandline.c. The dir stuff was shrunk to fit the needs of gen.c.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff#ifndef DNS_GEN_WIN32_H
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#define DNS_GEN_WIN32_H 1
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington#include <stdio.h>
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington#include <string.h>
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#include <windows.h>
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#include <isc/boolean.h>
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#include <isc/lang.h>
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffint isc_commandline_index = 1; /* Index into parent argv vector. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffint isc_commandline_option; /* Character checked for validity. */
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffchar *isc_commandline_argument; /* Argument associated with option. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffchar *isc_commandline_progname; /* For printing error messages. */
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffisc_boolean_t isc_commandline_errprint = ISC_TRUE; /* Print error messages. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffisc_boolean_t isc_commandline_reset = ISC_TRUE; /* Reset processing. */
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#define BADOPT '?'
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff#define BADARG ':'
7b1ab9e210e1463aca79423f334dcd8156ebc346Brian Wellington#define ENDOPT ""
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David LawrenceISC_LANG_BEGINDECLS
52d06580bd522aa193de65c62e2142ab32f18398James Brister
52d06580bd522aa193de65c62e2142ab32f18398James Brister/*
52d06580bd522aa193de65c62e2142ab32f18398James Brister * getopt --
52d06580bd522aa193de65c62e2142ab32f18398James Brister * Parse argc/argv argument vector.
52d06580bd522aa193de65c62e2142ab32f18398James Brister */
3d2332d68f7d7461a083049be33e0f903c34cc3fMichael Graffint
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrenceisc_commandline_parse(int argc, char * const *argv, const char *options) {
52d06580bd522aa193de65c62e2142ab32f18398James Brister static char *place = ENDOPT;
52d06580bd522aa193de65c62e2142ab32f18398James Brister char *option; /* Index into *options of option. */
52d06580bd522aa193de65c62e2142ab32f18398James Brister
52d06580bd522aa193de65c62e2142ab32f18398James Brister /*
52d06580bd522aa193de65c62e2142ab32f18398James Brister * Update scanning pointer, either because a reset was requested or
52d06580bd522aa193de65c62e2142ab32f18398James Brister * the previous argv was finished.
52d06580bd522aa193de65c62e2142ab32f18398James Brister */
52d06580bd522aa193de65c62e2142ab32f18398James Brister if (isc_commandline_reset || *place == '\0') {
52d06580bd522aa193de65c62e2142ab32f18398James Brister isc_commandline_reset = ISC_FALSE;
52d06580bd522aa193de65c62e2142ab32f18398James Brister
52d06580bd522aa193de65c62e2142ab32f18398James Brister if (isc_commandline_progname == NULL)
52d06580bd522aa193de65c62e2142ab32f18398James Brister isc_commandline_progname = argv[0];
52d06580bd522aa193de65c62e2142ab32f18398James Brister
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (isc_commandline_index >= argc ||
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *(place = argv[isc_commandline_index]) != '-') {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister /*
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Index out of range or points to non-option.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister */
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister place = ENDOPT;
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister return (-1);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister }
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister /*
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Found '--' to signal end of options. Advance
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * index to next argv, the first non-option.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister */
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister isc_commandline_index++;
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister place = ENDOPT;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (-1);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister }
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister }
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister isc_commandline_option = *place++;
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister option = strchr(options, isc_commandline_option);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister /*
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Ensure valid option has been passed as specified by options string.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * '-:' is never a valid command line option because it could not
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * distinguish ':' from the argument specifier in the options string.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister */
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (isc_commandline_option == ':' || option == NULL) {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (*place == '\0')
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister isc_commandline_index++;
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (isc_commandline_errprint && *options != ':')
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister fprintf(stderr, "%s: illegal option -- %c\n",
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister isc_commandline_progname,
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister isc_commandline_option);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister return (BADOPT);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister }
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (*++option != ':') {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option does not take an argument.
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_argument = NULL;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Skip to next argv if at the end of the current argv.
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (*place == '\0')
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister ++isc_commandline_index;
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister } else {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff * Option needs an argument.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (*place != '\0')
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option is in this argv, -D1 style.
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff */
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence isc_commandline_argument = place;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff else if (argc > ++isc_commandline_index)
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option is next argv, -D 1 style.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_argument = argv[isc_commandline_index];
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister else {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Argument needed, but no more argv.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister place = ENDOPT;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Silent failure with "missing argument" return
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff * when ':' starts options string, per historical spec.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (*options == ':')
70be3889746884692aa49939833d624ddd432bf0Mark Andrews return (BADARG);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (isc_commandline_errprint)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister fprintf(stderr,
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence "%s: option requires an argument -- %c\n",
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_progname,
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_option);
f9c862673848361c4361d143ac4c5d60f239d29bBob Halley
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews return (BADOPT);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister }
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff place = ENDOPT;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Point to argv that follows argument.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_index++;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence return (isc_commandline_option);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister}
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Grafftypedef struct {
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff HANDLE handle;
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff WIN32_FIND_DATA find_data;
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff isc_boolean_t first_file;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister char *filename;
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington} isc_dir_t;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristerisc_boolean_t
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristerstart_directory(const char *path, isc_dir_t *dir) {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister char pattern[_MAX_PATH], *p;
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
4e7973990c2aaec391cf307a7e60583331568e01Evan Hunt * Need space for slash-splat and final NUL.
4e7973990c2aaec391cf307a7e60583331568e01Evan Hunt */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (strlen(path) + 3 > sizeof(pattern))
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson return (ISC_FALSE);
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister strcpy(pattern, path);
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister /*
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Append slash (if needed) and splat.
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson */
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff p = pattern + strlen(pattern);
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff if (p != pattern && p[-1] != '\\' && p[-1] != ':')
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *p++ = '\\';
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *p++ = '*';
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister *p++ = '\0';
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister dir->first_file = ISC_TRUE;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister dir->handle = FindFirstFile(pattern, &dir->find_data);
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff if (dir->handle == INVALID_HANDLE_VALUE) {
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff dir->filename = NULL;
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff return (ISC_FALSE);
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff } else {
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson dir->filename = dir->find_data.cFileName;
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff return (ISC_TRUE);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister }
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister}
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristerisc_boolean_t
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristernext_file(isc_dir_t *dir) {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (dir->first_file)
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff dir->first_file = ISC_FALSE;
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister else if (dir->handle != INVALID_HANDLE_VALUE) {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (FindNextFile(dir->handle, &dir->find_data) == TRUE)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister dir->filename = dir->find_data.cFileName;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister else
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister dir->filename = NULL;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister } else
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson dir->filename = NULL;
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff if (dir->filename != NULL)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister return (ISC_TRUE);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister else
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister return (ISC_FALSE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristervoid
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristerend_directory(isc_dir_t *dir) {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (dir->handle != INVALID_HANDLE_VALUE)
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff FindClose(dir->handle);
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister}
4e7973990c2aaec391cf307a7e60583331568e01Evan Hunt
4e7973990c2aaec391cf307a7e60583331568e01Evan HuntISC_LANG_ENDDECLS
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister#endif /* DNS_GEN_WIN32_H */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graff