Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the macros from sys/param.h #1970

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion builtin/builtin_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nuttx/config.h>

#include <nuttx/lib/builtin.h>
#include <sys/param.h>

#include <sys/stat.h>

Expand All @@ -40,11 +41,11 @@
* Public Data
****************************************************************************/

#include "builtin_proto.h"

Check warning on line 44 in builtin/builtin_list.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section

const struct builtin_s g_builtins[] =
{
# include "builtin_list.h"

Check warning on line 48 in builtin/builtin_list.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#ifdef CONFIG_SCHED_USER_IDENTITY
{ NULL, 0, 0, 0, 0, 0, 0 }
#else
Expand All @@ -52,7 +53,7 @@
#endif
};

const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);
const int g_builtin_count = nitems(g_builtins);

/****************************************************************************
* Private Data
Expand Down
15 changes: 6 additions & 9 deletions canutils/libcanutils/lib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */

Check failure on line 1 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Missing blank line after comment
/*

Check failure on line 2 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Too many whitespaces before relative file path

Check failure on line 2 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

C comment opening on separate line
* lib.c - library for command line tools
*
* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
Expand Down Expand Up @@ -42,15 +42,16 @@
*
*/

#include <stdio.h>

Check warning on line 45 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#include <string.h>

Check warning on line 46 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#include <stdint.h>

Check warning on line 47 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section

#include <sys/param.h>

Check warning on line 49 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#include <sys/socket.h> /* for sa_family_t */

Check warning on line 50 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#include <nuttx/can.h>

Check warning on line 51 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section
#include <netpacket/can.h>

Check warning on line 52 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section

#include "lib.h"

Check warning on line 54 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

#include outside of 'Included Files' section

#define CANID_DELIM '#'
#define DATA_SEPARATOR '.'
Expand All @@ -62,14 +63,14 @@

static inline void put_hex_byte(char *buf, __u8 byte)
{
buf[0] = hex_asc_upper_hi(byte);

Check failure on line 66 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

TABs found. First detected
buf[1] = hex_asc_upper_lo(byte);
}

static inline void _put_id(char *buf, int end_offset, canid_t id)
{
/* build 3 (SFF) or 8 (EFF) digit CAN identifier */
while (end_offset >= 0) {

Check failure on line 73 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Left bracket not on separate line
buf[end_offset--] = hex_asc_upper_lo(id);
id >>= 4;
}
Expand All @@ -80,13 +81,13 @@

/* CAN DLC to real data length conversion helpers */

static const unsigned char dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7,

Check failure on line 84 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Multiple data definitions

Check failure on line 84 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Left bracket not on separate line
8, 12, 16, 20, 24, 32, 48, 64};

Check failure on line 85 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Right bracket not on separate line

/* get data length from can_dlc with sanitized can_dlc */

Check failure on line 87 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Missing blank line after comment
unsigned char can_dlc2len(unsigned char can_dlc)
{
return dlc2len[can_dlc & 0x0F];

Check failure on line 90 in canutils/libcanutils/lib.c

View workflow job for this annotation

GitHub Actions / check

Upper case hex constant found
}

static const unsigned char len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
Expand Down Expand Up @@ -496,10 +497,6 @@
"unspecified",
};

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif

static int snprintf_error_data(char *buf, size_t len, uint8_t err,
const char **arr, int arr_len)
{
Expand Down Expand Up @@ -537,7 +534,7 @@
n += snprintf(buf + n, len - n, "{");
n += snprintf_error_data(buf + n, len - n, cf->data[1],
controller_problems,
ARRAY_SIZE(controller_problems));
nitems(controller_problems));
n += snprintf(buf + n, len - n, "}");

return n;
Expand All @@ -553,10 +550,10 @@
n += snprintf(buf + n, len - n, "{{");
n += snprintf_error_data(buf + n, len - n, cf->data[2],
protocol_violation_types,
ARRAY_SIZE(protocol_violation_types));
nitems(protocol_violation_types));
n += snprintf(buf + n, len - n, "}{");
if (cf->data[3] > 0 &&
cf->data[3] < ARRAY_SIZE(protocol_violation_locations))
cf->data[3] < nitems(protocol_violation_locations))
n += snprintf(buf + n, len - n, "%s",
protocol_violation_locations[cf->data[3]]);
n += snprintf(buf + n, len - n, "}}");
Expand All @@ -575,15 +572,15 @@
return;

