Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
util: Exporting array_size
Browse files Browse the repository at this point in the history
Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
ceolin committed Jan 25, 2016
1 parent 3c25505 commit 54b9593
Show file tree
Hide file tree
Showing 39 changed files with 137 additions and 136 deletions.
4 changes: 2 additions & 2 deletions src/bin/sol-fbp-runner/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ runner_attach_simulation(struct runner *r)
idx = port_desc->array_size > 0 ? i - port_desc->base_port_idx : -1;
found = false;

for (k = 0; k < ARRAY_SIZE(input_nodes); k++) {
for (k = 0; k < SOL_UTIL_ARRAY_SIZE(input_nodes); k++) {
if (port_in->packet_type == *(input_nodes[k].packet_type)) {
node_name = get_node_name(port_desc->name, port_in->packet_type->name, idx);
SOL_NULL_CHECK_GOTO(node_name, nomem);
Expand Down Expand Up @@ -282,7 +282,7 @@ runner_attach_simulation(struct runner *r)
idx = port_desc->array_size > 0 ? i - port_desc->base_port_idx : -1;
found = false;

for (k = 0; k < ARRAY_SIZE(output_nodes); k++) {
for (k = 0; k < SOL_UTIL_ARRAY_SIZE(output_nodes); k++) {
if (port_out->packet_type == *(output_nodes[k].packet_type)) {
node_name = get_node_name(port_desc->name, port_out->packet_type->name, idx);
SOL_NULL_CHECK_GOTO(node_name, nomem);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/common/sol-log-impl-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ _kcmdline_parse_var(const char *start, size_t len)
const struct spec *itr, *itr_end;

itr = specs;
itr_end = itr + ARRAY_SIZE(specs);
itr_end = itr + SOL_UTIL_ARRAY_SIZE(specs);
for (; itr < itr_end; itr++) {
if (itr->prefixlen + 1 < len &&
memcmp(itr->prefix, start, itr->prefixlen) == 0 &&
Expand Down
4 changes: 2 additions & 2 deletions src/lib/common/sol-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sol_log_level_to_str(uint8_t level, char *buf, size_t buflen)
if (buflen < 1)
return;

if (level < ARRAY_SIZE(level_names)) {
if (level < SOL_UTIL_ARRAY_SIZE(level_names)) {
if (level_names[level]) {
strncpy(buf, level_names[level], buflen - 1);
buf[buflen - 1] = '\0';
Expand All @@ -219,7 +219,7 @@ sol_log_get_level_color(uint8_t level)
};

SOL_LOG_INIT_CHECK("level=%hhu", level);
if (level < ARRAY_SIZE(level_colors)) {
if (level < SOL_UTIL_ARRAY_SIZE(level_colors)) {
if (level_colors[level])
return level_colors[level];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/common/sol-mainloop-impl-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static const struct siginfo_handler siginfo_handler[] = {
SIG(SIGUSR2, NULL),
#undef SIG
};
#define SIGINFO_HANDLER_COUNT ARRAY_SIZE(siginfo_handler)
#define SIGINFO_HANDLER_COUNT SOL_UTIL_ARRAY_SIZE(siginfo_handler)

static struct sigaction sa_orig[SIGINFO_HANDLER_COUNT];
static sigset_t sig_blockset, sig_origset;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/common/sol-platform-impl-linux-micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ load_initial_services(void)
};
int err = 0;

for (itr = paths; itr < paths + ARRAY_SIZE(paths); itr++) {
for (itr = paths; itr < paths + SOL_UTIL_ARRAY_SIZE(paths); itr++) {
struct sol_file_reader *reader = sol_file_reader_open(*itr);
if (!reader && errno == ENOENT) {
SOL_DBG("no initial services to load at '%s'", *itr);
Expand Down Expand Up @@ -390,7 +390,7 @@ setup_pid1(void)
int err;
pid_t pid;

for (mnt = mount_table; mnt < mount_table + ARRAY_SIZE(mount_table); mnt++) {
for (mnt = mount_table; mnt < mount_table + SOL_UTIL_ARRAY_SIZE(mount_table); mnt++) {
const char *source = mnt->source ? mnt->source : "none";

SOL_DBG("creating %s", mnt->target);
Expand Down Expand Up @@ -424,7 +424,7 @@ setup_pid1(void)
}
}

for (sym = symlink_table; sym < symlink_table + ARRAY_SIZE(symlink_table); sym++) {
for (sym = symlink_table; sym < symlink_table + SOL_UTIL_ARRAY_SIZE(symlink_table); sym++) {
SOL_DBG("symlinking '%s' to '%s'", sym->source, sym->target);
err = symlink(sym->target, sym->source);
if (err < 0) {
Expand Down Expand Up @@ -504,7 +504,7 @@ teardown_pid1(void)
continue;
}

for (idx = 0; idx < ARRAY_SIZE(mount_table); idx++) {
for (idx = 0; idx < SOL_UTIL_ARRAY_SIZE(mount_table); idx++) {
if (streq(mount_table[idx].target, path)) {
should_umount = false;
break;
Expand Down Expand Up @@ -631,7 +631,7 @@ gdb_exec(const char *gdb_comm)
_exit(EXIT_FAILURE);
}

for (i = 0; i < ARRAY_SIZE(paths); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(paths); i++) {
if (execl(paths[i], paths[i], gdb_comm, argv[0], NULL) == -1)
SOL_DBG("failed to exec %s - %s", paths[i],
sol_util_strerrora(errno));
Expand Down
4 changes: 2 additions & 2 deletions src/lib/comms/sol-mavlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SOL_LOG_INTERNAL_DECLARE(_sol_mavlink_log_domain, "mavlink");
#define TYPE_MODE_MAPPING(_mode_map, _type) \
{ \
.mapping = (struct sol_mavlink_mode_mapping *)_mode_map, \
.len = ARRAY_SIZE(_mode_map), \
.len = SOL_UTIL_ARRAY_SIZE(_mode_map), \
.type = _type, \
} \

Expand Down Expand Up @@ -276,7 +276,7 @@ sol_mavlink_armed_transition(struct sol_mavlink *mavlink, uint8_t base_mode)
if (mavlink->custom_mode_enabled)
mask = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;

for (i = 0; i < ARRAY_SIZE(armed_transitions); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(armed_transitions); i++) {
uint8_t from, to;
const struct sol_mavlink_armed_trans *curr = &armed_transitions[i];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/comms/sol-socket-dtls-impl-tinydtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ sol_socket_dtls_set_handshake_cipher(struct sol_socket *s,

SOL_INT_CHECK(socket->dtls_magic, != dtls_magic, -EINVAL);

if ((size_t)cipher >= ARRAY_SIZE(conv_tbl))
if ((size_t)cipher >= SOL_UTIL_ARRAY_SIZE(conv_tbl))
return -EINVAL;

dtls_select_cipher(socket->context, conv_tbl[cipher]);
Expand Down
72 changes: 36 additions & 36 deletions src/lib/flow/sol-flow-node-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,50 +63,50 @@ get_member_memory(const struct sol_flow_node_options_member_description *member,
#define STRTOL_DECIMAL(_ptr, _endptr) strtoll(_ptr, _endptr, 0)

#define ASSIGN_LINEAR_VALUES(_parse_func, \
_max_val, _max_str, _max_str_len, \
_min_val, _min_str, _min_str_len) \
do { \
char *start, *end, backup; \
int field_cnt_max = ARRAY_SIZE(store_vals); \
if (keys_schema) break; \
start = buf; \
end = strchr(start, SUBOPTION_SEPARATOR); \
if (!end) end = start + strlen(start); \
backup = *end; \
*end = '\0'; \
_max_val, _max_str, _max_str_len, \
_min_val, _min_str, _min_str_len) \
do { \
char *start, *end, backup; \
int field_cnt_max = SOL_UTIL_ARRAY_SIZE(store_vals); \
if (keys_schema) break; \
start = buf; \
end = strchr(start, SUBOPTION_SEPARATOR); \
if (!end) end = start + strlen(start); \
backup = *end; \
*end = '\0'; \
for (field_cnt = 0; field_cnt < field_cnt_max;) { \
bool is_max = false, is_min = false; \
errno = 0; \
if (strlen(start) >= _max_str_len \
&& (strncmp(start, _max_str, \
_max_str_len) == 0)) { \
is_max = true; \
} else if (strlen(start) >= _min_str_len \
&& (strncmp(start, _min_str, \
_min_str_len) == 0)) { \
is_min = true; \
} \
if (is_max) *store_vals[field_cnt] = _max_val; \
else if (is_min) *store_vals[field_cnt] = _min_val; \
bool is_max = false, is_min = false; \
errno = 0; \
if (strlen(start) >= _max_str_len \
&& (strncmp(start, _max_str, \
_max_str_len) == 0)) { \
is_max = true; \
} else if (strlen(start) >= _min_str_len \
&& (strncmp(start, _min_str, \
_min_str_len) == 0)) { \
is_min = true; \
} \
if (is_max) *store_vals[field_cnt] = _max_val; \
else if (is_min) *store_vals[field_cnt] = _min_val; \
else { \
char *endptr; \
*store_vals[field_cnt] = _parse_func(start, &endptr); \
/* check if no number was parsed, indicates invalid string */ \
if (start == endptr) \
goto err; \
} \
if (errno != 0) goto err; \
field_cnt++; \
*end = backup; \
if (errno != 0) goto err; \
field_cnt++; \
*end = backup; \
start = NULL; \
if (backup == '\0') break; \
start = end + 1; \
if (!start) break; \
end = strchr(start, SUBOPTION_SEPARATOR); \
if (!end) end = start + strlen(start); \
backup = *end; \
*end = '\0'; \
} \
if (backup == '\0') break; \
start = end + 1; \
if (!start) break; \
end = strchr(start, SUBOPTION_SEPARATOR); \
if (!end) end = start + strlen(start); \
backup = *end; \
*end = '\0'; \
} \
if (start) goto err; \
} while (0)

Expand Down Expand Up @@ -605,7 +605,7 @@ sol_flow_node_named_options_parse_member(
if (m->type == 0) {
r = -EINVAL;
SOL_DBG("Unitialized member type for name=\"%s\": \"%s\"", m->name, value);
} else if (m->type < ARRAY_SIZE(options_parse_functions)) {
} else if (m->type < SOL_UTIL_ARRAY_SIZE(options_parse_functions)) {
if (mdesc->required)
init_member_suboptions(m);
else
Expand Down
4 changes: 2 additions & 2 deletions src/modules/flow/calamari/calamari.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ calamari_lever_spi_poll(void *data)
/* MCP300X message - Start, Single ended - pin 0, null */
static const uint8_t tx[] = { 0x01, 0x80, 0x00 };
/* rx must be the same size as tx */
static uint8_t rx[ARRAY_SIZE(tx)] = { 0x00, };
static uint8_t rx[SOL_UTIL_ARRAY_SIZE(tx)] = { 0x00, };

SOL_NULL_CHECK(mdata, false);
SOL_NULL_CHECK(mdata->spi, false);

if (!sol_spi_transfer(mdata->spi, tx, rx, ARRAY_SIZE(tx), spi_transfer_cb,
if (!sol_spi_transfer(mdata->spi, tx, rx, SOL_UTIL_ARRAY_SIZE(tx), spi_transfer_cb,
mdata)) {
SOL_WRN("Error reading lever during poll.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/flow/converter/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ direction_vector_convert(struct sol_flow_node *node, void *data, uint16_t port,
mdata->output_value.z = val;
}

for (i = 0; i < ARRAY_SIZE(mdata->output_initialized); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(mdata->output_initialized); i++) {
if (!mdata->output_initialized[i])
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/flow/grove/grove.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ color_cmd_queue(struct lcd_data *mdata,
uint32_t *color = colors;
unsigned i;

for (i = 0; i < ARRAY_SIZE(colors); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(colors); i++) {
int r = command_queue_append(mdata, RGB_ADDR, COLOR_ADDR[i], *color++);
SOL_INT_CHECK(r, < 0, r);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/flow/led-7seg/led-7seg.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ value_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_i
{
int32_t in_value;
int r;
const int array_size = ARRAY_SIZE(font) - 1;
const int array_size = SOL_UTIL_ARRAY_SIZE(font) - 1;

r = sol_flow_packet_get_irange_value(packet, &in_value);
SOL_INT_CHECK(r, < 0, r);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/flow/thingspeak/thingspeak.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ thingspeak_channel_update_send(void *data)
}
}

for (i = 0; i < ARRAY_SIZE(mdata->fields); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(mdata->fields); i++) {
if (!mdata->fields[i])
continue;

Expand Down Expand Up @@ -456,7 +456,7 @@ thingspeak_channel_update_field_process(struct sol_flow_node *node,
int n_field = port - SOL_FLOW_NODE_TYPE_THINGSPEAK_CHANNEL_UPDATE__IN__FIELD;
const char *field;

if (n_field < 0 || n_field >= (int)ARRAY_SIZE(mdata->fields)) {
if (n_field < 0 || n_field >= (int)SOL_UTIL_ARRAY_SIZE(mdata->fields)) {
SOL_WRN("Invalid field ID: %d, expecting 0 to 7", n_field);
return -EINVAL;
}
Expand Down Expand Up @@ -508,7 +508,7 @@ thingspeak_channel_update_close(struct sol_flow_node *node, void *data)
struct sol_http_client_connection *connection;
uint16_t i;

for (i = 0; i < ARRAY_SIZE(mdata->fields); i++)
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(mdata->fields); i++)
free(mdata->fields[i]);
free(mdata->status);

Expand Down Expand Up @@ -544,7 +544,7 @@ thingspeak_channel_update_open(struct sol_flow_node *node, void *data, const str
return -ENOMEM;
}

for (i = 0; i < ARRAY_SIZE(mdata->fields); i++)
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(mdata->fields); i++)
mdata->fields[i] = NULL;
mdata->status = NULL;
mdata->timeout = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/linux-micro/automount/automount.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ automount_get_fstype(char *dev)
{
unsigned int i;

for (i = 0; i < ARRAY_SIZE(table); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(table); i++) {
const struct filesystem_magic *magic;

for (magic = table[i].magic; magic->magic != NULL; magic++) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/linux-micro/bluetooth/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ on_fork(void *data)
NULL
};

for (i = 0; i < ARRAY_SIZE(daemon_possible_paths); i++) {
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(daemon_possible_paths); i++) {
argv[0] = daemon_possible_paths[i];
SOL_INF("attempting to exec %s", daemon_possible_paths[i]);
execvpe(argv[0], (char *const *)argv, (char *const *)envp);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/linux-micro/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ find_getty_cmd(void)
const char **itr, **itr_end;

itr = cmds;
itr_end = itr + ARRAY_SIZE(cmds);
itr_end = itr + SOL_UTIL_ARRAY_SIZE(cmds);
for (; itr < itr_end; itr++) {
if (access(*itr, R_OK | X_OK) == 0)
return *itr;
Expand Down Expand Up @@ -264,7 +264,7 @@ parse_var(const char *start, size_t len)
const struct spec *itr, *itr_end;

itr = specs;
itr_end = itr + ARRAY_SIZE(specs);
itr_end = itr + SOL_UTIL_ARRAY_SIZE(specs);
for (; itr < itr_end; itr++) {
if (itr->prefixlen < len &&
memcmp(itr->prefix, start, itr->prefixlen) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/linux-micro/locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ parse_var(const char *start, size_t len)
valuelen -= 2;
}

for (itr = locale_vars; itr < locale_vars + ARRAY_SIZE(locale_vars); itr++) {
for (itr = locale_vars; itr < locale_vars + SOL_UTIL_ARRAY_SIZE(locale_vars); itr++) {
if (itr->len == namelen && memcmp(itr->data, name, namelen) == 0) {
char *v = strndupa(value, valuelen);
SOL_DBG("set locale var %s=%s", itr->data, v);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/linux-micro/rc-d/rc-d.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ find_exec(const char *service, const char *arg)
"/etc/rc.d"
};

for (itr = dirs; itr < dirs + ARRAY_SIZE(dirs); itr++) {
for (itr = dirs; itr < dirs + SOL_UTIL_ARRAY_SIZE(dirs); itr++) {
char path[PATH_MAX];
int r;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/linux-micro/watchdog/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ watchdog_show_info_flags(const char *msg, uint32_t flags, uint32_t options)
msg, flags, options);

itr = map;
itr_end = itr + ARRAY_SIZE(map);
itr_end = itr + SOL_UTIL_ARRAY_SIZE(map);
for (; itr < itr_end; itr++) {
if (itr->flag & options) {
if (itr->flag & flags)
Expand Down
Loading

0 comments on commit 54b9593

Please sign in to comment.