summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authordjm <djm>2001-04-13 14:22:33 +0000
committerdjm <djm>2001-04-13 14:22:33 +0000
commit7f2a09e58877c50c1281e48196e8e274401a03d0 (patch)
tree94d4df71536f11ed5979c88a7a457dd34c3fba3f /openbsd-compat
parentc78a139dac289d920e982983284c0a862985cad6 (diff)
downloadopenssh-7f2a09e58877c50c1281e48196e8e274401a03d0.tar.gz
- Sync with OpenBSD glob.c, strlcat.c and vis.c changes
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/glob.c65
-rw-r--r--openbsd-compat/strlcat.c11
-rw-r--r--openbsd-compat/vis.c16
3 files changed, 49 insertions, 43 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c
index 677a8a10..4f70149c 100644
--- a/openbsd-compat/glob.c
+++ b/openbsd-compat/glob.c
@@ -56,7 +56,7 @@ get_arg_max()
#if 0
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#else
-static char rcsid[] = "$OpenBSD: glob.c,v 1.14 2001/03/28 20:54:19 millert Exp $";
+static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -137,7 +137,7 @@ typedef char Char;
static int compare __P((const void *, const void *));
-static int g_Ctoc __P((const Char *, char *, char *));
+static int g_Ctoc __P((const Char *, char *, u_int));
static int g_lstat __P((Char *, struct stat *, glob_t *));
static DIR *g_opendir __P((Char *, glob_t *));
static Char *g_strchr __P((Char *, int));
@@ -193,8 +193,7 @@ glob(pattern, flags, errfunc, pglob)
--patnext;
}
*bufnext++ = c | M_PROTECT;
- }
- else
+ } else
*bufnext++ = c;
}
*bufnext = EOS;
@@ -248,7 +247,7 @@ globexp2(ptr, pattern, pglob, rv)
/* copy part up to the brace */
for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
- continue;
+ ;
*lm = EOS;
ls = lm;
@@ -257,7 +256,7 @@ globexp2(ptr, pattern, pglob, rv)
if (*pe == LBRACKET) {
/* Ignore everything between [] */
for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
- continue;
+ ;
if (*pe == EOS) {
/*
* We could not find a matching RBRACKET.
@@ -265,8 +264,7 @@ globexp2(ptr, pattern, pglob, rv)
*/
pe = pm;
}
- }
- else if (*pe == LBRACE)
+ } else if (*pe == LBRACE)
i++;
else if (*pe == RBRACE) {
if (i == 0)
@@ -285,7 +283,7 @@ globexp2(ptr, pattern, pglob, rv)
case LBRACKET:
/* Ignore everything between [] */
for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
- continue;
+ ;
if (*pm == EOS) {
/*
* We could not find a matching RBRACKET.
@@ -311,13 +309,14 @@ globexp2(ptr, pattern, pglob, rv)
else {
/* Append the current string */
for (lm = ls; (pl < pm); *lm++ = *pl++)
- continue;
+ ;
+
/*
* Append the rest of the pattern after the
* closing brace
*/
- for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
- continue;
+ for (pl = pe + 1; (*lm++ = *pl++) != EOS; )
+ ;
/* Expand the current pattern */
#ifdef DEBUG
@@ -362,10 +361,15 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
eb = &patbuf[patbuf_len - 1];
for (p = pattern + 1, h = (char *) patbuf;
h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
- continue;
+ ;
*h = EOS;
+#if 0
+ if (h == (char *)eb)
+ return what;
+#endif
+
if (((char *) patbuf)[0] == EOS) {
/*
* handle a plain ~ or ~/ by expanding $HOME
@@ -380,8 +384,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
else
h = pwd->pw_dir;
}
- }
- else {
+ } else {
/*
* Expand a ~user
*/
@@ -393,11 +396,11 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
/* Copy the home directory */
for (b = patbuf; b < eb && *h; *b++ = *h++)
- continue;
+ ;
/* Append the rest of the pattern */
while (b < eb && (*b++ = *p++) != EOS)
- continue;
+ ;
*b = EOS;
return patbuf;
@@ -621,7 +624,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
/* TODO: don't call for ENOENT or ENOTDIR? */
if (pglob->gl_errfunc) {
- if (g_Ctoc(pathbuf, buf, buf+sizeof(buf)))
+ if (g_Ctoc(pathbuf, buf, sizeof(buf)))
return(GLOB_ABORTED);
if (pglob->gl_errfunc(buf, errno) ||
pglob->gl_flags & GLOB_ERR)
@@ -718,11 +721,11 @@ globextend(path, pglob, limitp)
pglob->gl_pathv = pathv;
for (p = path; *p++;)
- continue;
+ ;
len = (size_t)(p - path);
*limitp += len;
if ((copy = malloc(len)) != NULL) {
- if (g_Ctoc(path, copy, copy+len+1)) {
+ if (g_Ctoc(path, copy, len)) {
free(copy);
return(GLOB_NOSPACE);
}
@@ -820,7 +823,7 @@ g_opendir(str, pglob)
if (!*str)
strcpy(buf, ".");
else {
- if (g_Ctoc(str, buf, buf+sizeof(buf)))
+ if (g_Ctoc(str, buf, sizeof(buf)))
return(NULL);
}
@@ -838,7 +841,7 @@ g_lstat(fn, sb, pglob)
{
char buf[MAXPATHLEN];
- if (g_Ctoc(fn, buf, buf+sizeof(buf)))
+ if (g_Ctoc(fn, buf, sizeof(buf)))
return(-1);
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_lstat)(buf, sb));
@@ -853,7 +856,7 @@ g_stat(fn, sb, pglob)
{
char buf[MAXPATHLEN];
- if (g_Ctoc(fn, buf, buf+sizeof(buf)))
+ if (g_Ctoc(fn, buf, sizeof(buf)))
return(-1);
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
return((*pglob->gl_stat)(buf, sb));
@@ -873,17 +876,17 @@ g_strchr(str, ch)
}
static int
-g_Ctoc(str, buf, ebuf)
+g_Ctoc(str, buf, len)
register const Char *str;
- char *buf, *ebuf;
+ char *buf;
+ u_int len;
{
- register char *dc;
- for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;)
- continue;
- if (dc >= ebuf)
- return (1);
- return (0);
+ while (len--) {
+ if ((*buf++ = *str++) == EOS)
+ return (0);
+ }
+ return (1);
}
#ifdef DEBUG
diff --git a/openbsd-compat/strlcat.c b/openbsd-compat/strlcat.c
index 10ad9e71..7631d969 100644
--- a/openbsd-compat/strlcat.c
+++ b/openbsd-compat/strlcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */
+/* $OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -31,7 +31,7 @@
#ifndef HAVE_STRLCAT
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
+static char *rcsid = "$OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#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
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(initial dst) + strlen(src); if retval >= siz,
+ * truncation occurred.
*/
size_t strlcat(dst, src, siz)
char *dst;
@@ -54,7 +55,7 @@ size_t strlcat(dst, src, siz)
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
- while (*d != '\0' && n-- != 0)
+ while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c
index f49277eb..7eb2d6cd 100644
--- a/openbsd-compat/vis.c
+++ b/openbsd-compat/vis.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vis.c,v 1.5 2000/07/19 15:25:13 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: vis.c,v 1.6 2000/11/21 00:47:28 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include "includes.h"
@@ -40,18 +40,20 @@ static char rcsid[] = "$OpenBSD: vis.c,v 1.5 2000/07/19 15:25:13 deraadt Exp $";
#ifndef HAVE_VIS
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
+ isgraph((u_char)(c))) || \
+ ((flag & VIS_SP) == 0 && (c) == ' ') || \
+ ((flag & VIS_TAB) == 0 && (c) == '\t') || \
+ ((flag & VIS_NL) == 0 && (c) == '\n') || \
+ ((flag & VIS_SAFE) && \
+ ((c) == '\b' || (c) == '\007' || (c) == '\r')))
/*
* vis - visually encode characters
*/
char *vis(char *dst, int c, int flag, int nextc)
{
- if (((u_int)c <= UCHAR_MAX && isascii((u_char)c) &&
- isgraph((u_char)c)) ||
- ((flag & VIS_SP) == 0 && c == ' ') ||
- ((flag & VIS_TAB) == 0 && c == '\t') ||
- ((flag & VIS_NL) == 0 && c == '\n') ||
- ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) {
+ if (isvisible(c)) {
*dst++ = c;
if (c == '\\' && (flag & VIS_NOSLASH) == 0)
*dst++ = '\\';