Alexandre Julliard : winegcc: Add ARRAY_SIZE macro.

Alexandre Julliard julliard at winehq.org
Mon Sep 23 15:22:34 CDT 2019


Module: wine
Branch: master
Commit: cb010cd6ec17d5310753bc1a02e5d6a407beff3c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=cb010cd6ec17d5310753bc1a02e5d6a407beff3c

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Sep 23 18:53:19 2019 +0200

winegcc: Add ARRAY_SIZE macro.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 tools/winegcc/utils.h   |  2 ++
 tools/winegcc/winegcc.c | 12 ++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/winegcc/utils.h b/tools/winegcc/utils.h
index 6056ee7258..3d6b8f3665 100644
--- a/tools/winegcc/utils.h
+++ b/tools/winegcc/utils.h
@@ -35,6 +35,8 @@
 # endif
 #endif
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 enum target_cpu
 {
     CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 06771262eb..506096795e 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -579,7 +579,7 @@ static char *get_lib_dir( struct options *opts )
     build_len = strlen( build_multiarch );
     target_len = strlen( target_multiarch );
 
-    for (i = 0; i < sizeof(stdlibpath)/sizeof(stdlibpath[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(stdlibpath); i++)
     {
         char *p, *buffer = xmalloc( strlen(root) + strlen(stdlibpath[i]) +
                                     strlen("/arm-linux-gnueabi") + strlen(libwine) + 1 );
@@ -1260,7 +1260,7 @@ static int is_linker_arg(const char* arg)
 	    break;
     }
 
-    for (j = 0; j < sizeof(link_switches)/sizeof(link_switches[0]); j++)
+    for (j = 0; j < ARRAY_SIZE(link_switches); j++)
 	if (strcmp(link_switches[j], arg) == 0) return 1;
 
     return 0;
@@ -1297,7 +1297,7 @@ static int is_mingw_arg(const char* arg)
     };
     unsigned int j;
 
-    for (j = 0; j < sizeof(mingw_switches)/sizeof(mingw_switches[0]); j++)
+    for (j = 0; j < ARRAY_SIZE(mingw_switches); j++)
 	if (strcmp(mingw_switches[j], arg) == 0) return 1;
 
     return 0;
@@ -1315,7 +1315,7 @@ static void parse_target_option( struct options *opts, const char *target )
     if ((p = strchr( spec, '-' )))
     {
         *p++ = 0;
-        for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
+        for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
         {
             if (!strcmp( cpu_names[i].name, spec ))
             {
@@ -1323,7 +1323,7 @@ static void parse_target_option( struct options *opts, const char *target )
                 break;
             }
         }
-        if (i == sizeof(cpu_names)/sizeof(cpu_names[0]))
+        if (i == ARRAY_SIZE(cpu_names))
             error( "Unrecognized CPU '%s'\n", spec );
         platform = p;
         if ((p = strrchr( p, '-' ))) platform = p + 1;
@@ -1339,7 +1339,7 @@ static void parse_target_option( struct options *opts, const char *target )
     /* get the OS part */
 
     opts->target_platform = PLATFORM_UNSPECIFIED;  /* default value */
-    for (i = 0; i < sizeof(platform_names)/sizeof(platform_names[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(platform_names); i++)
     {
         if (!strncmp( platform_names[i].name, platform, strlen(platform_names[i].name) ))
         {




More information about the wine-cvs mailing list