diff options
author | Damien Miller <djm@mindrot.org> | 2001-04-14 00:22:33 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-04-14 00:22:33 +1000 |
commit | 6e77a538ca63f2ecbab74656839e77084a2db425 (patch) | |
tree | 03dd15234a4ccc802fba338e7b1e54e3a9e71b94 | |
parent | 92d4a020011565d766153cbf85210157c33c541c (diff) |
- Sync with OpenBSD glob.c, strlcat.c and vis.c changes
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | openbsd-compat/glob.c | 65 | ||||
-rw-r--r-- | openbsd-compat/strlcat.c | 11 | ||||
-rw-r--r-- | openbsd-compat/vis.c | 16 |
4 files changed, 53 insertions, 44 deletions
@@ -1,3 +1,6 @@ | |||
1 | 20010414 | ||
2 | - Sync with OpenBSD glob.c, strlcat.c and vis.c changes | ||
3 | |||
1 | 20010413 | 4 | 20010413 |
2 | - OpenBSD CVS Sync | 5 | - OpenBSD CVS Sync |
3 | - markus@cvs.openbsd.org 2001/04/12 14:29:09 | 6 | - markus@cvs.openbsd.org 2001/04/12 14:29:09 |
@@ -5049,4 +5052,4 @@ | |||
5049 | - Wrote replacements for strlcpy and mkdtemp | 5052 | - Wrote replacements for strlcpy and mkdtemp |
5050 | - Released 1.0pre1 | 5053 | - Released 1.0pre1 |
5051 | 5054 | ||
5052 | $Id: ChangeLog,v 1.1107 2001/04/13 04:44:37 mouring Exp $ | 5055 | $Id: ChangeLog,v 1.1108 2001/04/13 14:22:33 djm Exp $ |
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 677a8a10c..4f70149cb 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -56,7 +56,7 @@ get_arg_max() | |||
56 | #if 0 | 56 | #if 0 |
57 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; | 57 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; |
58 | #else | 58 | #else |
59 | static char rcsid[] = "$OpenBSD: glob.c,v 1.14 2001/03/28 20:54:19 millert Exp $"; | 59 | static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $"; |
60 | #endif | 60 | #endif |
61 | #endif /* LIBC_SCCS and not lint */ | 61 | #endif /* LIBC_SCCS and not lint */ |
62 | 62 | ||
@@ -137,7 +137,7 @@ typedef char Char; | |||
137 | 137 | ||
138 | 138 | ||
139 | static int compare __P((const void *, const void *)); | 139 | static int compare __P((const void *, const void *)); |
140 | static int g_Ctoc __P((const Char *, char *, char *)); | 140 | static int g_Ctoc __P((const Char *, char *, u_int)); |
141 | static int g_lstat __P((Char *, struct stat *, glob_t *)); | 141 | static int g_lstat __P((Char *, struct stat *, glob_t *)); |
142 | static DIR *g_opendir __P((Char *, glob_t *)); | 142 | static DIR *g_opendir __P((Char *, glob_t *)); |
143 | static Char *g_strchr __P((Char *, int)); | 143 | static Char *g_strchr __P((Char *, int)); |
@@ -193,8 +193,7 @@ glob(pattern, flags, errfunc, pglob) | |||
193 | --patnext; | 193 | --patnext; |
194 | } | 194 | } |
195 | *bufnext++ = c | M_PROTECT; | 195 | *bufnext++ = c | M_PROTECT; |
196 | } | 196 | } else |
197 | else | ||
198 | *bufnext++ = c; | 197 | *bufnext++ = c; |
199 | } | 198 | } |
200 | *bufnext = EOS; | 199 | *bufnext = EOS; |
@@ -248,7 +247,7 @@ globexp2(ptr, pattern, pglob, rv) | |||
248 | 247 | ||
249 | /* copy part up to the brace */ | 248 | /* copy part up to the brace */ |
250 | for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) | 249 | for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) |
251 | continue; | 250 | ; |
252 | *lm = EOS; | 251 | *lm = EOS; |
253 | ls = lm; | 252 | ls = lm; |
254 | 253 | ||
@@ -257,7 +256,7 @@ globexp2(ptr, pattern, pglob, rv) | |||
257 | if (*pe == LBRACKET) { | 256 | if (*pe == LBRACKET) { |
258 | /* Ignore everything between [] */ | 257 | /* Ignore everything between [] */ |
259 | for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) | 258 | for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) |
260 | continue; | 259 | ; |
261 | if (*pe == EOS) { | 260 | if (*pe == EOS) { |
262 | /* | 261 | /* |
263 | * We could not find a matching RBRACKET. | 262 | * We could not find a matching RBRACKET. |
@@ -265,8 +264,7 @@ globexp2(ptr, pattern, pglob, rv) | |||
265 | */ | 264 | */ |
266 | pe = pm; | 265 | pe = pm; |
267 | } | 266 | } |
268 | } | 267 | } else if (*pe == LBRACE) |
269 | else if (*pe == LBRACE) | ||
270 | i++; | 268 | i++; |
271 | else if (*pe == RBRACE) { | 269 | else if (*pe == RBRACE) { |
272 | if (i == 0) | 270 | if (i == 0) |
@@ -285,7 +283,7 @@ globexp2(ptr, pattern, pglob, rv) | |||
285 | case LBRACKET: | 283 | case LBRACKET: |
286 | /* Ignore everything between [] */ | 284 | /* Ignore everything between [] */ |
287 | for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) | 285 | for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) |
288 | continue; | 286 | ; |
289 | if (*pm == EOS) { | 287 | if (*pm == EOS) { |
290 | /* | 288 | /* |
291 | * We could not find a matching RBRACKET. | 289 | * We could not find a matching RBRACKET. |
@@ -311,13 +309,14 @@ globexp2(ptr, pattern, pglob, rv) | |||
311 | else { | 309 | else { |
312 | /* Append the current string */ | 310 | /* Append the current string */ |
313 | for (lm = ls; (pl < pm); *lm++ = *pl++) | 311 | for (lm = ls; (pl < pm); *lm++ = *pl++) |
314 | continue; | 312 | ; |
313 | |||
315 | /* | 314 | /* |
316 | * Append the rest of the pattern after the | 315 | * Append the rest of the pattern after the |
317 | * closing brace | 316 | * closing brace |
318 | */ | 317 | */ |
319 | for (pl = pe + 1; (*lm++ = *pl++) != EOS;) | 318 | for (pl = pe + 1; (*lm++ = *pl++) != EOS; ) |
320 | continue; | 319 | ; |
321 | 320 | ||
322 | /* Expand the current pattern */ | 321 | /* Expand the current pattern */ |
323 | #ifdef DEBUG | 322 | #ifdef DEBUG |
@@ -362,10 +361,15 @@ globtilde(pattern, patbuf, patbuf_len, pglob) | |||
362 | eb = &patbuf[patbuf_len - 1]; | 361 | eb = &patbuf[patbuf_len - 1]; |
363 | for (p = pattern + 1, h = (char *) patbuf; | 362 | for (p = pattern + 1, h = (char *) patbuf; |
364 | h < (char *)eb && *p && *p != SLASH; *h++ = *p++) | 363 | h < (char *)eb && *p && *p != SLASH; *h++ = *p++) |
365 | continue; | 364 | ; |
366 | 365 | ||
367 | *h = EOS; | 366 | *h = EOS; |
368 | 367 | ||
368 | #if 0 | ||
369 | if (h == (char *)eb) | ||
370 | return what; | ||
371 | #endif | ||
372 | |||
369 | if (((char *) patbuf)[0] == EOS) { | 373 | if (((char *) patbuf)[0] == EOS) { |
370 | /* | 374 | /* |
371 | * handle a plain ~ or ~/ by expanding $HOME | 375 | * handle a plain ~ or ~/ by expanding $HOME |
@@ -380,8 +384,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob) | |||
380 | else | 384 | else |
381 | h = pwd->pw_dir; | 385 | h = pwd->pw_dir; |
382 | } | 386 | } |
383 | } | 387 | } else { |
384 | else { | ||
385 | /* | 388 | /* |
386 | * Expand a ~user | 389 | * Expand a ~user |
387 | */ | 390 | */ |
@@ -393,11 +396,11 @@ globtilde(pattern, patbuf, patbuf_len, pglob) | |||
393 | 396 | ||
394 | /* Copy the home directory */ | 397 | /* Copy the home directory */ |
395 | for (b = patbuf; b < eb && *h; *b++ = *h++) | 398 | for (b = patbuf; b < eb && *h; *b++ = *h++) |
396 | continue; | 399 | ; |
397 | 400 | ||
398 | /* Append the rest of the pattern */ | 401 | /* Append the rest of the pattern */ |
399 | while (b < eb && (*b++ = *p++) != EOS) | 402 | while (b < eb && (*b++ = *p++) != EOS) |
400 | continue; | 403 | ; |
401 | *b = EOS; | 404 | *b = EOS; |
402 | 405 | ||
403 | return patbuf; | 406 | return patbuf; |
@@ -621,7 +624,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | |||
621 | if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { | 624 | if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { |
622 | /* TODO: don't call for ENOENT or ENOTDIR? */ | 625 | /* TODO: don't call for ENOENT or ENOTDIR? */ |
623 | if (pglob->gl_errfunc) { | 626 | if (pglob->gl_errfunc) { |
624 | if (g_Ctoc(pathbuf, buf, buf+sizeof(buf))) | 627 | if (g_Ctoc(pathbuf, buf, sizeof(buf))) |
625 | return(GLOB_ABORTED); | 628 | return(GLOB_ABORTED); |
626 | if (pglob->gl_errfunc(buf, errno) || | 629 | if (pglob->gl_errfunc(buf, errno) || |
627 | pglob->gl_flags & GLOB_ERR) | 630 | pglob->gl_flags & GLOB_ERR) |
@@ -718,11 +721,11 @@ globextend(path, pglob, limitp) | |||
718 | pglob->gl_pathv = pathv; | 721 | pglob->gl_pathv = pathv; |
719 | 722 | ||
720 | for (p = path; *p++;) | 723 | for (p = path; *p++;) |
721 | continue; | 724 | ; |
722 | len = (size_t)(p - path); | 725 | len = (size_t)(p - path); |
723 | *limitp += len; | 726 | *limitp += len; |
724 | if ((copy = malloc(len)) != NULL) { | 727 | if ((copy = malloc(len)) != NULL) { |
725 | if (g_Ctoc(path, copy, copy+len+1)) { | 728 | if (g_Ctoc(path, copy, len)) { |
726 | free(copy); | 729 | free(copy); |
727 | return(GLOB_NOSPACE); | 730 | return(GLOB_NOSPACE); |
728 | } | 731 | } |
@@ -820,7 +823,7 @@ g_opendir(str, pglob) | |||
820 | if (!*str) | 823 | if (!*str) |
821 | strcpy(buf, "."); | 824 | strcpy(buf, "."); |
822 | else { | 825 | else { |
823 | if (g_Ctoc(str, buf, buf+sizeof(buf))) | 826 | if (g_Ctoc(str, buf, sizeof(buf))) |
824 | return(NULL); | 827 | return(NULL); |
825 | } | 828 | } |
826 | 829 | ||
@@ -838,7 +841,7 @@ g_lstat(fn, sb, pglob) | |||
838 | { | 841 | { |
839 | char buf[MAXPATHLEN]; | 842 | char buf[MAXPATHLEN]; |
840 | 843 | ||
841 | if (g_Ctoc(fn, buf, buf+sizeof(buf))) | 844 | if (g_Ctoc(fn, buf, sizeof(buf))) |
842 | return(-1); | 845 | return(-1); |
843 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | 846 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
844 | return((*pglob->gl_lstat)(buf, sb)); | 847 | return((*pglob->gl_lstat)(buf, sb)); |
@@ -853,7 +856,7 @@ g_stat(fn, sb, pglob) | |||
853 | { | 856 | { |
854 | char buf[MAXPATHLEN]; | 857 | char buf[MAXPATHLEN]; |
855 | 858 | ||
856 | if (g_Ctoc(fn, buf, buf+sizeof(buf))) | 859 | if (g_Ctoc(fn, buf, sizeof(buf))) |
857 | return(-1); | 860 | return(-1); |
858 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | 861 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
859 | return((*pglob->gl_stat)(buf, sb)); | 862 | return((*pglob->gl_stat)(buf, sb)); |
@@ -873,17 +876,17 @@ g_strchr(str, ch) | |||
873 | } | 876 | } |
874 | 877 | ||
875 | static int | 878 | static int |
876 | g_Ctoc(str, buf, ebuf) | 879 | g_Ctoc(str, buf, len) |
877 | register const Char *str; | 880 | register const Char *str; |
878 | char *buf, *ebuf; | 881 | char *buf; |
882 | u_int len; | ||
879 | { | 883 | { |
880 | register char *dc; | ||
881 | 884 | ||
882 | for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;) | 885 | while (len--) { |
883 | continue; | 886 | if ((*buf++ = *str++) == EOS) |
884 | if (dc >= ebuf) | 887 | return (0); |
885 | return (1); | 888 | } |
886 | return (0); | 889 | return (1); |
887 | } | 890 | } |
888 | 891 | ||
889 | #ifdef DEBUG | 892 | #ifdef DEBUG |
diff --git a/openbsd-compat/strlcat.c b/openbsd-compat/strlcat.c index 10ad9e71a..7631d9694 100644 --- a/openbsd-compat/strlcat.c +++ b/openbsd-compat/strlcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ | 1 | /* $OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -31,7 +31,7 @@ | |||
31 | #ifndef HAVE_STRLCAT | 31 | #ifndef HAVE_STRLCAT |
32 | 32 | ||
33 | #if defined(LIBC_SCCS) && !defined(lint) | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
34 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; | 34 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $"; |
35 | #endif /* LIBC_SCCS and not lint */ | 35 | #endif /* LIBC_SCCS and not lint */ |
36 | 36 | ||
37 | #include <sys/types.h> | 37 | #include <sys/types.h> |
@@ -40,8 +40,9 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp | |||
40 | /* | 40 | /* |
41 | * Appends src to string dst of size siz (unlike strncat, siz is the | 41 | * Appends src to string dst of size siz (unlike strncat, siz is the |
42 | * full size of dst, not space left). At most siz-1 characters | 42 | * full size of dst, not space left). At most siz-1 characters |
43 | * will be copied. Always NUL terminates (unless siz == 0). | 43 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). |
44 | * Returns strlen(src); if retval >= siz, truncation occurred. | 44 | * Returns strlen(initial dst) + strlen(src); if retval >= siz, |
45 | * truncation occurred. | ||
45 | */ | 46 | */ |
46 | size_t strlcat(dst, src, siz) | 47 | size_t strlcat(dst, src, siz) |
47 | char *dst; | 48 | char *dst; |
@@ -54,7 +55,7 @@ size_t strlcat(dst, src, siz) | |||
54 | size_t dlen; | 55 | size_t dlen; |
55 | 56 | ||
56 | /* Find the end of dst and adjust bytes left but don't go past end */ | 57 | /* Find the end of dst and adjust bytes left but don't go past end */ |
57 | while (*d != '\0' && n-- != 0) | 58 | while (n-- != 0 && *d != '\0') |
58 | d++; | 59 | d++; |
59 | dlen = d - dst; | 60 | dlen = d - dst; |
60 | n = siz - dlen; | 61 | n = siz - dlen; |
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c index f49277eb3..7eb2d6cd9 100644 --- a/openbsd-compat/vis.c +++ b/openbsd-compat/vis.c | |||
@@ -32,7 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char rcsid[] = "$OpenBSD: vis.c,v 1.5 2000/07/19 15:25:13 deraadt Exp $"; | 35 | static char rcsid[] = "$OpenBSD: vis.c,v 1.6 2000/11/21 00:47:28 millert Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include "includes.h" | 38 | #include "includes.h" |
@@ -40,18 +40,20 @@ static char rcsid[] = "$OpenBSD: vis.c,v 1.5 2000/07/19 15:25:13 deraadt Exp $"; | |||
40 | #ifndef HAVE_VIS | 40 | #ifndef HAVE_VIS |
41 | 41 | ||
42 | #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') | 42 | #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') |
43 | #define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ | ||
44 | isgraph((u_char)(c))) || \ | ||
45 | ((flag & VIS_SP) == 0 && (c) == ' ') || \ | ||
46 | ((flag & VIS_TAB) == 0 && (c) == '\t') || \ | ||
47 | ((flag & VIS_NL) == 0 && (c) == '\n') || \ | ||
48 | ((flag & VIS_SAFE) && \ | ||
49 | ((c) == '\b' || (c) == '\007' || (c) == '\r'))) | ||
43 | 50 | ||
44 | /* | 51 | /* |
45 | * vis - visually encode characters | 52 | * vis - visually encode characters |
46 | */ | 53 | */ |
47 | char *vis(char *dst, int c, int flag, int nextc) | 54 | char *vis(char *dst, int c, int flag, int nextc) |
48 | { | 55 | { |
49 | if (((u_int)c <= UCHAR_MAX && isascii((u_char)c) && | 56 | if (isvisible(c)) { |
50 | isgraph((u_char)c)) || | ||
51 | ((flag & VIS_SP) == 0 && c == ' ') || | ||
52 | ((flag & VIS_TAB) == 0 && c == '\t') || | ||
53 | ((flag & VIS_NL) == 0 && c == '\n') || | ||
54 | ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { | ||
55 | *dst++ = c; | 57 | *dst++ = c; |
56 | if (c == '\\' && (flag & VIS_NOSLASH) == 0) | 58 | if (c == '\\' && (flag & VIS_NOSLASH) == 0) |
57 | *dst++ = '\\'; | 59 | *dst++ = '\\'; |