Commit 5cc33084 authored by Matthijs Mekking's avatar Matthijs Mekking 🏡

Make clang-format happy

parent 3275e784
Pipeline #35002 passed with stages
in 32 minutes and 8 seconds
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
* information regarding copyright ownership. * information regarding copyright ownership.
*/ */
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <isc/errno.h> #include <isc/errno.h>
#include <isc/glob.h> #include <isc/glob.h>
...@@ -26,11 +26,12 @@ ...@@ -26,11 +26,12 @@
#include <stdlib.h> #include <stdlib.h>
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1
#include <windows.h> #include <windows.h>
#include <isc/list.h> #include <isc/list.h>
#define GLOB_WIN_IMPL 1 #define GLOB_WIN_IMPL 1
#define GLOB_ERR 0x0004 /* Return on error. */ #define GLOB_ERR 0x0004 /* Return on error. */
#define GLOB_NOSPACE (-1) #define GLOB_NOSPACE (-1)
#define GLOB_NOMATCH (-3) #define GLOB_NOMATCH (-3)
/* custom glob implementation for windows */ /* custom glob implementation for windows */
static int static int
...@@ -52,19 +53,18 @@ isc_glob(const char *pattern, glob_t *pglob) { ...@@ -52,19 +53,18 @@ isc_glob(const char *pattern, glob_t *pglob) {
int rc = glob(pattern, GLOB_ERR, NULL, pglob); int rc = glob(pattern, GLOB_ERR, NULL, pglob);
switch (rc) { switch (rc) {
case 0: case 0:
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
case GLOB_NOMATCH: case GLOB_NOMATCH:
return (ISC_R_FILENOTFOUND); return (ISC_R_FILENOTFOUND);
case GLOB_NOSPACE: case GLOB_NOSPACE:
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
default: default:
return (errno != 0 ? isc_errno_toresult(errno) : ISC_R_IOERROR); return (errno != 0 ? isc_errno_toresult(errno) : ISC_R_IOERROR);
} }
} }
void void
...@@ -103,12 +103,8 @@ map_error(DWORD win_err_code) { ...@@ -103,12 +103,8 @@ map_error(DWORD win_err_code) {
/* add file in directory dir, that matches glob expression /* add file in directory dir, that matches glob expression
* provided in function glob(), to the linked list fl */ * provided in function glob(), to the linked list fl */
static int static int
append_file(isc_mem_t *mctx, append_file(isc_mem_t *mctx, file_list_t *fl, const char *dir, const char *file,
file_list_t *fl, size_t full_path_len) {
const char *dir,
const char *file,
size_t full_path_len)
{
file_path_t *fp = isc_mem_get(mctx, sizeof(file_path_t)); file_path_t *fp = isc_mem_get(mctx, sizeof(file_path_t));
fp->path = isc_mem_get(mctx, full_path_len + 1); fp->path = isc_mem_get(mctx, full_path_len + 1);
_snprintf(fp->path, full_path_len + 1, "%s%s", dir, file); _snprintf(fp->path, full_path_len + 1, "%s%s", dir, file);
...@@ -126,7 +122,8 @@ path_cmp(const void *path1, const void *path2) { ...@@ -126,7 +122,8 @@ path_cmp(const void *path1, const void *path2) {
static int static int
glob(const char *pattern, int flags, void *unused, glob_t *pglob) { glob(const char *pattern, int flags, void *unused, glob_t *pglob) {
char path[MAX_PATH]; char path[MAX_PATH];
WIN32_FIND_DATAA find_data;; WIN32_FIND_DATAA find_data;
;
HANDLE hnd; HANDLE hnd;
REQUIRE(pattern != NULL); REQUIRE(pattern != NULL);
...@@ -153,7 +150,8 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) { ...@@ -153,7 +150,8 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) {
// strip filename from path. // strip filename from path.
size_t dir_len = strlen(path); size_t dir_len = strlen(path);
while (dir_len > 0 && path[dir_len - 1] != '/' && path[dir_len - 1] != '\\') { while (dir_len > 0 && path[dir_len - 1] != '/' &&
path[dir_len - 1] != '\\') {
dir_len--; dir_len--;
} }
...@@ -173,18 +171,16 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) { ...@@ -173,18 +171,16 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) {
goto fail; goto fail;
} }
append_file(pglob->mctx, append_file(pglob->mctx, (file_list_t *)pglob->reserved, path,
(file_list_t *)pglob->reserved, find_data.cFileName, full_path_len);
path,
find_data.cFileName,
full_path_len);
entries++; entries++;
} while (FindNextFileA(hnd, &find_data)); } while (FindNextFileA(hnd, &find_data));
FindClose(hnd); FindClose(hnd);
pglob->gl_pathv = isc_mem_get(pglob->mctx, (entries + 1) * sizeof(char*)); pglob->gl_pathv = isc_mem_get(pglob->mctx,
(entries + 1) * sizeof(char *));
pglob->gl_pathv[entries] = NULL; pglob->gl_pathv[entries] = NULL;
pglob->gl_pathc = entries; pglob->gl_pathc = entries;
...@@ -192,11 +188,12 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) { ...@@ -192,11 +188,12 @@ glob(const char *pattern, int flags, void *unused, glob_t *pglob) {
size_t e = 0; size_t e = 0;
file_path_t *fp; file_path_t *fp;
for (fp = ISC_LIST_HEAD(*fl); fp != NULL; fp = ISC_LIST_NEXT(fp, link)) { for (fp = ISC_LIST_HEAD(*fl); fp != NULL; fp = ISC_LIST_NEXT(fp, link))
{
pglob->gl_pathv[e++] = fp->path; pglob->gl_pathv[e++] = fp->path;
} }
qsort(pglob->gl_pathv, pglob->gl_pathc, sizeof(char*), path_cmp); qsort(pglob->gl_pathv, pglob->gl_pathc, sizeof(char *), path_cmp);
return (0); return (0);
...@@ -213,14 +210,13 @@ fail: ...@@ -213,14 +210,13 @@ fail:
} }
void void
globfree(glob_t* pglob) { globfree(glob_t *pglob) {
REQUIRE(pglob != NULL); REQUIRE(pglob != NULL);
REQUIRE(pglob->mctx != NULL); REQUIRE(pglob->mctx != NULL);
/* first free memory used by char ** gl_pathv */ /* first free memory used by char ** gl_pathv */
if (pglob->gl_pathv) { if (pglob->gl_pathv) {
isc_mem_put(pglob->mctx, isc_mem_put(pglob->mctx, pglob->gl_pathv,
pglob->gl_pathv,
(pglob->gl_pathc + 1) * sizeof(char *)); (pglob->gl_pathc + 1) * sizeof(char *));
pglob->gl_pathv = NULL; pglob->gl_pathv = NULL;
} }
......
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
#include <glob.h> #include <glob.h>
#else #else
#include <stddef.h> #include <stddef.h>
#include <isc/mem.h> #include <isc/mem.h>
typedef struct { typedef struct {
size_t gl_pathc; size_t gl_pathc;
char **gl_pathv; char ** gl_pathv;
isc_mem_t *mctx; isc_mem_t *mctx;
void *reserved; void * reserved;
} glob_t; } glob_t;
#endif #endif
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
/*! \file */ /*! \file */
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <isc/buffer.h> #include <isc/buffer.h>
#include <isc/dir.h> #include <isc/dir.h>
...@@ -2395,11 +2395,13 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) { ...@@ -2395,11 +2395,13 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
/* Allow include to specify a pattern that follows /* Allow include to specify a pattern that follows
* the same rules as the shell e.g "/path/zone*.conf" */ * the same rules as the shell e.g "/path/zone*.conf" */
glob_t glob_obj; glob_t glob_obj;
CHECK(isc_glob(includename->value.string.base, &glob_obj)); CHECK(isc_glob(includename->value.string.base,
&glob_obj));
cfg_obj_destroy(pctx, &includename); cfg_obj_destroy(pctx, &includename);
for (size_t i = 0; i < glob_obj.gl_pathc; ++i) { for (size_t i = 0; i < glob_obj.gl_pathc; ++i) {
CHECK(parser_openfile(pctx, glob_obj.gl_pathv[i])); CHECK(parser_openfile(pctx,
glob_obj.gl_pathv[i]));
} }
isc_globfree(&glob_obj); isc_globfree(&glob_obj);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment