]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Refactor lib/isc/fsaccess.c
authorMichał Kępień <michal@isc.org>
Fri, 5 Jun 2020 11:19:49 +0000 (13:19 +0200)
committerMichał Kępień <michal@isc.org>
Fri, 5 Jun 2020 11:19:49 +0000 (13:19 +0200)
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.

lib/isc/Makefile.am
lib/isc/fsaccess_common.c [moved from lib/isc/fsaccess.c with 83% similarity]
lib/isc/fsaccess_common_p.h [new file with mode: 0644]
lib/isc/unix/fsaccess.c
lib/isc/win32/fsaccess.c
lib/isc/win32/libisc.vcxproj.filters.in
lib/isc/win32/libisc.vcxproj.in
util/copyrights

index 2d96823e93bcd2898ab2761d5fcb45602d048b60..870083201181aaf54e7156351ac1ccfc5de5cb5b 100644 (file)
@@ -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
similarity index 83%
rename from lib/isc/fsaccess.c
rename to lib/isc/fsaccess_common.c
index 025d4788d701360590694412c23422a7c288b077..565828c7a4496b9e97d5f110b7dd4a91fefb2ae6 100644 (file)
 #include <stdbool.h>
 
 #include <isc/fsaccess.h>
-#include <isc/print.h>
 #include <isc/result.h>
+#include <isc/types.h>
 #include <isc/util.h>
 
-/*!
- * Shorthand.  Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
- * <isc/fsaccess.h>.  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 (file)
index 0000000..4c6b641
--- /dev/null
@@ -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
+ * <isc/fsaccess.h>.  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);
index bade1c2bbf21a6b6594db4975645efb211953e1b..fbc0c5fe54c222a695948177c748e92bf0585dcb 100644 (file)
 #include <errno.h>
 #include <stdbool.h>
 #include <sys/stat.h>
-#include <sys/types.h>
 
-#include "errno2result.h"
+#include <isc/fsaccess.h>
+#include <isc/result.h>
+#include <isc/types.h>
+#include <isc/util.h>
 
-/*! \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);
        }
index f6192da32562d047b1a1f58591765e6e156af56a..96132b0d4c8765951c254f54d40d6eae02d4d787 100644 (file)
 #include <sys/types.h>
 
 #include <isc/file.h>
+#include <isc/fsaccess.h>
+#include <isc/result.h>
 #include <isc/stat.h>
 #include <isc/string.h>
+#include <isc/util.h>
 
+#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);
        }
index 5dcf67ab50d22ca1c129ccb99213d812935cf883..80f17237d74d3d53ed9e897463e00bac4f5a3505 100644 (file)
     <ClInclude Include="..\entropy_private.h">
       <Filter>Win32 Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\fsaccess_common_p.h">
+      <Filter>Win32 Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\openssl_shim.h">
       <Filter>Win32 Header Files</Filter>
     </ClInclude>
     <ClCompile Include="..\entropy.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\fsaccess_common.c">
+      <Filter>Library Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\hash.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
index a695a205e57285a13284252dd2e162b8df93168f..b4fcc52a313187bda35b42bd4292c0f31bce14c5 100644 (file)
@@ -353,6 +353,7 @@ copy InstallFiles ..\Build\Release\
     <ClInclude Include="include\isc\time.h" />
     <ClInclude Include="include\isc\win32os.h" />
     <ClInclude Include="..\entropy_private.h" />
+    <ClInclude Include="..\fsaccess_common_p.h" />
     <ClInclude Include="..\openssl_shim.h" />
     <ClInclude Include="syslog.h" />
     <ClInclude Include="unistd.h" />
@@ -375,6 +376,7 @@ copy InstallFiles ..\Build\Release\
     <ClCompile Include="..\entropy.c" />
     <ClCompile Include="..\error.c" />
     <ClCompile Include="..\event.c" />
+    <ClCompile Include="..\fsaccess_common.c" />
     <ClCompile Include="..\glob.c" />
     <ClCompile Include="..\hash.c" />
     <ClCompile Include="..\heap.c" />
index 6ea48afacbcfdbe0527bd2e3d25fd3ad0f563bc5..e86e83d2b30b330bb683a63fefa45331bdc19519 100644 (file)
 ./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