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:
parent
8967f13bc6
commit
2097d45f7f
43
misc.c
43
misc.c
@ -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 $ */
|
/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
@ -30,7 +30,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#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
|
#define KSH_CHVT_FLAG
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
@ -1289,32 +1289,27 @@ print_columns(struct shf *shf, unsigned int n,
|
|||||||
afree(str, ATEMP);
|
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
|
void
|
||||||
strip_nuls(char *buf, int nbytes)
|
strip_nuls(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
char *dst;
|
char *cp, *dp, *ep;
|
||||||
|
|
||||||
/*
|
if (!len || !(dp = memchr(buf, '\0', len)))
|
||||||
* nbytes check because some systems (older FreeBSDs) have a
|
return;
|
||||||
* buggy memchr()
|
|
||||||
*/
|
|
||||||
if (nbytes && (dst = memchr(buf, '\0', nbytes))) {
|
|
||||||
char *end = buf + nbytes;
|
|
||||||
char *p, *q;
|
|
||||||
|
|
||||||
for (p = dst; p < end; p = q) {
|
ep = buf + len;
|
||||||
/* skip a block of nulls */
|
cp = dp;
|
||||||
while (++p < end && *p == '\0')
|
|
||||||
;
|
cp_has_nul_byte:
|
||||||
/* find end of non-null block */
|
while (cp++ < ep && *cp == '\0')
|
||||||
if (!(q = memchr(p, '\0', end - p)))
|
; /* nothing */
|
||||||
q = end;
|
while (cp < ep && *cp != '\0')
|
||||||
memmove(dst, p, q - p);
|
*dp++ = *cp++;
|
||||||
dst += q - p;
|
if (cp < ep)
|
||||||
}
|
goto cp_has_nul_byte;
|
||||||
*dst = '\0';
|
|
||||||
}
|
*dp = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
5
sh.h
5
sh.h
@ -169,7 +169,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R50 2015/03/13"
|
#define MKSH_VERSION "R50 2015/03/13"
|
||||||
|
|
||||||
@ -1869,7 +1869,8 @@ char *quote_value(const char *);
|
|||||||
void print_columns(struct shf *, unsigned int,
|
void print_columns(struct shf *, unsigned int,
|
||||||
char *(*)(char *, size_t, unsigned int, const void *),
|
char *(*)(char *, size_t, unsigned int, const void *),
|
||||||
const void *, size_t, size_t, bool);
|
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)
|
ssize_t blocking_read(int, char *, size_t)
|
||||||
MKSH_A_BOUNDED(__buffer__, 2, 3);
|
MKSH_A_BOUNDED(__buffer__, 2, 3);
|
||||||
int reset_nonblock(int);
|
int reset_nonblock(int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user