* defs.h (ARRAY_SIZE): New macro.
* ioctl.c: Use it.
* pathtrace.c (pathmatch, storepath): Likewise.
* process.c (printpriv): Likewise.
* signal.c: Likewise.
* syscall.c: Likewise.
# define __attribute__(x) /*nothing*/
#endif
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
/* Trace Control Block */
struct tcb {
short flags; /* See below for TCB_ values */
#include <asm/ioctl.h>
#endif
-const int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0];
+const int nioctlents0 = ARRAY_SIZE(ioctlent0);
#if SUPPORTED_PERSONALITIES >= 2
const struct ioctlent ioctlent1[] = {
#include "ioctlent1.h"
};
-const int nioctlents1 = sizeof ioctlent1 / sizeof ioctlent1[0];
+const int nioctlents1 = ARRAY_SIZE(ioctlent1);
#endif /* SUPPORTED_PERSONALITIES >= 2 */
#if SUPPORTED_PERSONALITIES >= 3
#include "ioctlent2.h"
};
-const int nioctlents2 = sizeof ioctlent2 / sizeof ioctlent2[0];
+const int nioctlents2 = ARRAY_SIZE(ioctlent2);
#endif /* SUPPORTED_PERSONALITIES >= 3 */
const struct ioctlent *ioctlent;
#include "syscall.h"
-#define NumElem(a) (int)(sizeof(a) / sizeof((a)[0]))
-
#define MAXSELECTED 256 /* max number of "selected" paths */
static const char *selected[MAXSELECTED]; /* paths selected for tracing */
static int
pathmatch(const char *path)
{
- int i;
+ unsigned int i;
- for (i = 0; i < NumElem(selected); ++i)
+ for (i = 0; i < ARRAY_SIZE(selected); ++i)
{
if (selected[i] == NULL)
return 0;
static int
storepath(const char *path)
{
- int i;
+ unsigned int i;
if (path == NULL)
{
- for (i = 0; i < NumElem(selected); ++i)
+ for (i = 0; i < ARRAY_SIZE(selected); ++i)
if (selected[i])
{
free((char *) selected[i]);
return 0;
}
- for (i = 0; i < NumElem(selected); ++i)
+ for (i = 0; i < ARRAY_SIZE(selected); ++i)
if (!selected[i])
{
selected[i] = path;
return 0;
}
- fprintf(stderr, "Max trace paths exceeded, only using first %d\n",
- NumElem(selected));
+ fprintf(stderr, "Max trace paths exceeded, only using first %u\n",
+ (unsigned int) ARRAY_SIZE(selected));
return -1;
}
printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
{
priv_t buf[128];
- int max = verbose(tcp) ? sizeof buf / sizeof buf[0] : 10;
+ int max = verbose(tcp) ? ARRAY_SIZE(buf) : 10;
int dots = len > max;
int i;
const char *const signalent0[] = {
#include "signalent.h"
};
-const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
+const int nsignals0 = ARRAY_SIZE(signalent0);
#if SUPPORTED_PERSONALITIES >= 2
const char *const signalent1[] = {
#include "signalent1.h"
};
-const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
+const int nsignals1 = ARRAY_SIZE(signalent1);
#endif /* SUPPORTED_PERSONALITIES >= 2 */
#if SUPPORTED_PERSONALITIES >= 3
const char *const signalent2[] = {
#include "signalent2.h"
};
-const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
+const int nsignals2 = ARRAY_SIZE(signalent2);
#endif /* SUPPORTED_PERSONALITIES >= 3 */
const char *const *signalent;
static const struct sysent sysent0[] = {
#include "syscallent.h"
};
-static const int nsyscalls0 = sizeof sysent0 / sizeof sysent0[0];
+static const int nsyscalls0 = ARRAY_SIZE(sysent0);
int qual_flags0[MAX_QUALS];
#if SUPPORTED_PERSONALITIES >= 2
static const struct sysent sysent1[] = {
#include "syscallent1.h"
};
-static const int nsyscalls1 = sizeof sysent1 / sizeof sysent1[0];
+static const int nsyscalls1 = ARRAY_SIZE(sysent1);
int qual_flags1[MAX_QUALS];
#endif /* SUPPORTED_PERSONALITIES >= 2 */
static const struct sysent sysent2[] = {
#include "syscallent2.h"
};
-static const int nsyscalls2 = sizeof sysent2 / sizeof sysent2[0];
+static const int nsyscalls2 = ARRAY_SIZE(sysent2);
int qual_flags2[MAX_QUALS];
#endif /* SUPPORTED_PERSONALITIES >= 3 */
static const char *const errnoent0[] = {
#include "errnoent.h"
};
-static const int nerrnos0 = sizeof errnoent0 / sizeof errnoent0[0];
+static const int nerrnos0 = ARRAY_SIZE(errnoent0);
#if SUPPORTED_PERSONALITIES >= 2
static const char *const errnoent1[] = {
#include "errnoent1.h"
};
-static const int nerrnos1 = sizeof errnoent1 / sizeof errnoent1[0];
+static const int nerrnos1 = ARRAY_SIZE(errnoent1);
#endif /* SUPPORTED_PERSONALITIES >= 2 */
#if SUPPORTED_PERSONALITIES >= 3
static const char *const errnoent2[] = {
#include "errnoent2.h"
};
-static const int nerrnos2 = sizeof errnoent2 / sizeof errnoent2[0];
+static const int nerrnos2 = ARRAY_SIZE(errnoent2);
#endif /* SUPPORTED_PERSONALITIES >= 3 */
const char *const *errnoent;
break;
#ifdef FREEBSD
case table_style:
- for (i = 0; i < sizeof(subcalls_table) / sizeof(struct subcall); i++)
+ for (i = 0; i < ARRAY_SIZE(subcalls_table); i++)
if (subcalls_table[i].call == tcp->scno) break;
- if (i < sizeof(subcalls_table) / sizeof(struct subcall) &&
+ if (i < ARRAY_SIZE(subcalls_table) &&
tcp->u_arg[0] >= 0 && tcp->u_arg[0] < subcalls_table[i].nsubcalls) {
tcp->scno = subcalls_table[i].subcalls[tcp->u_arg[0]];
for (i = 0; i < tcp->u_nargs; i++)
if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
tcp->u_nargs = sysent[tcp->scno].nargs;
else
- tcp->u_nargs = sizeof(argreg) / sizeof(argreg[0]);
+ tcp->u_nargs = ARRAY_SIZE(argreg);
for (i = 0; i < tcp->u_nargs; ++i)
if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
* in the trap number matches the number strace expects.
*/
/*
- assert(sysent[tcp->scno].nargs <
- sizeof(syscall_regs)/sizeof(syscall_regs[0]));
+ assert(sysent[tcp->scno].nargs < ARRAY_SIZE(syscall_regs));
*/
tcp->u_nargs = sysent[tcp->scno].nargs;