@matheusbsbs / matheus-bagliano / commits / b4f2a6ac92
Fork 0

Use #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 9, 2006 at 11:58 UTC b4f2a6ac9263d6e9bf3bf9c8abe607cd6def0ee8
5 files changed +5 -7
apply.c
+1 -1
@@ -651,7 +651,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch
651 len = linelen(line, size);
652 if (!len || line[len-1] != '\n')
653 break;
654 - for (i = 0; i < sizeof(optable) / sizeof(optable[0]); i++) {
654 + for (i = 0; i < ARRAY_SIZE(optable); i++) {
655 const struct opentry *p = optable + i;
656 int oplen = strlen(p->str);
657 if (len < oplen || memcmp(p->str, line, oplen))
date.c
+1 -3
@@ -123,8 +123,6 @@ static const struct {
123 { "IDLE", +12, 0, }, /* International Date Line East */
124 };
125
126 -#define NR_TZ (sizeof(timezone_names) / sizeof(timezone_names[0]))
127 -
126 static int match_string(const char *date, const char *str)
127 {
128 int i = 0;
@@ -173,7 +171,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
171 }
172 }
173
176 - for (i = 0; i < NR_TZ; i++) {
174 + for (i = 0; i < ARRAY_SIZE(timezone_names); i++) {
175 int match = match_string(date, timezone_names[i].name);
176 if (match >= 3) {
177 int off = timezone_names[i].offset;
exec_cmd.c
+1 -1
@@ -37,7 +37,7 @@ int execv_git_cmd(const char **argv)
37 getenv("GIT_EXEC_PATH"),
38 builtin_exec_path };
39
40 - for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
40 + for (i = 0; i < ARRAY_SIZE(paths); ++i) {
41 const char *exec_dir = paths[i];
42 const char *tmp;
43
git-compat-util.h
+2
@@ -9,6 +9,8 @@
9 #endif
10 #endif
11
12 +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
13 +
14 #include <unistd.h>
15 #include <stdio.h>
16 #include <sys/stat.h>
git.c
-2
@@ -323,8 +323,6 @@ static int cmd_log(int argc, const char **argv, char **envp)
323 return 0;
324 }
325
326 -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
327 -
326 static void handle_internal_command(int argc, const char **argv, char **envp)
327 {
328 const char *cmd = argv[0];