class = cf->can_id & CAN_EFF_MASK;
if (class > (1 << ARRAY_SIZE(error_classes))) {
if (class > (1 << nitems(error_classes))) {
fprintf(stderr, "Error class %#jx is invalid\n", (uintmax_t)class);
return;
}

if (!sep)
sep = defsep;

for (i = 0; i < (int)ARRAY_SIZE(error_classes); i++) {
for (i = 0; i < (int)nitems(error_classes); i++) {
mask = 1 << i;
if (class & mask) {
if (classes)
Expand Down
9 changes: 4 additions & 5 deletions examples/adxl372_test/adxl372_test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <nuttx/fs/fs.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand All @@ -41,7 +41,6 @@
* Pre-processor Definitions
****************************************************************************/

#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#define PASSED 0

#define SUB_PROMPT "stst >"
Expand Down Expand Up @@ -394,7 +393,7 @@ int main(int argc, FAR char *argv[])
adxl372_test, /* ADXL372 accelerometer tests */
};

FAR char *test_path[ARRAYSIZE(test_ptr_array)];
FAR char *test_path[nitems(test_ptr_array)];

if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
{
Expand Down Expand Up @@ -490,7 +489,7 @@ int main(int argc, FAR char *argv[])
printf("Set to batch mode.\n");
}
}
else if (ui >= ARRAYSIZE(test_ptr_array))
else if (ui >= nitems(test_ptr_array))
{
printf("Huh?\n");
}
Expand All @@ -511,7 +510,7 @@ int main(int argc, FAR char *argv[])
{
printf("ADXL372 sensor diagnostic started in batch mode...\n");

for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
for (ui = 0; ui < nitems(test_ptr_array); ui++)
{
step_rc = 0;
if (test_ptr_array[ui] != 0)
Expand Down
11 changes: 4 additions & 7 deletions examples/dac/dac_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/param.h>
#include <nuttx/analog/dac.h>
#include <nuttx/arch.h>

Expand All @@ -47,10 +48,6 @@
# define CONFIG_EXAMPLES_DAC_DEVPATH "/dev/dac0"
#endif

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

/****************************************************************************
* Private Types
****************************************************************************/
Expand Down Expand Up @@ -226,7 +223,7 @@ static int cmd_dac_put(int argc, FAR const char *argv[])
{
msgs[0].am_channel = g_dacstate.channel;
msgs[0].am_data = data;
ret = dac_put(g_dacstate.devpath, msgs, ARRAY_SIZE(msgs), delay);
ret = dac_put(g_dacstate.devpath, msgs, nitems(msgs), delay);
printf("ret=%d\n", ret);
}

Expand Down Expand Up @@ -277,7 +274,7 @@ static void dac_help(void)
"Default: %s Current: %s\n",
CONFIG_EXAMPLES_DAC_DEVPATH,
g_dacstate.devpath ? g_dacstate.devpath : "NONE");
print_cmds("\nCommands:\n", commands, ARRAY_SIZE(commands), "\n");
print_cmds("\nCommands:\n", commands, nitems(commands), "\n");
}

static int arg_string(FAR const char **arg, FAR const char **value)
Expand Down Expand Up @@ -422,7 +419,7 @@ int main(int argc, FAR const char *argv[])
}
else
{
ret = execute_cmd(argc, argv, commands, ARRAY_SIZE(commands));
ret = execute_cmd(argc, argv, commands, nitems(commands));
}

return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE;
Expand Down
24 changes: 11 additions & 13 deletions examples/ft80x/ft80x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <fcntl.h>
#include <errno.h>

#include <sys/param.h>
#include <nuttx/lcd/ft80x.h>

#include "graphics/ft80x.h"
Expand Down Expand Up @@ -60,13 +61,13 @@ struct ft80x_exampleinfo_s
* ft80x_prim_lines LINES Line drawing primitive
* ft80x_prim_linestrip LINE_STRIP Line strip drawing primitive
* ft80x_prim_edgestrip_r EDGE_STRIP_R Edge strip right side drawing
primitive
* primitive
* (To be provided) EDGE_STRIP_L Edge strip left side drawing
primitive
* primitive
* (To be provided) EDGE_STRIP_A Edge strip above side drawing
primitive
* primitive
* (To be provided) EDGE_STRIP_B Edge strip below side drawing
primitive
* primitive
* ft80x_prim_rectangles RECTS Rectangle drawing primitive
* ft80x_prim_scissor SCISSOR Scissor primitive
* ft80x_prim_stencil STENCIL Stencil primitives
Expand All @@ -88,15 +89,14 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
{ "Alpha Blend", ft80x_prim_alphablend }
};

#define NPRIMITIVES (sizeof(g_primitives) / sizeof(struct ft80x_exampleinfo_s))
#endif /* CONFIG_EXAMPLES_FT80X_PRIMITIVES */

