optimise and, ahem… plug…

This commit is contained in:
tg 2006-11-09 14:19:31 +00:00
parent 39057dd592
commit a1bfc17aa0
3 changed files with 13 additions and 29 deletions

View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.25 2006/08/24 18:57:30 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.26 2006/11/09 14:19:31 tg Exp $");
#if !defined(__sun__)
#define DO_HISTORY
@ -75,9 +75,9 @@ c_fc(char **wp)
if (strcmp(p, "-") == 0)
sflag++;
else {
size_t len = strlen(p) + 4;
editor = str_nsave(p, len, ATEMP);
strlcat(editor, " $_", len);
size_t len = strlen(p);
editor = str_nsave(p, len + 4, ATEMP);
memcpy(editor + len, " $_", 4);
}
break;
case 'g': /* non-at&t ksh */

30
misc.c
View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.18 2006/11/05 17:01:46 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.19 2006/11/09 14:19:31 tg Exp $\t"
MKSH_SH_H_ID);
short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */
@ -56,9 +56,9 @@ char *
ulton(long unsigned int n, int base)
{
char *p;
static char buf [20];
static char buf[20];
p = &buf[sizeof(buf)];
p = &buf[sizeof (buf)];
*--p = '\0';
do {
*--p = "0123456789ABCDEF"[n%base];
@ -67,20 +67,6 @@ ulton(long unsigned int n, int base)
return p;
}
char *
str_save(const char *s, Area *ap)
{
size_t len;
char *p;
if (!s)
return NULL;
len = strlen(s)+1;
p = alloc(len, ap);
strlcpy(p, s, len+1);
return (p);
}
/* Allocate a string of size n+1 and copy upto n characters from the possibly
* null terminated string s into it. Always returns a null terminated string
* (unless n < 0).
@ -88,13 +74,11 @@ str_save(const char *s, Area *ap)
char *
str_nsave(const char *s, int n, Area *ap)
{
char *ns;
char *ns = NULL;
if (n < 0)
return 0;
ns = alloc(n + 1, ap);
ns[0] = '\0';
return strncat(ns, s, n);
if (n >= 0 && s)
strlcpy(ns = alloc(n + 1, ap), s, n + 1);
return (ns);
}
/* called from XcheckN() to grow buffer */

4
sh.h
View File

@ -8,7 +8,7 @@
/* $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.55 2006/11/09 00:39:27 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.56 2006/11/09 14:19:31 tg Exp $"
#define MKSH_VERSION "R29 2006/11/08"
#if HAVE_SYS_PARAM_H
@ -1220,7 +1220,7 @@ struct tbl **ktsort(struct table *);
void setctypes(const char *, int);
void initctypes(void);
char *ulton(unsigned long, int);
char *str_save(const char *, Area *);
#define str_save(s, a) str_nsave((s), strlen(s), a)
char *str_nsave(const char *, int, Area *);
int option(const char *);
char *getoptions(void);