Skip to content

Commit

Permalink
Use #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Mar 9, 2006
1 parent 7bd7f28 commit b4f2a6a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch
len = linelen(line, size);
if (!len || line[len-1] != '\n')
break;
for (i = 0; i < sizeof(optable) / sizeof(optable[0]); i++) {
for (i = 0; i < ARRAY_SIZE(optable); i++) {
const struct opentry *p = optable + i;
int oplen = strlen(p->str);
if (len < oplen || memcmp(p->str, line, oplen))
Expand Down
4 changes: 1 addition & 3 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ static const struct {
{ "IDLE", +12, 0, }, /* International Date Line East */
};

#define NR_TZ (sizeof(timezone_names) / sizeof(timezone_names[0]))

static int match_string(const char *date, const char *str)
{
int i = 0;
Expand Down Expand Up @@ -173,7 +171,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
}
}

for (i = 0; i < NR_TZ; i++) {
for (i = 0; i < ARRAY_SIZE(timezone_names); i++) {
int match = match_string(date, timezone_names[i].name);
if (match >= 3) {
int off = timezone_names[i].offset;
Expand Down
2 changes: 1 addition & 1 deletion exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int execv_git_cmd(const char **argv)
getenv("GIT_EXEC_PATH"),
builtin_exec_path };

for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
for (i = 0; i < ARRAY_SIZE(paths); ++i) {
const char *exec_dir = paths[i];
const char *tmp;

Expand Down
2 changes: 2 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#endif
#endif

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

#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
Expand Down
2 changes: 0 additions & 2 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ static int cmd_log(int argc, const char **argv, char **envp)
return 0;
}

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

static void handle_internal_command(int argc, const char **argv, char **envp)
{
const char *cmd = argv[0];
Expand Down

0 comments on commit b4f2a6a

Please sign in to comment.