oksh rcsid-only sync, plus bonus rewrite of strip_nuls

(uses size_t ipv int for buffer size now, and no extra
calls to memchr/memmove, input is typically small)
This commit is contained in:
tg 2015-03-20 21:46:41 +00:00
parent 8967f13bc6
commit 2097d45f7f
2 changed files with 22 additions and 26 deletions

43
misc.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.39 2015/01/16 06:39:32 deraadt Exp $ */
/* $OpenBSD: misc.c,v 1.40 2015/03/18 15:12:36 tedu Exp $ */
/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */
/*-
@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.225 2015/03/01 15:23:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.226 2015/03/20 21:46:40 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -1289,32 +1289,27 @@ print_columns(struct shf *shf, unsigned int n,
afree(str, ATEMP);
}
/* Strip any nul bytes from buf - returns new length (nbytes - # of nuls) */
/* strip all NUL bytes from buf; output is NUL-terminated if stripped */
void
strip_nuls(char *buf, int nbytes)
strip_nuls(char *buf, size_t len)
{
char *dst;
char *cp, *dp, *ep;
/*
* nbytes check because some systems (older FreeBSDs) have a
* buggy memchr()
*/
if (nbytes && (dst = memchr(buf, '\0', nbytes))) {
char *end = buf + nbytes;
char *p, *q;
if (!len || !(dp = memchr(buf, '\0', len)))
return;
for (p = dst; p < end; p = q) {
/* skip a block of nulls */
while (++p < end && *p == '\0')
;
/* find end of non-null block */
if (!(q = memchr(p, '\0', end - p)))
q = end;
memmove(dst, p, q - p);
dst += q - p;
}
*dst = '\0';
}
ep = buf + len;
cp = dp;
cp_has_nul_byte:
while (cp++ < ep && *cp == '\0')
; /* nothing */
while (cp < ep && *cp != '\0')
*dp++ = *cp++;
if (cp < ep)
goto cp_has_nul_byte;
*dp = '\0';
}
/*

5
sh.h
View File

@ -169,7 +169,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.719 2015/03/14 05:23:17 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.720 2015/03/20 21:46:41 tg Exp $");
#endif
#define MKSH_VERSION "R50 2015/03/13"
@ -1869,7 +1869,8 @@ char *quote_value(const char *);
void print_columns(struct shf *, unsigned int,
char *(*)(char *, size_t, unsigned int, const void *),
const void *, size_t, size_t, bool);
void strip_nuls(char *, int);
void strip_nuls(char *, size_t)
MKSH_A_BOUNDED(__string__, 1, 2);
ssize_t blocking_read(int, char *, size_t)
MKSH_A_BOUNDED(__buffer__, 2, 3);
int reset_nonblock(int);