diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-14 01:34:36 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-14 01:34:36 +0000 |
commit | 78d690b47a336b8bcd3499e23f5dea0c6ed41974 (patch) | |
tree | cafaae88066e64d99b18606b48ea90621aab6fb3 /usr.bin/rdist/expand.c | |
parent | 968f100607f98e659a5ce90c71e5949d09d4898a (diff) |
o Sync w/ freerdist 0.92 minus the compress option
o KNF and ANSIfy the function headers
Sparse file support is currently a no-op since it didn't work.
Proper sparse file support will be added later.
Diffstat (limited to 'usr.bin/rdist/expand.c')
-rw-r--r-- | usr.bin/rdist/expand.c | 110 |
1 files changed, 52 insertions, 58 deletions
diff --git a/usr.bin/rdist/expand.c b/usr.bin/rdist/expand.c index 3ecd9eb8908..e72f25f7725 100644 --- a/usr.bin/rdist/expand.c +++ b/usr.bin/rdist/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: expand.c,v 1.10 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,23 +33,24 @@ * SUCH DAMAGE. */ +#include "defs.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: expand.c,v 6.18 1998/03/24 00:37:10 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: expand.c,v 1.4 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: expand.c,v 1.10 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)expand.c 5.2 (Berkeley) 3/28/86"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)expand.c 5.2 (Berkeley) 3/28/86"; -char copyright[] = +char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ -#include "defs.h" #define MAXEARGS 2048 #define LC '{' @@ -71,16 +72,15 @@ char *entp; char **sortbase; char *argvbuf[MAXEARGS]; -static int argcmp(); -void expstr(); -void expsh(); -void matchdir(); - #define sort() qsort((char *)sortbase, &eargv[eargc] - sortbase, \ sizeof(*sortbase), argcmp), sortbase = &eargv[eargc] -static void Cat(s1, s2) /* quote in s1 and s2 */ - u_char *s1, *s2; +static void Cat(u_char *, u_char *); +static void addpath(int); +static int argcmp(const void *, const void *); + +static void +Cat(u_char *s1, u_char *s2) /* quote in s1 and s2 */ { char *cp; int len = strlen((char *)s1) + strlen((char *)s2) + 2; @@ -96,16 +96,16 @@ static void Cat(s1, s2) /* quote in s1 and s2 */ do { if (*s1 == QUOTECHAR) s1++; - } while ((*cp++ = *s1++)); + } while ((*cp++ = *s1++) != '\0'); cp--; do { if (*s2 == QUOTECHAR) s2++; - } while ((*cp++ = *s2++)); + } while ((*cp++ = *s2++) != '\0'); } -static void addpath(c) - char c; +static void +addpath(int c) { if (pathp >= lastpathp) { yyerror("Pathname too long"); @@ -126,9 +126,7 @@ static void addpath(c) * Major portions of this were snarfed from csh/sh.glob.c. */ struct namelist * -expand(list, wh) /* quote in list->n_name */ - struct namelist *list; - int wh; +expand(struct namelist *list, int wh) /* quote in list->n_name */ { struct namelist *nl, *prev; int n; @@ -177,9 +175,8 @@ expand(list, wh) /* quote in list->n_name */ * xstrchr() is a version of strchr() that * handles u_char buffers. */ -u_char *xstrchr(str, ch) - u_char *str; - int ch; +u_char * +xstrchr(u_char *str, int ch) { u_char *cp; @@ -190,8 +187,8 @@ u_char *xstrchr(str, ch) return(NULL); } -void expstr(s) - u_char *s; +void +expstr(u_char *s) { u_char *cp, *cp1; struct namelist *tp; @@ -208,7 +205,7 @@ void expstr(s) * Remove quoted characters */ if (IS_ON(which, E_VARS)) { - if ((int)strlen((char *)s) > sizeof(varbuff)) { + if (strlen((char *)s) > sizeof(varbuff)) { yyerror("Variable is too large."); return; } @@ -261,13 +258,13 @@ void expstr(s) *tail = savec; if (tp != NULL) { for (; tp != NULL; tp = tp->n_next) { - (void) snprintf((char *)ebuf, sizeof ebuf, - "%s%s%s", s, tp->n_name, tail); + (void) snprintf((char *)ebuf, sizeof(ebuf), + "%s%s%s", s, tp->n_name, tail); expstr(ebuf); } return; } - (void) snprintf((char *)ebuf, sizeof ebuf, "%s%s", s, tail); + (void) snprintf((char *)ebuf, sizeof(ebuf), "%s%s", s, tail); expstr(ebuf); return; } @@ -292,9 +289,9 @@ void expstr(s) if (pw == NULL || strcmp(pw->pw_name, (char *)ebuf+1) != 0) { if ((pw = getpwnam((char *)ebuf+1)) == NULL) { - strlcat((char *)ebuf, - ": unknown user name", - sizeof(ebuf)); + strlcat((char *)ebuf, + ": unknown user name", + sizeof(ebuf)); yyerror((char *)ebuf+1); return; } @@ -302,8 +299,8 @@ void expstr(s) cp1 = (u_char *)pw->pw_dir; s = cp; } - for (cp = (u_char *)path; (*cp++ = *cp1++); ) - ; + for (cp = (u_char *)path; (*cp++ = *cp1++) != '\0'; ) + continue; tpathp = pathp = (char *)cp - 1; } else { tpathp = pathp = path; @@ -327,9 +324,9 @@ void expstr(s) } static int -argcmp(a1, a2) - char **a1, **a2; +argcmp(const void *v1, const void *v2) { + const char *const *a1 = v1, *const *a2 = v2; return (strcmp(*a1, *a2)); } @@ -338,8 +335,8 @@ argcmp(a1, a2) * If there are any Shell meta characters in the name, * expand into a list, after searching directory */ -void expsh(s) /* quote in s */ - u_char *s; +void +expsh(u_char *s) /* quote in s */ { u_char *cp, *oldcp; char *spathp; @@ -376,8 +373,8 @@ endit: *pathp = CNULL; } -void matchdir(pattern) /* quote in pattern */ - char *pattern; +void +matchdir(char *pattern) /* quote in pattern */ { struct stat stb; DIRENTRY *dp; @@ -389,7 +386,7 @@ void matchdir(pattern) /* quote in pattern */ return; goto patherr2; } - if (fstat(dirp->dd_fd, &stb) < 0) + if (fstat(dirfd(dirp), &stb) < 0) goto patherr1; if (!S_ISDIR(stb.st_mode)) { errno = ENOTDIR; @@ -418,8 +415,7 @@ patherr2: } int -execbrc(p, s) /* quote in p */ - u_char *p, *s; +execbrc(u_char *p, u_char *s) /* quote in p */ { u_char restbuf[BUFSIZ + 2]; u_char *pe, *pm, *pl; @@ -482,9 +478,9 @@ doit: *pm = 0; *lm = 0; (void) strlcat((char *)restbuf, (char *)pl, - sizeof restbuf); + sizeof(restbuf)); (void) strlcat((char *)restbuf, (char *)pe + 1, - sizeof restbuf); + sizeof(restbuf)); *pm = savec; if (s == 0) { spathp = pathp; @@ -512,8 +508,7 @@ doit: } int -match(s, p) /* quote in p */ - char *s, *p; +match(char *s, char *p) /* quote in p */ { int c; char *sentp; @@ -530,9 +525,7 @@ match(s, p) /* quote in p */ } int -amatch(s, p) /* quote in p */ - char *s; - u_char *p; +amatch(char *s, u_char *p) /* quote in p */ { int scc; int ok, lc; @@ -551,7 +544,7 @@ amatch(s, p) /* quote in p */ case '[': ok = 0; lc = 077777; - while ((cc = *p++)) { + while ((cc = *p++) != '\0') { if (cc == ']') { if (ok) break; @@ -605,17 +598,18 @@ slash: while (*s) addpath(*s++); addpath('/'); - if (stat(path, &stb) == 0 && S_ISDIR(stb.st_mode)) + if (stat(path, &stb) == 0 && S_ISDIR(stb.st_mode)) { if (*p == CNULL) { - if (which & E_TILDE) + if (which & E_TILDE) { Cat((u_char *)path, (u_char *)""); - else + } else { Cat((u_char *)tilde, (u_char *)tpathp); - } else { + } + } else expsh(p); - } + } pathp = spathp; *pathp = CNULL; return (0); |