]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Introduce and use ARRAY_SIZE macro
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 3 Feb 2018 09:42:22 +0000 (10:42 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 3 Feb 2018 09:42:22 +0000 (10:42 +0100)
ccache.h
compopt.c
unittest/test_util.c

index 6fdd0d4014b4a227968b769c353ea693085e8211..dec11fa21d720cc2ca80275420b60465c5dd3b44 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -76,6 +76,7 @@ enum stats {
 #define str_endswith(s, suffix) \
        (strlen(s) >= strlen(suffix) \
         && str_eq((s) + strlen(s) - strlen(suffix), (suffix)))
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
 
 // Buffer size for I/O operations. Should be a multiple of 4 KiB.
 #define READ_BUFFER_SIZE 65536
index 89976a4a8068261dd087d4bbb579befddd3aa53d..aab9fe55249886029f928726a94b016cecd1299f 100644 (file)
--- a/compopt.c
+++ b/compopt.c
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2016 Joel Rosdahl
+// Copyright (C) 2010-2018 Joel Rosdahl
 //
 // This program is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by the Free
@@ -113,8 +113,8 @@ find(const char *option)
        struct compopt key;
        key.name = option;
        return bsearch(
-                &key, compopts, sizeof(compopts) / sizeof(compopts[0]),
-                sizeof(compopts[0]), compare_compopts);
+               &key, compopts, ARRAY_SIZE(compopts), sizeof(compopts[0]),
+               compare_compopts);
 }
 
 static const struct compopt *
@@ -123,8 +123,8 @@ find_prefix(const char *option)
        struct compopt key;
        key.name = option;
        return bsearch(
-                &key, compopts, sizeof(compopts) / sizeof(compopts[0]),
-                sizeof(compopts[0]), compare_prefix_compopts);
+               &key, compopts, ARRAY_SIZE(compopts), sizeof(compopts[0]),
+               compare_prefix_compopts);
 }
 
 // Runs fn on the first two characters of option.
@@ -141,7 +141,7 @@ compopt_short(bool (*fn)(const char *), const char *option)
 bool
 compopt_verify_sortedness(void)
 {
-       for (size_t i = 1; i < sizeof(compopts)/sizeof(compopts[0]); i++) {
+       for (size_t i = 1; i < ARRAY_SIZE(compopts); i++) {
                if (strcmp(compopts[i-1].name, compopts[i].name) >= 0) {
                        fprintf(stderr,
                                "compopt_verify_sortedness: %s >= %s\n",
index dca718c34e783631235663218d0d2982d2e2632e..b6c4c2eb8d2d6dcdc238bbf0944d17cbc1e15e8a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2016 Joel Rosdahl
+// Copyright (C) 2010-2018 Joel Rosdahl
 //
 // This program is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by the Free
@@ -193,7 +193,7 @@ TEST(parse_size_with_suffix)
 
        };
 
-       for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) {
+       for (i = 0; i < ARRAY_SIZE(sizes); ++i) {
                CHECKM(parse_size_with_suffix(sizes[i].size, &size), sizes[i].size);
                CHECK_INT_EQ(sizes[i].expected, size);
        }