commit b710ee81fcdb077d6ff088aa5beab021f58dc3d9
Author: Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Wed Nov 29 08:39:32 2023 +0100
Commit: k0ga <Roberto E. Vargas Caballero [email protected]>
CommitDate: Thu Dec 28 14:01:30 2023 +0100
ed: Add copystring()
This makes possible to use the function to initialize the string from
an existing char array.
diff --git a/ed.c b/ed.c
index b430e74..d5ac2e3 100644
--- a/ed.c
+++ b/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)
{