sh: Add stsavestr(), like savestr() but allocates using stalloc().
This commit is contained in:
parent
51492908f9
commit
a4652c280b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=278818
10
bin/sh/cd.c
10
bin/sh/cd.c
@ -182,7 +182,6 @@ cdlogical(char *dest)
|
|||||||
struct stat statb;
|
struct stat statb;
|
||||||
int first;
|
int first;
|
||||||
int badstat;
|
int badstat;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check each component of the path. If we find a symlink or
|
* 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.
|
* next time we get the value of the current directory.
|
||||||
*/
|
*/
|
||||||
badstat = 0;
|
badstat = 0;
|
||||||
len = strlen(dest);
|
cdcomppath = stsavestr(dest);
|
||||||
cdcomppath = stalloc(len + 1);
|
|
||||||
memcpy(cdcomppath, dest, len + 1);
|
|
||||||
STARTSTACKSTR(p);
|
STARTSTACKSTR(p);
|
||||||
if (*dest == '/') {
|
if (*dest == '/') {
|
||||||
STPUTC('/', p);
|
STPUTC('/', p);
|
||||||
@ -277,7 +274,6 @@ findcwd(char *dir)
|
|||||||
{
|
{
|
||||||
char *new;
|
char *new;
|
||||||
char *p;
|
char *p;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If our argument is NULL, we don't know the current directory
|
* If our argument is NULL, we don't know the current directory
|
||||||
@ -286,9 +282,7 @@ findcwd(char *dir)
|
|||||||
*/
|
*/
|
||||||
if (dir == NULL || curdir == NULL)
|
if (dir == NULL || curdir == NULL)
|
||||||
return getpwd2();
|
return getpwd2();
|
||||||
len = strlen(dir);
|
cdcomppath = stsavestr(dir);
|
||||||
cdcomppath = stalloc(len + 1);
|
|
||||||
memcpy(cdcomppath, dir, len + 1);
|
|
||||||
STARTSTACKSTR(new);
|
STARTSTACKSTR(new);
|
||||||
if (*dir != '/') {
|
if (*dir != '/') {
|
||||||
STPUTS(curdir, new);
|
STPUTS(curdir, new);
|
||||||
|
@ -1284,11 +1284,8 @@ addfname(char *name)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
struct strlist *sp;
|
struct strlist *sp;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
len = strlen(name);
|
p = stsavestr(name);
|
||||||
p = stalloc(len + 1);
|
|
||||||
memcpy(p, name, len + 1);
|
|
||||||
sp = (struct strlist *)stalloc(sizeof *sp);
|
sp = (struct strlist *)stalloc(sizeof *sp);
|
||||||
sp->text = p;
|
sp->text = p;
|
||||||
*exparg.lastp = sp;
|
*exparg.lastp = sp;
|
||||||
|
@ -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
|
void
|
||||||
setstackmark(struct stackmark *mark)
|
setstackmark(struct stackmark *mark)
|
||||||
|
@ -52,6 +52,7 @@ void ckfree(pointer);
|
|||||||
char *savestr(const char *);
|
char *savestr(const char *);
|
||||||
pointer stalloc(int);
|
pointer stalloc(int);
|
||||||
void stunalloc(pointer);
|
void stunalloc(pointer);
|
||||||
|
char *stsavestr(const char *);
|
||||||
void setstackmark(struct stackmark *);
|
void setstackmark(struct stackmark *);
|
||||||
void popstackmark(struct stackmark *);
|
void popstackmark(struct stackmark *);
|
||||||
char *growstackstr(void);
|
char *growstackstr(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user