From: Michał Kępień Date: Fri, 5 Jun 2020 11:19:49 +0000 (+0200) Subject: Refactor lib/isc/fsaccess.c X-Git-Tag: v9.17.2~11^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3cfdb96706888301b65eb27746acb3ac9c6aa23;p=thirdparty%2Fbind9.git Refactor lib/isc/fsaccess.c Turn the static check_bad_bits() function used by both Unix and Windows systems into a "private" function and extract the "private" parts of lib/isc/fsaccess.c to lib/isc/fsaccess_common_p.h. Instead of including lib/isc/fsaccess.c from lib/isc/{unix,win32}/fsaccess.c, make the former an independent C source file. Rename lib/isc/fsaccess.c to lib/isc/fsaccess_common.c to prevent build issues on Windows caused by multiple source files (lib/isc/fsaccess.c, lib/isc/win32/fsaccess.c) being compiled into the same object file. These changes improve consistency with the way "private" functions and macros are treated elsewhere in the source tree. --- diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 2d96823e93b..87008320118 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -163,6 +163,7 @@ libisc_la_SOURCES = \ entropy.c \ error.c \ event.c \ + fsaccess_common.c \ glob.c \ hash.c \ hp.c \ @@ -211,6 +212,7 @@ libisc_la_SOURCES = \ pthreads/mutex.c \ pthreads/thread.c \ entropy_private.h \ + fsaccess_common_p.h \ mem_p.h \ task_p.h \ timer_p.h diff --git a/lib/isc/fsaccess.c b/lib/isc/fsaccess_common.c similarity index 83% rename from lib/isc/fsaccess.c rename to lib/isc/fsaccess_common.c index 025d4788d70..565828c7a44 100644 --- a/lib/isc/fsaccess.c +++ b/lib/isc/fsaccess_common.c @@ -16,18 +16,11 @@ #include #include -#include #include +#include #include -/*! - * Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in - * . Could check consistency with sizeof(isc_fsaccess_t) - * and the number of bits in each function. - */ -#define STEP (ISC__FSACCESS_PERMISSIONBITS) -#define GROUP (STEP) -#define OTHER (STEP * 2) +#include "fsaccess_common_p.h" void isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) { @@ -65,8 +58,8 @@ isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) { } } -static isc_result_t -check_bad_bits(isc_fsaccess_t access, bool is_dir) { +isc_result_t +isc__fsaccess_check_bad_bits(isc_fsaccess_t access, bool is_dir) { isc_fsaccess_t bits; /* diff --git a/lib/isc/fsaccess_common_p.h b/lib/isc/fsaccess_common_p.h new file mode 100644 index 00000000000..4c6b641ca1d --- /dev/null +++ b/lib/isc/fsaccess_common_p.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +/*! + * Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in + * . Could check consistency with sizeof(isc_fsaccess_t) + * and the number of bits in each function. + */ +#define STEP (ISC__FSACCESS_PERMISSIONBITS) +#define GROUP (STEP) +#define OTHER (STEP * 2) + +isc_result_t +isc__fsaccess_check_bad_bits(isc_fsaccess_t access, bool is_dir); diff --git a/lib/isc/unix/fsaccess.c b/lib/isc/unix/fsaccess.c index bade1c2bbf2..fbc0c5fe54c 100644 --- a/lib/isc/unix/fsaccess.c +++ b/lib/isc/unix/fsaccess.c @@ -12,15 +12,14 @@ #include #include #include -#include -#include "errno2result.h" +#include +#include +#include +#include -/*! \file - * \brief - * The OS-independent part of the API is in lib/isc. - */ -#include "../fsaccess.c" +#include "../fsaccess_common_p.h" +#include "errno2result.h" isc_result_t isc_fsaccess_set(const char *path, isc_fsaccess_t access) { @@ -40,7 +39,7 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) { return (ISC_R_INVALIDFILE); } - result = check_bad_bits(access, is_dir); + result = isc__fsaccess_check_bad_bits(access, is_dir); if (result != ISC_R_SUCCESS) { return (result); } diff --git a/lib/isc/win32/fsaccess.c b/lib/isc/win32/fsaccess.c index f6192da3256..96132b0d4c8 100644 --- a/lib/isc/win32/fsaccess.c +++ b/lib/isc/win32/fsaccess.c @@ -27,16 +27,15 @@ #include #include +#include +#include #include #include +#include +#include "../fsaccess_common_p.h" #include "errno2result.h" -/* - * The OS-independent part of the API is in lib/isc. - */ -#include "../fsaccess.c" - /* Store the user account name locally */ static char username[255] = "\0"; static DWORD namelen = 0; @@ -323,7 +322,7 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) { return (ISC_R_INVALIDFILE); } - result = check_bad_bits(access, is_dir); + result = isc__fsaccess_check_bad_bits(access, is_dir); if (result != ISC_R_SUCCESS) { return (result); } diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in index 5dcf67ab50d..80f17237d74 100644 --- a/lib/isc/win32/libisc.vcxproj.filters.in +++ b/lib/isc/win32/libisc.vcxproj.filters.in @@ -349,6 +349,9 @@ Win32 Header Files + + Win32 Header Files + Win32 Header Files @@ -488,6 +491,9 @@ Library Source Files + + Library Source Files + Library Source Files diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index a695a205e57..b4fcc52a313 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -353,6 +353,7 @@ copy InstallFiles ..\Build\Release\ + @@ -375,6 +376,7 @@ copy InstallFiles ..\Build\Release\ + diff --git a/util/copyrights b/util/copyrights index 6ea48afacbc..e86e83d2b30 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1751,7 +1751,8 @@ ./lib/isc/entropy_private.h C 2018,2019,2020 ./lib/isc/error.c C 1998,1999,2000,2001,2004,2005,2007,2015,2016,2018,2019,2020 ./lib/isc/event.c C 1998,1999,2000,2001,2004,2005,2007,2014,2016,2017,2018,2019,2020 -./lib/isc/fsaccess.c C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020 +./lib/isc/fsaccess_common.c C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020 +./lib/isc/fsaccess_common_p.h C 2000,2001,2004,2005,2007,2016,2017,2018,2019,2020 ./lib/isc/glob.c C 2020 ./lib/isc/hash.c C 2003,2004,2005,2006,2007,2009,2013,2014,2015,2016,2017,2018,2019,2020 ./lib/isc/heap.c C 1997,1998,1999,2000,2001,2004,2005,2006,2007,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020