get rid of the need of strlcat() altogether (only one use was left)
This commit is contained in:
parent
2b375abef1
commit
36ac8dc0f7
8
Build.sh
8
Build.sh
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.67 2006/11/09 00:13:27 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.68 2006/11/09 15:02:30 tg Exp $
|
||||
#-
|
||||
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF
|
||||
|
||||
@ -182,11 +182,6 @@ ac_test setmode <<-'EOF'
|
||||
int main(int ac, char *av[]) { setmode(av[0]); return (ac); }
|
||||
EOF
|
||||
|
||||
ac_test strlcat <<-'EOF'
|
||||
#include <string.h>
|
||||
int main(int ac, char *av[]) { strlcat(av[0], av[1], 1); return (ac); }
|
||||
EOF
|
||||
|
||||
ac_test strlcpy <<-'EOF'
|
||||
#include <string.h>
|
||||
int main(int ac, char *av[]) { strlcpy(av[0], av[1], 1); return (ac); }
|
||||
@ -199,7 +194,6 @@ EOF
|
||||
|
||||
$e ... done.
|
||||
addsrcs HAVE_SETMODE setmode.c
|
||||
addsrcs HAVE_STRLCAT strlfun.c
|
||||
addsrcs HAVE_STRLCPY strlfun.c
|
||||
|
||||
(v "cd '$srcdir' && exec $CC $CFLAGS -I'$curdir' $CPPFLAGS" \
|
||||
|
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.70 2006/11/08 23:45:46 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.71 2006/11/09 15:02:30 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
@ -3872,5 +3872,5 @@ category: pdksh
|
||||
stdin:
|
||||
echo $KSH_VERSION
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R29 2006/11/08
|
||||
@(#)MIRBSD KSH R29 2006/11/09
|
||||
---
|
||||
|
79
edit.c
79
edit.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.60 2006/11/09 00:39:27 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.61 2006/11/09 15:02:30 tg Exp $");
|
||||
|
||||
/* tty driver characters we are interested in */
|
||||
typedef struct {
|
||||
@ -1178,13 +1178,13 @@ typedef enum {
|
||||
/*
|
||||
* The following are used for my horizontal scrolling stuff
|
||||
*/
|
||||
static char *xbuf; /* beg input buffer */
|
||||
static char *xend; /* end input buffer */
|
||||
static char *xcp; /* current position */
|
||||
static char *xep; /* current end */
|
||||
static char *xbp; /* start of visible portion of input buffer */
|
||||
static char *xlp; /* last char visible on screen */
|
||||
static int x_adj_ok;
|
||||
static char *xbuf; /* beg input buffer */
|
||||
static char *xend; /* end input buffer */
|
||||
static char *xcp; /* current position */
|
||||
static char *xep; /* current end */
|
||||
static char *xbp; /* start of visible portion of input buffer */
|
||||
static char *xlp; /* last char visible on screen */
|
||||
static int x_adj_ok;
|
||||
/*
|
||||
* we use x_adj_done so that functions can tell
|
||||
* whether x_adjust() has been called while they are active.
|
||||
@ -1199,19 +1199,19 @@ static int x_arg_defaulted;/* x_arg not explicitly set; defaulted to 1 */
|
||||
|
||||
static int xlp_valid;
|
||||
|
||||
static int x_prefix1 = MKCTRL('['), x_prefix2 = MKCTRL('X');
|
||||
static char **x_histp; /* history position */
|
||||
static int x_nextcmd; /* for newline-and-next */
|
||||
static char *xmp; /* mark pointer */
|
||||
static u_char x_last_command;
|
||||
static u_char (*x_tab)[X_TABSZ]; /* key definition */
|
||||
static char *(*x_atab)[X_TABSZ]; /* macro definitions */
|
||||
static unsigned char x_bound[(X_TABSZ * X_NTABS + 7) / 8];
|
||||
static int x_prefix1 = MKCTRL('['), x_prefix2 = MKCTRL('X');
|
||||
static char **x_histp; /* history position */
|
||||
static int x_nextcmd; /* for newline-and-next */
|
||||
static char *xmp; /* mark pointer */
|
||||
static u_char x_last_command;
|
||||
static u_char (*x_tab)[X_TABSZ]; /* key definition */
|
||||
static char *(*x_atab)[X_TABSZ]; /* macro definitions */
|
||||
static unsigned char x_bound[(X_TABSZ * X_NTABS + 7) / 8];
|
||||
#define KILLSIZE 20
|
||||
static char *killstack[KILLSIZE];
|
||||
static int killsp, killtp;
|
||||
static int x_curprefix;
|
||||
static char *macroptr;
|
||||
static char *killstack[KILLSIZE];
|
||||
static int killsp, killtp;
|
||||
static int x_curprefix;
|
||||
static char *macroptr;
|
||||
static int cur_col; /* current column on line */
|
||||
static int pwidth; /* width of prompt */
|
||||
static int prompt_trunc; /* how much of prompt to truncate */
|
||||
@ -1225,11 +1225,11 @@ static int lastref; /* argument to last refresh() */
|
||||
static char holdbuf[LINE]; /* place to hold last edit buffer */
|
||||
static int holdlen; /* length of holdbuf */
|
||||
|
||||
static int x_ins(char *);
|
||||
static void x_delete(int, int);
|
||||
static int x_ins(char *);
|
||||
static void x_delete(int, int);
|
||||
static int x_bword(void);
|
||||
static int x_fword(int);
|
||||
static void x_goto(char *);
|
||||
static void x_goto(char *);
|
||||
static void x_bs2(char *);
|
||||
static int x_size_str(char *);
|
||||
static int x_size2(char *, char **);
|
||||
@ -1240,9 +1240,10 @@ static void x_load_hist(char **);
|
||||
static int x_search(char *, int, int);
|
||||
static int x_match(char *, char *);
|
||||
static void x_redraw(int);
|
||||
static void x_push(int);
|
||||
static char * x_mapin(const char *);
|
||||
static char * x_mapout(int);
|
||||
static void x_push(int);
|
||||
static char * x_mapin(const char *);
|
||||
static char * x_mapout(int);
|
||||
static void x_mapout2(int, char **);
|
||||
static void x_print(int, int);
|
||||
static void x_adjust(void);
|
||||
static void x_e_ungetc(int);
|
||||
@ -2626,11 +2627,10 @@ x_mapin(const char *cp)
|
||||
return new;
|
||||
}
|
||||
|
||||
static char *
|
||||
x_mapout(int c)
|
||||
static void
|
||||
x_mapout2(int c, char **buf)
|
||||
{
|
||||
static char buf[8];
|
||||
char *p = buf;
|
||||
char *p = *buf;
|
||||
|
||||
if (c < ' ' || c == 0x7f) {
|
||||
*p++ = '^';
|
||||
@ -2638,7 +2638,17 @@ x_mapout(int c)
|
||||
} else
|
||||
*p++ = c;
|
||||
*p = 0;
|
||||
return buf;
|
||||
*buf = p;
|
||||
}
|
||||
|
||||
static char *
|
||||
x_mapout(int c)
|
||||
{
|
||||
static char buf[8];
|
||||
char *bp = buf;
|
||||
|
||||
x_mapout2(c, &bp);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2703,10 +2713,11 @@ x_bind(const char *a1, const char *a2,
|
||||
break;
|
||||
}
|
||||
if (*++m1 && ((*m1 != '~') || *(m1+1))) {
|
||||
char msg[256] = "bind: key sequence '";
|
||||
char msg[256] = "key sequence '";
|
||||
const char *c = a1;
|
||||
while (*c)
|
||||
strlcat(msg, x_mapout(*c++), sizeof (msg));
|
||||
m1 = msg + strlen(msg);
|
||||
while (*c && m1 < (msg + sizeof (msg) - 3))
|
||||
x_mapout2(*c++, &m1);
|
||||
bi_errorf("%s' too long", msg);
|
||||
return (1);
|
||||
}
|
||||
|
4
sh.h
4
sh.h
@ -8,8 +8,8 @@
|
||||
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
|
||||
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
|
||||
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.57 2006/11/09 14:58:27 tg Exp $"
|
||||
#define MKSH_VERSION "R29 2006/11/08"
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.58 2006/11/09 15:02:31 tg Exp $"
|
||||
#define MKSH_VERSION "R29 2006/11/09"
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
|
32
strlfun.c
32
strlfun.c
@ -1,4 +1,4 @@
|
||||
/* $MirOS: src/bin/mksh/strlfun.c,v 1.6 2006/11/08 23:23:41 tg Exp $ */
|
||||
/* $MirOS: src/bin/mksh/strlfun.c,v 1.7 2006/11/09 15:02:31 tg Exp $ */
|
||||
/* _MirOS: src/lib/libc/string/strlfun.c,v 1.10 2006/11/08 23:18:04 tg Exp $ */
|
||||
|
||||
/*-
|
||||
@ -71,38 +71,10 @@ extern size_t strlen(const char *);
|
||||
#define __predict_false(exp) ((exp) != 0)
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/strlfun.c,v 1.6 2006/11/08 23:23:41 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/strlfun.c,v 1.7 2006/11/09 15:02:31 tg Exp $");
|
||||
|
||||
size_t strlcat(char *, const char *, size_t);
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
|
||||
#if !defined(HAVE_STRLCAT) || (HAVE_STRLCAT == 0)
|
||||
/*
|
||||
* 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 <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t dlen)
|
||||
{
|
||||
size_t n = 0, slen;
|
||||
|
||||
slen = strlen(src);
|
||||
while (__predict_true(n + 1 < dlen && dst[n] != '\0'))
|
||||
++n;
|
||||
if (__predict_false(dlen == 0 || dst[n] != '\0'))
|
||||
return (dlen + slen);
|
||||
while (__predict_true((slen > 0) && (n < (dlen - 1)))) {
|
||||
dst[n++] = *src++;
|
||||
--slen;
|
||||
}
|
||||
dst[n] = '\0';
|
||||
return (n + slen);
|
||||
}
|
||||
#endif /* !HAVE_STRLCAT */
|
||||
|
||||
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*-
|
||||
|
Loading…
x
Reference in New Issue
Block a user