summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/line.c24
2 files changed, 25 insertions, 2 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 1be37a960e4..ffb982be5fc 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.87 2006/05/08 21:24:24 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.88 2006/05/27 21:20:11 kjell Exp $ */
/* This file is in the public domain. */
@@ -350,6 +350,7 @@ int lnewline(void);
int ldelete(RSIZE, int);
int ldelnewline(void);
int lreplace(RSIZE, char *);
+char * linetostr(const struct line *);
/* yank.c X */
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 3178bcc6b30..014a0581e7f 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.37 2005/12/20 06:17:36 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.38 2006/05/27 21:20:11 kjell Exp $ */
/* This file is in the public domain. */
@@ -569,3 +569,25 @@ lreplace(RSIZE plen, char *st)
undo_add_boundary();
return (TRUE);
}
+
+/*
+ * Allocate and return the supplied line as a C string
+ */
+char *
+linetostr(const struct line *ln)
+{
+ size_t len;
+ char *line;
+
+ len = llength(ln);
+ if (len == SIZE_MAX) /* (len + 1) overflow */
+ return (NULL);
+
+ if ((line = malloc(len + 1)) == NULL)
+ return (NULL);
+
+ (void)memcpy(line, ltext(ln), len);
+ line[len] = '\0';
+
+ return (line);
+}