1/*	$NetBSD: glob.c,v 1.2 2024/02/21 22:52:28 christos Exp $	*/
2
3/*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16#include <errno.h>
17#include <glob.h>
18#include <stdio.h>
19#include <string.h>
20
21#include <isc/errno.h>
22#include <isc/glob.h>
23#include <isc/print.h>
24#include <isc/result.h>
25#include <isc/types.h>
26#include <isc/util.h>
27
28isc_result_t
29isc_glob(const char *pattern, glob_t *pglob) {
30	REQUIRE(pattern != NULL);
31	REQUIRE(*pattern != '\0');
32	REQUIRE(pglob != NULL);
33
34	int rc = glob(pattern, GLOB_ERR, NULL, pglob);
35
36	switch (rc) {
37	case 0:
38		return (ISC_R_SUCCESS);
39
40	case GLOB_NOMATCH:
41		return (ISC_R_FILENOTFOUND);
42
43	case GLOB_NOSPACE:
44		return (ISC_R_NOMEMORY);
45
46	default:
47		return (errno != 0 ? isc_errno_toresult(errno) : ISC_R_IOERROR);
48	}
49}
50
51void
52isc_globfree(glob_t *pglob) {
53	REQUIRE(pglob != NULL);
54	globfree(pglob);
55}
56