#define NMH_UNUSED(i) i
#endif
+/* DIM gives the number of elements in the one-dimensional array a. */
+#define DIM(a) (sizeof (a) / sizeof (*(a)))
+
/* LEN gives the strlen() of string constant s, excluding the
* terminating NUL. */
#define LEN(s) (sizeof (s) - 1)
{
int eindex = errno;
char buffer[BUFSIZ], errbuf[BUFSIZ], *err;
- struct iovec iob[20], *iov;
+ struct iovec iob[10], *iov;
+ size_t niov;
iov = iob;
#undef ADD_LITERAL
#undef ADD_VAR
+ niov = iov - iob;
+ assert(niov <= DIM(iob));
+
fflush (stdout);
fflush (stderr);
- if (writev (fileno (stderr), iob, iov - iob) < 0) {
+ if (writev(fileno(stderr), iob, niov) == -1) {
snprintf(buffer, sizeof buffer, "%s: write stderr failed: %d\n",
invo_name && *invo_name ? invo_name : "nmh", errno);
if (write(2, buffer, strlen(buffer)) == -1) {