aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2015-02-15 21:41:29 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2015-02-15 21:41:29 +0000
commita4652c280b6f8a5b34143413f685d94b86e8b78c (patch)
treec36f84630b24693d8cf17b0d6a9606dcbe8ce91a /bin
parent51492908f9e7e6f4901ca421980dada135ce4cc8 (diff)
downloadsrc-a4652c280b6f8a5b34143413f685d94b86e8b78c.tar.gz
src-a4652c280b6f8a5b34143413f685d94b86e8b78c.zip
sh: Add stsavestr(), like savestr() but allocates using stalloc().
Notes
Notes: svn path=/head/; revision=278818
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/cd.c10
-rw-r--r--bin/sh/expand.c5
-rw-r--r--bin/sh/memalloc.c12
-rw-r--r--bin/sh/memalloc.h1
4 files changed, 16 insertions, 12 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 7720fad7d64c..017dfa1e13ec 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -182,7 +182,6 @@ cdlogical(char *dest)
struct stat statb;
int first;
int badstat;
- size_t len;
/*
* Check each component of the path. If we find a symlink or
@@ -190,9 +189,7 @@ cdlogical(char *dest)
* next time we get the value of the current directory.
*/
badstat = 0;
- len = strlen(dest);
- cdcomppath = stalloc(len + 1);
- memcpy(cdcomppath, dest, len + 1);
+ cdcomppath = stsavestr(dest);
STARTSTACKSTR(p);
if (*dest == '/') {
STPUTC('/', p);
@@ -277,7 +274,6 @@ findcwd(char *dir)
{
char *new;
char *p;
- size_t len;
/*
* If our argument is NULL, we don't know the current directory
@@ -286,9 +282,7 @@ findcwd(char *dir)
*/
if (dir == NULL || curdir == NULL)
return getpwd2();
- len = strlen(dir);
- cdcomppath = stalloc(len + 1);
- memcpy(cdcomppath, dir, len + 1);
+ cdcomppath = stsavestr(dir);
STARTSTACKSTR(new);
if (*dir != '/') {
STPUTS(curdir, new);
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index b542303d239e..53b2c9bfd7d9 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -1284,11 +1284,8 @@ addfname(char *name)
{
char *p;
struct strlist *sp;
- size_t len;
- len = strlen(name);
- p = stalloc(len + 1);
- memcpy(p, name, len + 1);
+ p = stsavestr(name);
sp = (struct strlist *)stalloc(sizeof *sp);
sp->text = p;
*exparg.lastp = sp;
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c
index 119f12e9fc74..a04020f80c97 100644
--- a/bin/sh/memalloc.c
+++ b/bin/sh/memalloc.c
@@ -180,6 +180,18 @@ stunalloc(pointer p)
}
+char *
+stsavestr(const char *s)
+{
+ char *p;
+ size_t len;
+
+ len = strlen(s);
+ p = stalloc(len + 1);
+ memcpy(p, s, len + 1);
+ return p;
+}
+
void
setstackmark(struct stackmark *mark)
diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h
index a22fa3919872..e8df7cb1c0b9 100644
--- a/bin/sh/memalloc.h
+++ b/bin/sh/memalloc.h
@@ -52,6 +52,7 @@ void ckfree(pointer);
char *savestr(const char *);
pointer stalloc(int);
void stunalloc(pointer);
+char *stsavestr(const char *);
void setstackmark(struct stackmark *);
void popstackmark(struct stackmark *);
char *growstackstr(void);