Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/config Avoid needlessly recreating the Makefile, io...



details:   https://anonhg.NetBSD.org/src/rev/c8e33e59fb74
branches:  trunk
changeset: 522217:c8e33e59fb74
user:      atatat <atatat%NetBSD.org@localhost>
date:      Tue Feb 12 23:20:11 2002 +0000

description:
Avoid needlessly recreating the Makefile, ioconf.c, or any of the
swap*.c files if they haven't changed from the last time config was
run, so that less stuff will need to be rebuilt (ie, assym.h, upon
which many other things depend) each time config is rerun.

diffstat:

 usr.sbin/config/defs.h       |   3 ++-
 usr.sbin/config/mkheaders.c  |  17 ++++++++---------
 usr.sbin/config/mkioconf.c   |  11 ++++++++---
 usr.sbin/config/mkmakefile.c |  14 ++++++++++----
 usr.sbin/config/mkswap.c     |  12 +++++++++---
 5 files changed, 37 insertions(+), 20 deletions(-)

diffs (201 lines):

diff -r 057da164a2d7 -r c8e33e59fb74 usr.sbin/config/defs.h
--- a/usr.sbin/config/defs.h    Tue Feb 12 23:11:58 2002 +0000
+++ b/usr.sbin/config/defs.h    Tue Feb 12 23:20:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.2 2002/01/31 22:44:01 tv Exp $      */
+/*     $NetBSD: defs.h,v 1.3 2002/02/12 23:20:11 atatat Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -425,6 +425,7 @@
 
 /* mkheaders.c */
 int    mkheaders(void);
+int    moveifchanged(const char *, const char *);
 
 /* mkioconf.c */
 int    mkioconf(void);
diff -r 057da164a2d7 -r c8e33e59fb74 usr.sbin/config/mkheaders.c
--- a/usr.sbin/config/mkheaders.c       Tue Feb 12 23:11:58 2002 +0000
+++ b/usr.sbin/config/mkheaders.c       Tue Feb 12 23:20:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkheaders.c,v 1.30 2002/01/29 10:20:37 tv Exp $        */
+/*     $NetBSD: mkheaders.c,v 1.31 2002/02/12 23:20:11 atatat Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -60,7 +60,6 @@
 static int locators_print(const char *, void *, void *);
 static int defopts_print(const char *, void *, void *);
 static char *cntname(const char *);
-static int cmphdr(const char *, const char *);
 static int fprintcnt(FILE *, struct nvlist *);
 static int fprintstr(FILE *, const char *);
 
@@ -117,7 +116,7 @@
        if (fclose(fp) == EOF)
                return (herr("clos", tfname, NULL));
 
-       return (cmphdr(tfname, nfname));
+       return (moveifchanged(tfname, nfname));
 }
 
 /*
@@ -189,7 +188,7 @@
        if (fclose(fp) == EOF)
                return (herr("clos", tfname, NULL));
 
-       return (cmphdr(tfname, name));
+       return (moveifchanged(tfname, name));
 
  bad:
        return (herr("writ", tfname, fp));
@@ -284,7 +283,7 @@
                return (herr("clos", tfname, NULL));
        if (rval)
                return (rval);
-       return (cmphdr(tfname, "locators.h"));
+       return (moveifchanged(tfname, "locators.h"));
 }
 
 /*
@@ -313,15 +312,15 @@
        if (fclose(tfp) == EOF)
                return (herr("clos", tfname, NULL));
 
-       return (cmphdr(tfname, "ioconf.h"));
+       return (moveifchanged(tfname, "ioconf.h"));
 }
 
 /*
- * Compare two header files.  If nfname doesn't exist, or is different from
+ * Compare two files.  If nfname doesn't exist, or is different from
  * tfname, move tfname to nfname.  Otherwise, delete tfname.
  */
