ed: Add copystring()

This makes possible to use the function to initialize the string from
an existing char array.
This commit is contained in:
Roberto E. Vargas Caballero 2023-11-29 08:39:32 +01:00 committed by k0ga
parent 4cf7643094
commit b710ee81fc
1 changed files with 18 additions and 0 deletions

18
ed.c
View File

@ -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)
{