mirror of
git://git.suckless.org/sbase
synced 2025-01-02 21:12:15 +00:00
ed: Add copystring()
This makes possible to use the function to initialize the string from an existing char array.
This commit is contained in:
parent
4cf7643094
commit
b710ee81fc
18
ed.c
18
ed.c
@ -121,6 +121,24 @@ prevln(int line)
|
||||
return (line < 0) ? lastln : line;
|
||||
}
|
||||
|
||||
static String *
|
||||
copystring(String *s, char *from)
|
||||
{
|
||||
size_t len;
|
||||
char *t;
|
||||
|
||||
if ((t = strdup(from)) == NULL)
|
||||
error("out of memory");
|
||||
len = strlen(t);
|
||||
|
||||
free(s->str);
|
||||
s->str = t;
|
||||
s->siz = len;
|
||||
s->cap = len;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static String *
|
||||
string(String *s)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user