Re: CVS commit: src/usr.bin/mkdep
Hey Roland - friendly question: I saw this error earlier today and threw in a temporary local fix where I pushed the “const” qualifier deeper (into findcc.[ch]) rather than relax it in mk dep.c. You choose the other route. Did you do that because you expect to have that storage r/w, or something else, rather than enforcing a restriction (that currently seems to hold) further into the code? Signed Curious. On Thu, Aug 19, 2021 at 21:24 Roland Illig wrote: > Module Name:src > Committed By: rillig > Date: Fri Aug 20 04:23:56 UTC 2021 > > Modified Files: > src/usr.bin/mkdep: mkdep.c > > Log Message: > mkdep: fix string constness in call to findcc > > > To generate a diff of this commit: > cvs rdiff -u -r1.45 -r1.46 src/usr.bin/mkdep/mkdep.c > > Please note that diffs are not public domain; they are subject to the > copyright notices on the relevant files. > >
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: rillig Date: Fri Aug 20 04:23:56 UTC 2021 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: mkdep: fix string constness in call to findcc To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: rillig Date: Fri Aug 20 04:23:56 UTC 2021 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: mkdep: fix string constness in call to findcc To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.45 src/usr.bin/mkdep/mkdep.c:1.46 --- src/usr.bin/mkdep/mkdep.c:1.45 Wed May 23 21:20:20 2018 +++ src/usr.bin/mkdep/mkdep.c Fri Aug 20 04:23:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.45 2018/05/23 21:20:20 joerg Exp $ */ +/* $NetBSD: mkdep.c,v 1.46 2021/08/20 04:23:56 rillig Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved."); -__RCSID("$NetBSD: mkdep.c,v 1.45 2018/05/23 21:20:20 joerg Exp $"); +__RCSID("$NetBSD: mkdep.c,v 1.46 2021/08/20 04:23:56 rillig Exp $"); #endif /* not lint */ #include @@ -95,7 +95,9 @@ usage(void) static int run_cc(int argc, char **argv, const char **fname) { - const char *CC, *tmpdir; + static char default_cc[] = DEFAULT_CC; + char *CC; + const char *tmpdir; char * volatile pathname; static char tmpfilename[MAXPATHLEN]; char **args; @@ -104,7 +106,7 @@ run_cc(int argc, char **argv, const char int status; if ((CC = getenv("CC")) == NULL) - CC = DEFAULT_CC; + CC = default_cc; if ((pathname = findcc(CC)) == NULL) if (!setenv("PATH", DEFAULT_PATH, 1)) pathname = findcc(CC);
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: rillig Date: Wed Aug 11 20:48:16 UTC 2021 Modified Files: src/usr.bin/mkdep: findcc.c Log Message: mkdep: document possible undefined behavior If findcc is called with a constant string, as its prototype suggests, the process crashes with a segmentation fault. Luckily, neither mkdep nor lint do that, but the function prototype is nevertheless confusing. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/mkdep/findcc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/findcc.c diff -u src/usr.bin/mkdep/findcc.c:1.6 src/usr.bin/mkdep/findcc.c:1.7 --- src/usr.bin/mkdep/findcc.c:1.6 Sun Sep 4 20:30:06 2011 +++ src/usr.bin/mkdep/findcc.c Wed Aug 11 20:48:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: findcc.c,v 1.6 2011/09/04 20:30:06 joerg Exp $ */ +/* $NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 rillig Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved."); -__RCSID("$NetBSD: findcc.c,v 1.6 2011/09/04 20:30:06 joerg Exp $"); +__RCSID("$NetBSD: findcc.c,v 1.7 2021/08/11 20:48:16 rillig Exp $"); #endif /* not lint */ #include @@ -55,6 +55,11 @@ findcc(const char *progname) char buffer[MAXPATHLEN]; if ((next = strchr(progname, ' ')) != NULL) { + /* + * FIXME: writing to a 'const char *' invokes undefined + * behavior. The call to 'strchr' subtly hides the unconst + * cast from the compiler. + */ *next = '\0'; }
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: rillig Date: Wed Aug 11 20:48:16 UTC 2021 Modified Files: src/usr.bin/mkdep: findcc.c Log Message: mkdep: document possible undefined behavior If findcc is called with a constant string, as its prototype suggests, the process crashes with a segmentation fault. Luckily, neither mkdep nor lint do that, but the function prototype is nevertheless confusing. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/mkdep/findcc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: joerg Date: Wed May 23 21:20:20 UTC 2018 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: deconst -> __UNCONST to avoid null pointer arithmetic To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: joerg Date: Wed May 23 21:20:20 UTC 2018 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: deconst -> __UNCONST to avoid null pointer arithmetic To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.44 src/usr.bin/mkdep/mkdep.c:1.45 --- src/usr.bin/mkdep/mkdep.c:1.44 Tue Jun 16 22:54:10 2015 +++ src/usr.bin/mkdep/mkdep.c Wed May 23 21:20:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.44 2015/06/16 22:54:10 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.45 2018/05/23 21:20:20 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved."); -__RCSID("$NetBSD: mkdep.c,v 1.44 2015/06/16 22:54:10 christos Exp $"); +__RCSID("$NetBSD: mkdep.c,v 1.45 2018/05/23 21:20:20 joerg Exp $"); #endif /* not lint */ #include @@ -82,12 +82,6 @@ static int verbose; static void save_for_optional(const char *, const char *); static size_t write_optional(int, opt_t *, size_t); -static inline void * -deconst(const void *p) -{ - return (const char *)p - (const char *)0 + (char *)0; -} - __dead static void usage(void) { @@ -119,8 +113,8 @@ run_cc(int argc, char **argv, const char if ((args = malloc((argc + 3) * sizeof(char *))) == NULL) err(EXIT_FAILURE, "malloc"); - args[0] = deconst(CC); - args[1] = deconst("-M"); + args[0] = __UNCONST(CC); + args[1] = __UNCONST("-M"); (void)memcpy([2], argv, (argc + 1) * sizeof(char *)); if ((tmpdir = getenv("TMPDIR")) == NULL)
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Tue Mar 5 21:57:47 UTC 2013 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Conditionally include the depend files. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.42 src/usr.bin/mkdep/mkdep.c:1.43 --- src/usr.bin/mkdep/mkdep.c:1.42 Mon Mar 4 20:59:56 2013 +++ src/usr.bin/mkdep/mkdep.c Tue Mar 5 16:57:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.43 2013/03/05 21:57:47 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $); +__RCSID($NetBSD: mkdep.c,v 1.43 2013/03/05 21:57:47 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -328,7 +328,7 @@ main(int argc, char **argv) } else fname = *argv++; if (iflag) { -if (dprintf(dependfile, .include \%s\\n, +if (dprintf(dependfile, .-include \%s\\n, fname) 0) goto wrerror; continue;
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Tue Mar 5 21:57:47 UTC 2013 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Conditionally include the depend files. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Tue Mar 5 01:59:56 UTC 2013 Modified Files: src/usr.bin/mkdep: mkdep.1 mkdep.c Log Message: add -i and -v To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/mkdep/mkdep.1 cvs rdiff -u -r1.41 -r1.42 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.1 diff -u src/usr.bin/mkdep/mkdep.1:1.17 src/usr.bin/mkdep/mkdep.1:1.18 --- src/usr.bin/mkdep/mkdep.1:1.17 Sun Aug 26 18:37:19 2012 +++ src/usr.bin/mkdep/mkdep.1 Mon Mar 4 20:59:56 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: mkdep.1,v 1.17 2012/08/26 22:37:19 jmmv Exp $ +.\ $NetBSD: mkdep.1,v 1.18 2013/03/05 01:59:56 christos Exp $ .\ .\ Copyright (c) 1987, 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ @(#)mkdep.1 8.1 (Berkeley) 6/6/93 .\ -.Dd August 26, 2012 +.Dd March 4, 2013 .Dt MKDEP 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd construct Makefile dependency list .Sh SYNOPSIS .Nm -.Op Fl aDdopq +.Op Fl aDdiopqv .Op Fl f Ar file .Op Fl P Ar prefix .Op Fl s Ar suffixes @@ -80,6 +80,13 @@ depend files into a single file. Write the include file dependencies to .Ar file , instead of the default ``.depend''. +.It Fl i +When +.Fl d +or +.Fl D +is used, instead of inlining the contents of the files to the resulting +depend file, use include statements to include the source dependency files. .It Fl o Add an additional .OPTIONAL line for each dependent file. .It Fl P @@ -118,6 +125,8 @@ Expand each target filename to a list, r suffix with each element of .Ar suffixes . The list of suffixes may be space or comma separated. +.It Fl v +print debugging output. .El .Sh FILES .Bl -tag -width .depend -compact Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.41 src/usr.bin/mkdep/mkdep.c:1.42 --- src/usr.bin/mkdep/mkdep.c:1.41 Sun Aug 26 18:37:19 2012 +++ src/usr.bin/mkdep/mkdep.c Mon Mar 4 20:59:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv Exp $ */ +/* $NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.41 2012/08/26 22:37:19 jmmv Exp $); +__RCSID($NetBSD: mkdep.c,v 1.42 2013/03/05 01:59:56 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -74,12 +74,13 @@ typedef struct suff_list { /* tree of includes for -o processing */ static opt_t *opt; static int width; +static int verbose; #define DEFAULT_PATH _PATH_DEFPATH #define DEFAULT_FILENAME .depend static void save_for_optional(const char *, const char *); -static int write_optional(int, opt_t *, int); +static size_t write_optional(int, opt_t *, size_t); static inline void * deconst(const void *p) @@ -91,7 +92,7 @@ __dead static void usage(void) { (void)fprintf(stderr, - usage: %s [-aDdopq] [-f file] [-P prefix] [-s suffixes] + usage: %s [-aDdiopqv] [-f file] [-P prefix] [-s suffixes] -- [flags] file ...\n, getprogname()); exit(EXIT_FAILURE); @@ -132,6 +133,13 @@ run_cc(int argc, char **argv, const char (void)unlink(tmpfilename); *fname = tmpfilename; + if (verbose) { + char **a; + for (a = args; *a; a++) + printf(%s , *a); + printf(\n); + } + switch (cpid = vfork()) { case 0: (void)dup2(tmpfd, STDOUT_FILENO); @@ -208,7 +216,7 @@ addsuff(suff_list_t **l, const char *s, int main(int argc, char **argv) { - int aflag, dflag, oflag, qflag; + int aflag, dflag, iflag, oflag, qflag; const char *filename; int dependfile; char *buf, *lim, *ptr, *line, *suf, *colon, *eol; @@ -229,6 +237,7 @@ main(int argc, char **argv) aflag = O_WRONLY | O_APPEND | O_CREAT | O_TRUNC; dflag = 0; + iflag = 0; oflag = 0; qflag = 0; filename = DEFAULT_FILENAME; @@ -237,7 +246,7 @@ main(int argc, char **argv) opterr = 0; /* stop getopt() bleating about errors. */ for (;;) { ok_ind = optind; - ch = getopt_long(argc, argv, aDdf:oP:pqRs:, longopt, NULL); + ch = getopt_long(argc, argv, aDdf:ioP:pqRs:v, longopt, NULL); switch (ch) { case -1: ok_ind = optind; @@ -256,6 +265,9 @@ main(int argc, char **argv) case 'f': /* Name of output file */ filename = optarg; continue; + case 'i': + iflag = 1; + continue; case 'o': /* Mark dependent files .OPTIONAL */ oflag = 1; continue; @@ -274,6 +286,9 @@ main(int argc, char **argv) case 's': /* Suffix list */ suffixes = optarg; continue; + case 'v': + verbose = 1; + continue; default: if (dflag) usage(); @@ -302,8 +317,7 @@ main(int argc, char **argv) dependfile = open(filename, aflag, 0666); if (dependfile == -1) - err(EXIT_FAILURE, unable to %s to file %s\n, - aflag
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Tue Mar 5 01:59:56 UTC 2013 Modified Files: src/usr.bin/mkdep: mkdep.1 mkdep.c Log Message: add -i and -v To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/mkdep/mkdep.1 cvs rdiff -u -r1.41 -r1.42 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: joerg Date: Sun Sep 4 20:30:06 UTC 2011 Modified Files: src/usr.bin/mkdep: findcc.c mkdep.c Log Message: ANSIfy + static + __dead To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/mkdep/findcc.c cvs rdiff -u -r1.39 -r1.40 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/findcc.c diff -u src/usr.bin/mkdep/findcc.c:1.5 src/usr.bin/mkdep/findcc.c:1.6 --- src/usr.bin/mkdep/findcc.c:1.5 Sun Apr 12 14:23:30 2009 +++ src/usr.bin/mkdep/findcc.c Sun Sep 4 20:30:06 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: findcc.c,v 1.5 2009/04/12 14:23:30 lukem Exp $ */ +/* $NetBSD: findcc.c,v 1.6 2011/09/04 20:30:06 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: findcc.c,v 1.5 2009/04/12 14:23:30 lukem Exp $); +__RCSID($NetBSD: findcc.c,v 1.6 2011/09/04 20:30:06 joerg Exp $); #endif /* not lint */ #include sys/param.h @@ -49,8 +49,7 @@ #include findcc.h char * -findcc(progname) - const char *progname; +findcc(const char *progname) { char *path, *dir, *next; char buffer[MAXPATHLEN]; Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.39 src/usr.bin/mkdep/mkdep.c:1.40 --- src/usr.bin/mkdep/mkdep.c:1.39 Thu Jun 30 20:09:42 2011 +++ src/usr.bin/mkdep/mkdep.c Sun Sep 4 20:30:06 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.39 2011/06/30 20:09:42 wiz Exp $ */ +/* $NetBSD: mkdep.c,v 1.40 2011/09/04 20:30:06 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.39 2011/06/30 20:09:42 wiz Exp $); +__RCSID($NetBSD: mkdep.c,v 1.40 2011/09/04 20:30:06 joerg Exp $); #endif /* not lint */ #include sys/mman.h @@ -72,8 +72,8 @@ } suff_list_t; /* tree of includes for -o processing */ -opt_t *opt; -int width; +static opt_t *opt; +static int width; #define DEFAULT_PATH _PATH_DEFPATH #define DEFAULT_FILENAME .depend @@ -81,14 +81,13 @@ static void save_for_optional(const char *, const char *); static int write_optional(int, opt_t *, int); - static inline void * deconst(const void *p) { return (const char *)p - (const char *)0 + (char *)0; } -static void +__dead static void usage(void) { (void)fprintf(stderr,
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: joerg Date: Sun Sep 4 20:30:06 UTC 2011 Modified Files: src/usr.bin/mkdep: findcc.c mkdep.c Log Message: ANSIfy + static + __dead To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/mkdep/findcc.c cvs rdiff -u -r1.39 -r1.40 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Mon May 30 22:52:13 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Handle the empty suffix properly. Convert suffix list to a list from an array and don't have limits in the suffix length. Also don't require that suffixes have a single dot. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.36 src/usr.bin/mkdep/mkdep.c:1.37 --- src/usr.bin/mkdep/mkdep.c:1.36 Sun Apr 17 18:35:22 2011 +++ src/usr.bin/mkdep/mkdep.c Mon May 30 18:52:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $); +__RCSID($NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -65,9 +65,10 @@ char name[4]; }; -typedef struct { +typedef struct suff_list { size_t len; - char suff[12]; + char *suff; + struct suff_list *next; } suff_list_t; /* tree of includes for -o processing */ @@ -125,10 +126,9 @@ tmpdir = _PATH_TMP; (void)snprintf(tmpfilename, sizeof (tmpfilename), %s/%s, tmpdir, mkdepXX); - if ((tmpfd = mkstemp(tmpfilename)) 0) { - warn(unable to create temporary file %s, tmpfilename); - exit(EXIT_FAILURE); - } + if ((tmpfd = mkstemp(tmpfilename)) 0) + err(EXIT_FAILURE, Unable to create temporary file %s, + tmpfilename); (void)unlink(tmpfilename); *fname = tmpfilename; @@ -189,6 +189,22 @@ { NULL, 0, NULL, '\0' }, }; +static void +addsuff(suff_list_t **l, const char *s, size_t len) +{ + suff_list_t *p = calloc(1, sizeof(*p)); + if (p == NULL) + err(1, calloc); + p-suff = malloc(len + 1); + if (p-suff == NULL) + err(1, malloc); + memcpy(p-suff, s, len); + p-suff[len] = '\0'; + p-len = len; + p-next = *l; + *l = p; +} + int main(int argc, char **argv) { @@ -269,22 +285,15 @@ usage(); if (suffixes != NULL) { - /* parse list once and save names and lengths */ - /* allocate an extra entry to mark end of list */ - for (sz = 1, s = suffixes; *s != 0; s++) - if (*s == '.') - sz++; - suff_list = calloc(sz, sizeof *suff_list); - if (suff_list == NULL) - err(2, malloc); - sl = suff_list; - for (s = suffixes; (s = strchr(s, '.')); s += sz, sl++) { - sz = strcspn(s, , ); - if (sz sizeof sl-suff) -errx(2, suffix too long); - sl-len = sz; - memcpy(sl-suff, s, sz); - } + if (*suffixes) { + for (s = suffixes; (sz = strcspn(s, , )) != 0;) { +addsuff(suff_list, s, sz); +s += sz; +while (*s strchr(, , *s)) + s++; + } + } else + addsuff(suff_list, , 0); } dependfile = open(filename, aflag, 0666); @@ -368,8 +377,10 @@ errx(EXIT_FAILURE, Corrupted file `%s', fname); /* Then look for any valid suffix */ -for (sl = suff_list; sl-len != 0; sl++) { - if (!memcmp(suf - sl-len, sl-suff, +for (sl = suff_list; sl != NULL; +sl = sl-next) { + if (sl-len + !memcmp(suf - sl-len, sl-suff, sl-len)) break; } @@ -377,7 +388,7 @@ * Not found, check for .o, since the * original file will have it. */ -if (sl-len == 0 suff_list-len != 0) { +if (sl == NULL) { if (memcmp(suf - 2, .o, 2) == 0) slen = 2; else @@ -387,7 +398,8 @@ } if (suff_list != NULL slen != 0) { suf -= slen; -for (sl = suff_list; sl-len != 0; sl++) { +for (sl = suff_list; sl != NULL; sl = sl-next) +{ if (sl != suff_list) write(dependfile, , 1); write(dependfile, line, suf - line);
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: enami Date: Tue May 31 02:34:32 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Don't touch before the mmap'ed region. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.37 src/usr.bin/mkdep/mkdep.c:1.38 --- src/usr.bin/mkdep/mkdep.c:1.37 Mon May 30 22:52:12 2011 +++ src/usr.bin/mkdep/mkdep.c Tue May 31 02:34:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.38 2011/05/31 02:34:32 enami Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $); +__RCSID($NetBSD: mkdep.c,v 1.38 2011/05/31 02:34:32 enami Exp $); #endif /* not lint */ #include sys/mman.h @@ -379,7 +379,7 @@ /* Then look for any valid suffix */ for (sl = suff_list; sl != NULL; sl = sl-next) { - if (sl-len + if (sl-len buf = suf - sl-len !memcmp(suf - sl-len, sl-suff, sl-len)) break;
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Mon May 30 22:52:13 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Handle the empty suffix properly. Convert suffix list to a list from an array and don't have limits in the suffix length. Also don't require that suffixes have a single dot. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: enami Date: Tue May 31 02:34:32 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Don't touch before the mmap'ed region. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/usr.bin/mkdep
On Sun, Apr 17, 2011 at 06:35:22PM -0400, Christos Zoulas wrote: Module Name: src Committed By: christos Date: Sun Apr 17 22:35:22 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Recognize --sysroot but don't document it or do anything about it for now. This shouldn't be needed at all. It should have fallen into the default case and as such be passed down without modifications. Joerg
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Sun Apr 17 22:35:22 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Recognize --sysroot but don't document it or do anything about it for now. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.35 src/usr.bin/mkdep/mkdep.c:1.36 --- src/usr.bin/mkdep/mkdep.c:1.35 Wed May 26 14:07:34 2010 +++ src/usr.bin/mkdep/mkdep.c Sun Apr 17 18:35:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.35 2010/05/26 18:07:34 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.35 2010/05/26 18:07:34 christos Exp $); +__RCSID($NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -46,6 +46,7 @@ #include ctype.h #include err.h #include fcntl.h +#include getopt.h #include locale.h #include paths.h #include stdio.h @@ -183,6 +184,11 @@ return fbuf; } +static struct option longopt[] = { + { sysroot, 1, NULL, 'R' }, + { NULL, 0, NULL, '\0' }, +}; + int main(int argc, char **argv) { @@ -214,7 +220,7 @@ opterr = 0; /* stop getopt() bleating about errors. */ for (;;) { ok_ind = optind; - ch = getopt(argc, argv, aDdf:opqs:); + ch = getopt_long(argc, argv, aDdf:opqRs:, longopt, NULL); switch (ch) { case -1: ok_ind = optind; @@ -242,6 +248,9 @@ case 'q': /* Quiet */ qflag = 1; continue; + case 'R': + /* sysroot = optarg */ + continue; case 's': /* Suffix list */ suffixes = optarg; continue;
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Sun Apr 17 22:35:22 UTC 2011 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: Recognize --sysroot but don't document it or do anything about it for now. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: dholland Date: Fri Oct 15 05:46:48 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.1 Log Message: Per PR 19359 note that mkdep doesn't handle all make metacharacters correctly; in particular, filenames containing '#' cause trouble, although '$' seems to be ok. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/mkdep/mkdep.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.1 diff -u src/usr.bin/mkdep/mkdep.1:1.14 src/usr.bin/mkdep/mkdep.1:1.15 --- src/usr.bin/mkdep/mkdep.1:1.14 Mon Dec 12 22:49:37 2005 +++ src/usr.bin/mkdep/mkdep.1 Fri Oct 15 05:46:48 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: mkdep.1,v 1.14 2005/12/12 22:49:37 wiz Exp $ +.\ $NetBSD: mkdep.1,v 1.15 2010/10/15 05:46:48 dholland Exp $ .\ .\ Copyright (c) 1987, 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ @(#)mkdep.1 8.1 (Berkeley) 6/6/93 .\ -.Dd December 12, 2005 +.Dd October 15, 2010 .Dt MKDEP 1 .Os .Sh NAME @@ -124,3 +124,11 @@ .Nm command appeared in .Bx 4.3 Tahoe . +.Sh BUGS +Some characters special to +.Xr make 1 , +most notably the comment character, are not escaped correctly if they +appear in file names. +This can lead to unparseable output or silently cause dependencies to +be lost. +.\ (This problem is actually in gcc -M.)
Re: CVS commit: src/usr.bin/mkdep
On Wed, May 26, 2010 at 02:07:34PM -0400, Christos Zoulas wrote: Module Name: src Committed By: christos Date: Wed May 26 18:07:34 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: fix empty suffix case. Thanks again. But still not quite right, the .o extension remains while according to the man page it should be removed. nj...@lanfeust [~] mkdep -p -f main.dep main.c nj...@lanfeust [~] cat main.dep main.o: main.c nj...@lanfeust [~] mkdep -s '' -f main.dep main.c nj...@lanfeust [~] cat main.dep main.o: main.c -- Nicolas Joly Biological Software and Databanks. Institut Pasteur, Paris.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Wed May 26 15:04:40 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: PR/43364: Nicolas Joly: mkdep(1) wrong target names when suffix list miss .o To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.33 src/usr.bin/mkdep/mkdep.c:1.34 --- src/usr.bin/mkdep/mkdep.c:1.33 Sun Apr 12 10:23:30 2009 +++ src/usr.bin/mkdep/mkdep.c Wed May 26 11:04:40 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.33 2009/04/12 14:23:30 lukem Exp $ */ +/* $NetBSD: mkdep.c,v 1.34 2010/05/26 15:04:40 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.33 2009/04/12 14:23:30 lukem Exp $); +__RCSID($NetBSD: mkdep.c,v 1.34 2010/05/26 15:04:40 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -193,6 +193,7 @@ int ok_ind, ch; size_t sz; int fd; + size_t slen; const char *fname; const char *suffixes = NULL, *s; suff_list_t *suff_list = NULL, *sl; @@ -363,9 +364,20 @@ sl-len)) break; } +/* + * Not found, check for .o, since the + * original file will have it. + */ +if (sl-len == 0) { + if (memcmp(suf - 2, .o, 2) == 0) + slen = 2; + else + slen = 0; +} else + slen = sl-len; } - if (suff_list != NULL sl-len != 0) { -suf -= sl-len; + if (suff_list != NULL slen != 0) { +suf -= slen; for (sl = suff_list; sl-len != 0; sl++) { if (sl != suff_list) write(dependfile, , 1);
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Wed May 26 18:07:34 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: fix empty suffix case. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/mkdep/mkdep.c diff -u src/usr.bin/mkdep/mkdep.c:1.34 src/usr.bin/mkdep/mkdep.c:1.35 --- src/usr.bin/mkdep/mkdep.c:1.34 Wed May 26 11:04:40 2010 +++ src/usr.bin/mkdep/mkdep.c Wed May 26 14:07:34 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: mkdep.c,v 1.34 2010/05/26 15:04:40 christos Exp $ */ +/* $NetBSD: mkdep.c,v 1.35 2010/05/26 18:07:34 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT(@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\ All rights reserved.); -__RCSID($NetBSD: mkdep.c,v 1.34 2010/05/26 15:04:40 christos Exp $); +__RCSID($NetBSD: mkdep.c,v 1.35 2010/05/26 18:07:34 christos Exp $); #endif /* not lint */ #include sys/mman.h @@ -269,7 +269,7 @@ if (suff_list == NULL) err(2, malloc); sl = suff_list; - for (s = suffixes; (s = strchr(s, '.')); s += sz, sl++ ) { + for (s = suffixes; (s = strchr(s, '.')); s += sz, sl++) { sz = strcspn(s, , ); if (sz sizeof sl-suff) errx(2, suffix too long); @@ -368,7 +368,7 @@ * Not found, check for .o, since the * original file will have it. */ -if (sl-len == 0) { +if (sl-len == 0 suff_list-len != 0) { if (memcmp(suf - 2, .o, 2) == 0) slen = 2; else
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Wed May 26 15:04:40 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: PR/43364: Nicolas Joly: mkdep(1) wrong target names when suffix list miss .o To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/mkdep
Module Name:src Committed By: christos Date: Wed May 26 18:07:34 UTC 2010 Modified Files: src/usr.bin/mkdep: mkdep.c Log Message: fix empty suffix case. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/mkdep/mkdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.