From: mdw Date: Fri, 21 May 1999 22:09:19 +0000 (+0000) Subject: Take advantage of new dynamic string macros. X-Git-Tag: 1.0.1~6 X-Git-Url: https://git.distorted.org.uk/~mdw/checkpath/commitdiff_plain/724621554ef66263f2530e17fd6d8f4074b6475c Take advantage of new dynamic string macros. --- diff --git a/checkpath.c b/checkpath.c index f470d49..4cf0e8f 100644 --- a/checkpath.c +++ b/checkpath.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: checkpath.c,v 1.2 1999/05/18 20:49:12 mdw Exp $ + * $Id: checkpath.c,v 1.3 1999/05/21 22:07:20 mdw Exp $ * * Check a path for safety * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: checkpath.c,v $ + * Revision 1.3 1999/05/21 22:07:20 mdw + * Take advantage of new dynamic string macros. + * * Revision 1.2 1999/05/18 20:49:12 mdw * Use a dynamic string for reading symlinks. * @@ -84,7 +87,7 @@ enum { static struct elt rootnode = { 0, 0, 0 }; /* Root of the list */ static struct elt *sp; /* Stack pointer for list */ -static dstr d; /* Current path string */ +static dstr d = DSTR_INIT; /* Current path string */ /*----- Main code ---------------------------------------------------------*/ @@ -214,13 +217,12 @@ static void report(struct chkpath *cp, int what, int verbose, /* --- Format the message nicely --- */ if (cp->cp_what & CP_REPORT) { - dstr d; + dstr d = DSTR_INIT; va_list ap; const char *q = msg; size_t n; int e = errno; - dstr_create(&d); va_start(ap, msg); if (verbose > 1) dstr_puts(&d, "[ "); @@ -355,7 +357,7 @@ int path_check(const char *p, struct chkpath *cp) struct stat st; int bad = 0; - /* --- Initialise stack pointer and path string --- */ + /* --- Initialize stack pointer and path string --- */ sp = &rootnode; dstr_destroy(&d); @@ -421,12 +423,11 @@ int path_check(const char *p, struct chkpath *cp) /* --- Handle symbolic links specially --- */ if (S_ISLNK(st.st_mode)) { - dstr buf; + dstr buf = DSTR_INIT; int i; /* --- Resolve the link --- */ - dstr_create(&buf); dstr_ensure(&buf, st.st_size + 1); if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) { report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e"); diff --git a/path.c b/path.c index 4a136b8..657abd1 100644 --- a/path.c +++ b/path.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: path.c,v 1.2 1999/05/18 20:49:12 mdw Exp $ + * $Id: path.c,v 1.3 1999/05/21 22:07:20 mdw Exp $ * * Check a path for safety * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: path.c,v $ + * Revision 1.3 1999/05/21 22:07:20 mdw + * Take advantage of new dynamic string macros. + * * Revision 1.2 1999/05/18 20:49:12 mdw * Use a dynamic string for reading symlinks. * @@ -84,7 +87,7 @@ enum { static struct elt rootnode = { 0, 0, 0 }; /* Root of the list */ static struct elt *sp; /* Stack pointer for list */ -static dstr d; /* Current path string */ +static dstr d = DSTR_INIT; /* Current path string */ /*----- Main code ---------------------------------------------------------*/ @@ -214,13 +217,12 @@ static void report(struct chkpath *cp, int what, int verbose, /* --- Format the message nicely --- */ if (cp->cp_what & CP_REPORT) { - dstr d; + dstr d = DSTR_INIT; va_list ap; const char *q = msg; size_t n; int e = errno; - dstr_create(&d); va_start(ap, msg); if (verbose > 1) dstr_puts(&d, "[ "); @@ -355,7 +357,7 @@ int path_check(const char *p, struct chkpath *cp) struct stat st; int bad = 0; - /* --- Initialise stack pointer and path string --- */ + /* --- Initialize stack pointer and path string --- */ sp = &rootnode; dstr_destroy(&d); @@ -421,12 +423,11 @@ int path_check(const char *p, struct chkpath *cp) /* --- Handle symbolic links specially --- */ if (S_ISLNK(st.st_mode)) { - dstr buf; + dstr buf = DSTR_INIT; int i; /* --- Resolve the link --- */ - dstr_create(&buf); dstr_ensure(&buf, st.st_size + 1); if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) { report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e"); diff --git a/tmpdir.c b/tmpdir.c index 4a2843d..fed0810 100644 --- a/tmpdir.c +++ b/tmpdir.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tmpdir.c,v 1.2 1999/05/19 20:37:28 mdw Exp $ + * $Id: tmpdir.c,v 1.3 1999/05/21 22:07:20 mdw Exp $ * * Choose and check temporary directories * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: tmpdir.c,v $ + * Revision 1.3 1999/05/21 22:07:20 mdw + * Take advantage of new dynamic string macros. + * * Revision 1.2 1999/05/19 20:37:28 mdw * Track gratuitous change in mdwopt interface. * @@ -131,7 +134,7 @@ static char *trytmp(const char *parent, const char *base) "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }; char *p, *q; char *qq; - dstr d; + dstr d = DSTR_INIT; int createflag = 1; /* --- Make sure the parent directory is sane --- * @@ -147,7 +150,6 @@ static char *trytmp(const char *parent, const char *base) /* --- See whether the trivial version will work --- */ - dstr_create(&d); dstr_putf(&d, "%s/%s", parent, base); if (ok(d.buf, &createflag)) goto good;