-static int
-cmphdr(const char *tfname, const char *nfname)
+int
+moveifchanged(const char *tfname, const char *nfname)
 {
        char tbuf[BUFSIZ], nbuf[BUFSIZ];
        FILE *tfp, *nfp;
diff -r 057da164a2d7 -r c8e33e59fb74 usr.sbin/config/mkioconf.c
--- a/usr.sbin/config/mkioconf.c        Tue Feb 12 23:11:58 2002 +0000
+++ b/usr.sbin/config/mkioconf.c        Tue Feb 12 23:20:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkioconf.c,v 1.57 2002/01/29 10:20:37 tv Exp $ */
+/*     $NetBSD: mkioconf.c,v 1.58 2002/02/12 23:20:11 atatat Exp $     */
 
 /*
  * Copyright (c) 1992, 1993
@@ -84,7 +84,7 @@
        int v;
 
        qsort(packed, npacked, sizeof *packed, cforder);
-       if ((fp = fopen("ioconf.c", "w")) == NULL) {
+       if ((fp = fopen("ioconf.c.tmp", "w")) == NULL) {
                (void)fprintf(stderr, "config: cannot write ioconf.c: %s\n",
                    strerror(errno));
                return (1);
@@ -98,10 +98,15 @@
                            "config: error writing ioconf.c: %s\n",
                            strerror(errno));
                (void)fclose(fp);
-               /* (void)unlink("ioconf.c"); */
+               /* (void)unlink("ioconf.c.tmp"); */
                return (1);
        }
        (void)fclose(fp);
+       if (moveifchanged("ioconf.c.tmp", "ioconf.c") != 0) {
+               (void)fprintf(stderr, "config: error renaming ioconf.c: %s\n",
+                   strerror(errno));
+               return (1);
+       }
        return (0);
 }
 
diff -r 057da164a2d7 -r c8e33e59fb74 usr.sbin/config/mkmakefile.c
--- a/usr.sbin/config/mkmakefile.c      Tue Feb 12 23:11:58 2002 +0000
+++ b/usr.sbin/config/mkmakefile.c      Tue Feb 12 23:20:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkmakefile.c,v 1.53 2002/01/29 10:20:37 tv Exp $       */
+/*     $NetBSD: mkmakefile.c,v 1.54 2002/02/12 23:20:11 atatat Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -97,7 +97,7 @@
                free(ifname);
                return (1);
        }
-       if ((ofp = fopen("Makefile", "w")) == NULL) {
+       if ((ofp = fopen("Makefile.tmp", "w")) == NULL) {
                (void)fprintf(stderr, "config: cannot write Makefile: %s\n",
                    strerror(errno));
                free(ifname);
@@ -138,7 +138,7 @@
                    "config: error reading %s (at line %d): %s\n",
                    ifname, lineno, strerror(errno));
                goto bad;
-               /* (void)unlink("Makefile"); */
+               /* (void)unlink("Makefile.tmp"); */
                free(ifname);
                return (1);
        }
@@ -147,6 +147,12 @@
                goto wrerror;
        }
        (void)fclose(ifp);
+       if (moveifchanged("Makefile.tmp", "Makefile") != 0) {
+               (void)fprintf(stderr,
+                   "config: error renaming Makefile: %s\n",
+                   strerror(errno));
+               goto bad;
+       }
        free(ifname);
        return (0);
 wrerror:
@@ -155,7 +161,7 @@
 bad:
        if (ofp != NULL)
                (void)fclose(ofp);
-       /* (void)unlink("Makefile"); */
+       /* (void)unlink("Makefile.tmp"); */
        free(ifname);
        return (1);
 }
diff -r 057da164a2d7 -r c8e33e59fb74 usr.sbin/config/mkswap.c
--- a/usr.sbin/config/mkswap.c  Tue Feb 12 23:11:58 2002 +0000
+++ b/usr.sbin/config/mkswap.c  Tue Feb 12 23:20:11 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkswap.c,v 1.12 2002/01/29 10:20:37 tv Exp $   */
+/*     $NetBSD: mkswap.c,v 1.13 2002/02/12 23:20:11 atatat Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -86,11 +86,12 @@
 {
        struct nvlist *nv;
        FILE *fp;
-       char fname[200];
+       char fname[200], tname[200];
        char specinfo[200];
 
        (void)sprintf(fname, "swap%s.c", cf->cf_name);
-       if ((fp = fopen(fname, "w")) == NULL) {
+       (void)sprintf(tname, "swap%s.c.tmp", cf->cf_name);
+       if ((fp = fopen(tname, "w")) == NULL) {
                (void)fprintf(stderr, "config: cannot write %s: %s\n",
                    fname, strerror(errno));
                return (1);
@@ -147,6 +148,11 @@
                fp = NULL;
                goto wrerror;
        }
+       if (moveifchanged(tname, fname) != 0) {
+               (void)fprintf(stderr, "config: error renaming %s: %s\n",
+                   fname, strerror(errno));
+               return (1);
+       }
        return (0);
 wrerror:
        (void)fprintf(stderr, "config: error writing %s: %s\n",



Home | Main Index | Thread Index | Old Index