diff mbox series

[RFC,v5] edit: change the 'l_edit_enter' return signature from 'char *' to 'int'

Message ID 20240405002011.3480886-8-gerickson@nuovations.com (mailing list archive)
State New
Headers show
Series [RFC,v5] edit: change the 'l_edit_enter' return signature from 'char *' to 'int' | expand

Checks

Context Check Description
tedd_an/pre-ci_am fail error: ell/edit.c: does not exist in index error: ell/edit.h: does not exist in index hint: Use 'git am --show-current-patch' to see the failed patch

Commit Message

Grant Erickson April 5, 2024, 12:20 a.m. UTC
Using an 'int' signature with 0 for success and < 0 for failure with
failure enumerations sources from the negated POSIX errors from errno.h
eases system integration by precluding system integrators from having
to synthesize their own errors on the prior 'false' returns.

In addition, this sets the stage for better error handling of the
'wcstombs' and 'mbstowcs' functions.

The entered line is now returned via a return parameter.
---
 ell/edit.c | 12 +++++++++---
 ell/edit.h |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ell/edit.c b/ell/edit.c
index d6329d063c78..6747f92e289e 100644
--- a/ell/edit.c
+++ b/ell/edit.c
@@ -403,14 +403,14 @@  LIB_EXPORT bool l_edit_is_empty(struct l_edit *edit)
 	return (edit->main->len == 0);
 }
 
-LIB_EXPORT char *l_edit_enter(struct l_edit *edit)
+LIB_EXPORT int l_edit_enter(struct l_edit *edit, char **line)
 {
 	struct input_buf *buf;
 	char *str;
 	size_t len;
 
 	if (!edit)
-		return NULL;
+		return -EINVAL;
 
 	/* Convert the wide character string into the multibyte string
 	 * representation like UTF-8 for example.
@@ -458,9 +458,15 @@  LIB_EXPORT char *l_edit_enter(struct l_edit *edit)
 	}
 
 	edit->main = edit->head;
+
 	update_display(edit);
 
-	return str;
+	if (line)
+		*line = str;
+	else
+		l_free(str);
+
+	return 0;
 }
 
 LIB_EXPORT int l_edit_reset(struct l_edit *edit, const char *input)
diff --git a/ell/edit.h b/ell/edit.h
index 811246578894..425039733ad0 100644
--- a/ell/edit.h
+++ b/ell/edit.h
@@ -36,7 +36,7 @@  int  l_edit_set_max_input_length(struct l_edit *edit, size_t len);
 int  l_edit_set_history_size(struct l_edit *edit, unsigned int size);
 int  l_edit_refresh(struct l_edit *edit);
 bool l_edit_is_empty(struct l_edit *edit);
-char *l_edit_enter(struct l_edit *edit);
+int  l_edit_enter(struct l_edit *edit, char **line);
 int  l_edit_reset(struct l_edit *edit, const char *input);
 int  l_edit_insert(struct l_edit *edit, wint_t ch);
 int  l_edit_delete(struct l_edit *edit);