/* Co-processor display examples. Only a small, but interesting, subset
* here co-processor command are exercised and these with only a few of the
* possible options.
*
* FUNCTION CoProc CMD USED DESCRIPTION
* ------------------------ --------------- ----------------------------------
* ------------------------ --------------- --------------------------------
* ft80x_coproc_button CMD_BUTTON Draw a button
* ft80x_coproc_clock CMD_CLOCK Draw an analog clock
* ft80x_coproc_gauge CMD_GAUGE Draw a gauge
Expand All @@ -109,12 +109,12 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
* ft80x_coproc_toggle CMD_TOGGLE Draw a toggle switch
* ft80x_coproc_number CMD_NUMBER Draw a decimal number
* ft80x_coproc_calibrate CMD_CALIBRATE Execute the touch screen
calibration routine
* calibration routine
* ft80x_coproc_spinner CMD_SPINNER Start an animated spinner
* ft80x_coproc_screensaver CMD_SCREENSAVER Start an animated screensaver
* (To be provided) CMD_SKETCH Start a continuous sketch update
* (To be provided) CMD_SNAPSHOT Take a snapshot of the current
screen
* screen
* ft80x_coproc_logo CMD_LOGO Play device log animation
*/

Expand All @@ -139,8 +139,6 @@ static const struct ft80x_exampleinfo_s g_coproc[] =
{ "Logo", ft80x_coproc_logo }
};

#define NCOPROC (sizeof(g_coproc) / sizeof(struct ft80x_exampleinfo_s))

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -182,7 +180,7 @@ static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer,
/* Clear the display */

cmds.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(0, 0, 0x80);
cmds.clear.cmd = FT80X_CLEAR(1 ,1, 1);
cmds.clear.cmd = FT80X_CLEAR(1, 1, 1);
cmds.colorrgb.cmd = FT80X_COLOR_RGB(0xff, 0xff, 0xff);

/* Use the CMD_TEXT co-processor command to show the name of the next
Expand Down Expand Up @@ -308,7 +306,7 @@ int main(int argc, FAR char *argv[])

ft80x_info("FT80x Primitive Functions\n");

for (i = 0; i < NPRIMITIVES; i++)
for (i = 0; i < nitems(g_primitives); i++)
{
ft80x_example(fd, buffer, &g_primitives[i]);
}
Expand All @@ -318,7 +316,7 @@ int main(int argc, FAR char *argv[])

ft80x_info("FT80x Co-processor Functions\n");

for (i = 0; i < NCOPROC; i++)
for (i = 0; i < nitems(g_coproc); i++)
{
ft80x_example(fd, buffer, &g_coproc[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/ftpd/ftpd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <errno.h>
#include <debug.h>

#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

Expand Down Expand Up @@ -65,7 +66,6 @@ static const struct fptd_account_s g_ftpdaccounts[] =
{ FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL },
};
#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s))

/****************************************************************************
* Public Data
Expand Down Expand Up @@ -139,7 +139,7 @@ static void ftpd_accounts(FTPD_SESSION handle)
int i;

printf("Adding accounts:\n");
for (i = 0; i < NACCOUNTS; i++)
for (i = 0; i < nitems(g_ftpdaccounts); i++)
{
account = &g_ftpdaccounts[i];

Expand Down
9 changes: 4 additions & 5 deletions examples/lsm330spi_test/lsm330spi_test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <nuttx/fs/fs.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand All @@ -41,7 +41,6 @@
* Pre-processor Definitions
****************************************************************************/

#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#define PASSED 0

#define SUB_PROMPT "stst >"
Expand Down Expand Up @@ -631,7 +630,7 @@ int main(int argc, FAR char *argv[])
lsm330gyro_test, /* LSM330 gyroscope tests */
};

FAR char *test_path[ARRAYSIZE(test_ptr_array)];
FAR char *test_path[nitems(test_ptr_array)];

if (argc < 2 || *argv[1] == 0 || *(argv[1] + 1) == 0)
{
Expand Down Expand Up @@ -737,7 +736,7 @@ int main(int argc, FAR char *argv[])
printf("Set to batch mode.\n");
}
}
else if (ui >= ARRAYSIZE(test_ptr_array))
else if (ui >= nitems(test_ptr_array))
{
printf("Huh?\n");
}
Expand All @@ -757,7 +756,7 @@ int main(int argc, FAR char *argv[])
else /* not interactive mode */
{
printf("LSM330 sensor diagnostic started in batch mode...\n");
for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
for (ui = 0; ui < nitems(test_ptr_array); ui++)
{
step_rc = 0;
if (test_ptr_array[ui] != 0)
Expand Down
Loading
Loading