sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit b710ee81fcdb077d6ff088aa5beab021f58dc3d9
parent 4cf7643094e76bab00c5ba370effca3e72f2c7ba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 29 Nov 2023 08:39:32 +0100

ed: Add copystring()

This makes possible to use the function to initialize the string from
an existing char array.

Diffstat:
Med.c | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/ed.c b/ed.c @@ -122,6 +122,24 @@ prevln(int 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) { free(s->str);