OSDN Git Service

Ext4utils: Fix unused parameters
authorAndreas Gampe <agampe@google.com>
Thu, 6 Aug 2015 00:16:22 +0000 (17:16 -0700)
committerAndreas Gampe <agampe@google.com>
Thu, 13 Aug 2015 00:53:41 +0000 (17:53 -0700)
Refactor code so that parameters are not unused and the debug code
is always at least checked (and in non-debug cases compiled away).

Bug: 18632512

(cherry picked from commit 7ec740fee7356dd72918c9b9fd0a91276356673b)

Change-Id: I0e1eedae97a6edceb1771e10e6ec82c641ba9c5e

ext4_utils/canned_fs_config.c

index 2165feb..089a8df 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -80,6 +81,8 @@ int load_canned_fs_config(const char* fn) {
        return 0;
 }
 
+static const int kDebugCannedFsConfig = 0;
+
 void canned_fs_config(const char* path, int dir, const char* target_out_path,
                                          unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) {
        Path key;
@@ -94,16 +97,20 @@ void canned_fs_config(const char* path, int dir, const char* target_out_path,
        *mode = p->mode;
        *capabilities = p->capabilities;
 
-#if 0
-       // for debugging, run the built-in fs_config and compare the results.
-
-       unsigned c_uid, c_gid, c_mode;
-       uint64_t c_capabilities;
-       fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities);
-
-       if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid);
-       if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid);
-       if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode);
-       if (c_capabilities != *capabilities) printf("%s capabilities %llx %llx\n", path, *capabilities, c_capabilities);
-#endif
+       if (kDebugCannedFsConfig) {
+               // for debugging, run the built-in fs_config and compare the results.
+
+               unsigned c_uid, c_gid, c_mode;
+               uint64_t c_capabilities;
+               fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities);
+
+               if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid);
+               if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid);
+               if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode);
+               if (c_capabilities != *capabilities)
+                       printf("%s capabilities %" PRIx64 " %" PRIx64 "\n",
+                               path,
+                               *capabilities,
+                               c_capabilities);
+        }
 }