From bf3194e9375a39d546309fda64472b5ba40e7ef3 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 28 Oct 2008 14:51:06 +0000 Subject: [PATCH] save 1640 .text bytes in MKSH_SMALL case by not inlining strdupx, strndupx --- misc.c | 22 +++++++++++++++++++++- sh.h | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/misc.c b/misc.c index 722d6ec..f69c14d 100644 --- a/misc.c +++ b/misc.c @@ -6,7 +6,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.88 2008/10/28 14:32:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.89 2008/10/28 14:51:06 tg Exp $"); #undef USE_CHVT #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) @@ -1422,3 +1422,23 @@ stristr(const char *b, const char *l) } #endif #endif + +#ifdef MKSH_SMALL +char * +strndup_(const char *src, size_t len, Area *ap) +{ + char *dst = NULL; + + if (src != NULL) { + dst = alloc(++len, ap); + strlcpy(dst, src, len); + } + return (dst); +} + +char * +strdup_(const char *src, Area *ap) +{ + return (src == NULL ? NULL : strndup_(src, strlen(src), ap)); +} +#endif diff --git a/sh.h b/sh.h index 5027537..8edfbab 100644 --- a/sh.h +++ b/sh.h @@ -100,7 +100,7 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.248 2008/10/28 14:32:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.249 2008/10/28 14:51:06 tg Exp $"); #endif #define MKSH_VERSION "R36 2008/10/28" @@ -345,6 +345,14 @@ char *ucstrstr(char *, const char *); (dst) = (src) + utf_ptradjx_len; \ } while (/* CONSTCOND */ 0) +#ifdef MKSH_SMALL +#define strdupx(d, s, ap) do { \ + (d) = strdup_((s), (ap)); \ +} while (/* CONSTCOND */ 0) +#define strndupx(d, s, n, ap) do { \ + (d) = strndup_((s), (n), (ap)); \ +} while (/* CONSTCOND */ 0) +#else /* be careful to evaluate arguments only once! */ #define strdupx(d, s, ap) do { \ const char *strdup_src = (s); \ @@ -368,6 +376,7 @@ char *ucstrstr(char *, const char *); } \ (d) = strdup_dst; \ } while (/* CONSTCOND */ 0) +#endif #if HAVE_STRCASESTR #define stristr(b,l) ((const char *)strcasestr((b), (l))) @@ -1472,6 +1481,10 @@ int make_path(const char *, const char *, char **, XString *, int *); void simplify_path(char *); char *get_phys_path(const char *); void set_current_wd(char *); +#ifdef MKSH_SMALL +char *strdup_(const char *, Area *); +char *strndup_(const char *, size_t, Area *); +#endif /* shf.c */ struct shf *shf_open(const char *, int, int, int); struct shf *shf_fdopen(int, int, struct shf *);