From 56a95c7f17e2e46d2fbddded582bd99fc555abd9 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 2 Mar 2019 11:30:10 +0300 Subject: [PATCH] ARRAY_LEN() --- src/device.c | 8 ++++---- src/encoder.c | 2 +- src/tools.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/device.c b/src/device.c index b94fd97..5281a8f 100644 --- a/src/device.c +++ b/src/device.c @@ -99,7 +99,7 @@ void device_destroy(struct device_t *dev) { } int device_parse_format(const char *const str) { - for (unsigned index = 0; index < sizeof(_FORMATS) / sizeof(_FORMATS[0]); ++index) { + for (unsigned index = 0; index < ARRAY_LEN(_FORMATS); ++index) { if (!strcasecmp(str, _FORMATS[index].name)) { return _FORMATS[index].format; } @@ -108,7 +108,7 @@ int device_parse_format(const char *const str) { } v4l2_std_id device_parse_standard(const char *const str) { - for (unsigned index = 1; index < sizeof(_STANDARDS) / sizeof(_STANDARDS[0]); ++index) { + for (unsigned index = 1; index < ARRAY_LEN(_STANDARDS); ++index) { if (!strcasecmp(str, _STANDARDS[index].name)) { return _STANDARDS[index].standard; } @@ -457,7 +457,7 @@ static const char *_format_to_string_auto(char *buf, const size_t size, const un } static const char *_format_to_string_null(const unsigned format) { - for (unsigned index = 0; index < sizeof(_FORMATS) / sizeof(_FORMATS[0]); ++index) { + for (unsigned index = 0; index < ARRAY_LEN(_FORMATS); ++index) { if (format == _FORMATS[index].format) { return _FORMATS[index].name; } @@ -466,7 +466,7 @@ static const char *_format_to_string_null(const unsigned format) { } static const char *_standard_to_string(v4l2_std_id standard) { - for (unsigned index = 0; index < sizeof(_STANDARDS) / sizeof(_STANDARDS[0]); ++index) { + for (unsigned index = 0; index < ARRAY_LEN(_STANDARDS); ++index) { if (standard == _STANDARDS[index].standard) { return _STANDARDS[index].name; } diff --git a/src/encoder.c b/src/encoder.c index d34a460..4bf38cf 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -120,7 +120,7 @@ void encoder_destroy(struct encoder_t *encoder) { } enum encoder_type_t encoder_parse_type(const char *const str) { - for (unsigned index = 0; index < sizeof(_ENCODER_TYPES) / sizeof(_ENCODER_TYPES[0]); ++index) { + for (unsigned index = 0; index < ARRAY_LEN(_ENCODER_TYPES); ++index) { if (!strcasecmp(str, _ENCODER_TYPES[index].name)) { return _ENCODER_TYPES[index].type; } diff --git a/src/tools.h b/src/tools.h index bfdc657..9aab6a5 100644 --- a/src/tools.h +++ b/src/tools.h @@ -48,12 +48,12 @@ #define A_PTHREAD_C_SIGNAL(...) assert(!pthread_cond_signal(__VA_ARGS__)) #define A_PTHREAD_C_WAIT_TRUE(_var, _cond, _mutex) { while(!_var) assert(!pthread_cond_wait(_cond, _mutex)); } - #define A_CALLOC(_dest, _nmemb) assert((_dest = calloc(_nmemb, sizeof(*(_dest))))) #define A_REALLOC(_dest, _nmemb) assert((_dest = realloc(_dest, _nmemb * sizeof(*(_dest))))) #define MEMSET_ZERO(_obj) memset(&(_obj), 0, sizeof(_obj)) #define MEMSET_ZERO_PTR(_ptr) memset(_ptr, 0, sizeof(*(_ptr))) +#define ARRAY_LEN(_array) (sizeof(_array) / sizeof(_array[0])) #define INLINE inline __attribute__((always_inline)) #define UNUSED __attribute__((unused))