make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int.  Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted.  I didn't do
them since they are not well covered by the unit tests.
This commit is contained in:
rillig 2020-10-05 21:37:07 +00:00
parent c5aeb8a719
commit 883ec9be11
5 changed files with 44 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.260 2020/10/05 19:27:47 rillig Exp $ */
/* $NetBSD: job.c,v 1.261 2020/10/05 21:37:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -143,7 +143,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: job.c,v 1.260 2020/10/05 19:27:47 rillig Exp $");
MAKE_RCSID("$NetBSD: job.c,v 1.261 2020/10/05 21:37:07 rillig Exp $");
# define STATIC static
@ -290,7 +290,7 @@ static char *shellArgv = NULL; /* Custom shell args */
STATIC Job *job_table; /* The structures that describe them */
STATIC Job *job_table_end; /* job_table + maxJobs */
static int wantToken; /* we want a token */
static unsigned int wantToken; /* we want a token */
static int lurking_children = 0;
static int make_suspended = 0; /* non-zero if we've seen a SIGTSTP (etc) */
@ -300,7 +300,7 @@ static int make_suspended = 0; /* non-zero if we've seen a SIGTSTP (etc) */
*/
static struct pollfd *fds = NULL;
static Job **jobfds = NULL;
static int nfds = 0;
static nfds_t nfds = 0;
static void watchfd(Job *);
static void clearfd(Job *);
static int readyfd(Job *);
@ -314,7 +314,7 @@ static Job childExitJob; /* child exit pseudo-job */
#define CHILD_EXIT "."
#define DO_JOB_RESUME "R"
static const int npseudojobs = 2; /* number of pseudo-jobs */
enum { npseudojobs = 2 }; /* number of pseudo-jobs */
#define TARG_FMT "%s %s ---\n" /* Default format */
#define MESSAGE(fp, gn) \
@ -1648,10 +1648,10 @@ JobDoOutput(Job *job, Boolean finish)
{
Boolean gotNL = FALSE; /* true if got a newline */
Boolean fbuf; /* true if our buffer filled up */
int nr; /* number of bytes read */
int i; /* auxiliary index into outBuf */
int max; /* limit for i (end of current data) */
int nRead; /* (Temporary) number of bytes read */
size_t nr; /* number of bytes read */
size_t i; /* auxiliary index into outBuf */
size_t max; /* limit for i (end of current data) */
ssize_t nRead; /* (Temporary) number of bytes read */
/*
* Read as many bytes as will fit in the buffer.
@ -1670,7 +1670,7 @@ end_loop:
}
nr = 0;
} else {
nr = nRead;
nr = (size_t)nRead;
}
/*
@ -1693,7 +1693,7 @@ end_loop:
* TRUE.
*/
max = job->curPos + nr;
for (i = job->curPos + nr - 1; i >= job->curPos; i--) {
for (i = job->curPos + nr - 1; i >= job->curPos && i != (size_t)-1; i--) {
if (job->outBuf[i] == '\n') {
gotNL = TRUE;
break;
@ -1892,7 +1892,7 @@ Job_CatchOutput(void)
{
int nready;
Job *job;
int i;
unsigned int i;
(void)fflush(stdout);
@ -1926,9 +1926,9 @@ Job_CatchOutput(void)
Job_CatchChildren();
if (nready == 0)
return;
return;
for (i = npseudojobs*nfds_per_job(); i < nfds; i++) {
for (i = npseudojobs * nfds_per_job(); i < nfds; i++) {
if (!fds[i].revents)
continue;
job = jobfds[i];
@ -1947,7 +1947,7 @@ Job_CatchOutput(void)
}
#endif
if (--nready == 0)
return;
return;
}
}
@ -1991,7 +1991,7 @@ Shell_Init(void)
shellErrFlag = NULL;
}
if (!shellErrFlag) {
int n = strlen(commandShell->exit) + 2;
size_t n = strlen(commandShell->exit) + 2;
shellErrFlag = bmake_malloc(n);
if (shellErrFlag) {
@ -2032,8 +2032,8 @@ Job_Init(void)
{
Job_SetPrefix();
/* Allocate space for all the job info */
job_table = bmake_malloc(maxJobs * sizeof *job_table);
memset(job_table, 0, maxJobs * sizeof *job_table);
job_table = bmake_malloc((size_t)maxJobs * sizeof *job_table);
memset(job_table, 0, (size_t)maxJobs * sizeof *job_table);
job_table_end = job_table + maxJobs;
wantToken = 0;
@ -2065,9 +2065,9 @@ Job_Init(void)
/* Preallocate enough for the maximum number of jobs. */
fds = bmake_malloc(sizeof(*fds) *
(npseudojobs + maxJobs) * nfds_per_job());
(npseudojobs + (size_t)maxJobs) * nfds_per_job());
jobfds = bmake_malloc(sizeof(*jobfds) *
(npseudojobs + maxJobs) * nfds_per_job());
(npseudojobs + (size_t)maxJobs) * nfds_per_job());
/* These are permanent entries and take slots 0 and 1 */
watchfd(&tokenWaitJob);
@ -2521,10 +2521,10 @@ watchfd(Job *job)
static void
clearfd(Job *job)
{
int i;
size_t i;
if (job->inPollfd == NULL)
Punt("Unwatching unwatched job");
i = job->inPollfd - fds;
i = (size_t)(job->inPollfd - fds);
nfds--;
#if defined(USE_FILEMON) && !defined(USE_FILEMON_DEV)
if (useMeta) {
@ -2638,7 +2638,7 @@ Boolean
Job_TokenWithdraw(void)
{
char tok, tok1;
int count;
ssize_t count;
wantToken = 0;
DEBUG3(JOB, "Job_TokenWithdraw(%d): aborting %d, running %d\n",

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.h,v 1.54 2020/09/28 00:13:03 rillig Exp $ */
/* $NetBSD: job.h,v 1.55 2020/10/05 21:37:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -154,7 +154,7 @@ typedef struct Job {
char job_suspended;
short flags; /* Flags to control treatment of job */
int flags; /* Flags to control treatment of job */
#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
#define JOB_SILENT 0x002 /* no output */
#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
@ -170,7 +170,7 @@ typedef struct Job {
#define JOB_BUFSIZE 1024
/* Buffer for storing the output of the job, line by line. */
char outBuf[JOB_BUFSIZE + 1];
int curPos; /* Current position in outBuf. */
size_t curPos; /* Current position in outBuf. */
#ifdef USE_META
struct BuildMon bm;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.369 2020/10/05 19:27:47 rillig Exp $ */
/* $NetBSD: main.c,v 1.370 2020/10/05 21:37:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -122,7 +122,7 @@
#endif
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: main.c,v 1.369 2020/10/05 19:27:47 rillig Exp $");
MAKE_RCSID("$NetBSD: main.c,v 1.370 2020/10/05 21:37:07 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@ -443,7 +443,7 @@ MainParseArgJobs(const char *argvalue)
char *p;
forceJobs = TRUE;
maxJobs = strtol(argvalue, &p, 0);
maxJobs = (int)strtol(argvalue, &p, 0);
if (*p != '\0' || maxJobs < 1) {
(void)fprintf(stderr,
"%s: illegal argument to -j -- must be positive integer!\n",
@ -1073,7 +1073,7 @@ main(int argc, char **argv)
* on each program execution.
*/
gettimeofday(&rightnow, NULL);
srandom(rightnow.tv_sec + rightnow.tv_usec);
srandom((unsigned int)(rightnow.tv_sec + rightnow.tv_usec));
if ((progname = strrchr(argv[0], '/')) != NULL)
progname++;
@ -1419,7 +1419,7 @@ main(int argc, char **argv)
(void)Var_Subst("${.MAKE.JOBS}", VAR_GLOBAL, VARE_WANTRES, &value);
/* TODO: handle errors */
n = strtol(value, NULL, 0);
n = (int)strtol(value, NULL, 0);
if (n < 1) {
(void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
progname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.368 2020/10/05 19:27:47 rillig Exp $ */
/* $NetBSD: parse.c,v 1.369 2020/10/05 21:37:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.368 2020/10/05 19:27:47 rillig Exp $");
MAKE_RCSID("$NetBSD: parse.c,v 1.369 2020/10/05 21:37:07 rillig Exp $");
/* types and constants */
@ -143,7 +143,7 @@ typedef struct IFile {
Boolean fromForLoop; /* simulated .include by the .for loop */
int lineno; /* current line number in file */
int first_lineno; /* line number of start of text */
int cond_depth; /* 'if' nesting when file opened */
unsigned int cond_depth; /* 'if' nesting when file opened */
Boolean depending; /* state of doing_depend on EOF */
char *P_str; /* point to base of string buffer */
char *P_ptr; /* point to next char of string buffer */
@ -454,7 +454,7 @@ static struct loadedfile *
loadfile(const char *path, int fd)
{
struct loadedfile *lf;
static long pagesize = 0;
static unsigned long pagesize = 0;
ssize_t result;
size_t bufpos;
@ -477,8 +477,8 @@ loadfile(const char *path, int fd)
if (load_getsize(fd, &lf->len)) {
/* found a size, try mmap */
if (pagesize == 0)
pagesize = sysconf(_SC_PAGESIZE);
if (pagesize <= 0) {
pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
if (pagesize == 0 || pagesize == (unsigned long)-1) {
pagesize = 0x1000;
}
/* round size up to a page */
@ -540,7 +540,7 @@ loadfile(const char *path, int fd)
if (result == 0) {
break;
}
bufpos += result;
bufpos += (size_t)result;
}
assert(bufpos <= lf->len);
lf->len = bufpos;
@ -709,7 +709,7 @@ Parse_Error(int type, const char *fmt, ...)
lineno = 0;
} else {
fname = curFile->fname;
lineno = curFile->lineno;
lineno = (size_t)curFile->lineno;
}
va_start(ap, fmt);
@ -2113,7 +2113,7 @@ ParseAddCmd(GNode *gn, char *cmd)
Parse_Error(PARSE_WARNING,
"duplicate script for target \"%s\" ignored",
gn->name);
ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING,
ParseErrorInternal(gn->fname, (size_t)gn->lineno, PARSE_WARNING,
"using previous script for \"%s\" defined here",
gn->name);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.176 2020/10/05 19:27:47 rillig Exp $ */
/* $NetBSD: suff.c,v 1.177 2020/10/05 21:37:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -129,7 +129,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
MAKE_RCSID("$NetBSD: suff.c,v 1.176 2020/10/05 19:27:47 rillig Exp $");
MAKE_RCSID("$NetBSD: suff.c,v 1.177 2020/10/05 21:37:07 rillig Exp $");
#define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
@ -1619,7 +1619,7 @@ SuffFindArchiveDeps(GNode *gn, SrcList *slst)
/*
* Use first matching suffix...
*/
sd.name_len = eoarch - gn->name;
sd.name_len = (size_t)(eoarch - gn->name);
sd.name_end = eoarch;
ln = Lst_Find(ms->parents, SuffSuffIsSuffix, &sd);
@ -2099,7 +2099,7 @@ Suff_SetNull(const char *name)
}
if (suffNull != NULL) {
suffNull->flags &= ~SUFF_NULL;
suffNull->flags &= ~(unsigned)SUFF_NULL;
}
s->flags |= SUFF_NULL;
/*