($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Grant Erickson <gerickson@nuovations.com>
To: ell@lists.linux.dev
Cc: Marcel Holtmann <marcel@holtmann.org>
Subject: [RFC PATCH v5] edit: change the 'l_edit_enter' return signature from 'char *' to 'int'
Date: Thu,  4 Apr 2024 17:20:10 -0700	[thread overview]
Message-ID: <20240405002011.3480886-8-gerickson@nuovations.com> (raw)
In-Reply-To: <20240405002011.3480886-1-gerickson@nuovations.com>

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 --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);
-- 
2.42.0


  parent reply	other threads:[~2024-04-05  0:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05  0:20 [RFC PATCH v5] Line Editor Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] edit: Initial revision Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] ell: Add include directive for 'ell/edit.h' Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] ell/Makefile: Added 'edit.[ch]' to HEADERS and SOURCES Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] edit: Added 'l_edit_*' symbols Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] edit: pass the l_edit instance to the display and debug handlers Grant Erickson
2024-04-05  0:20 ` [RFC PATCH v5] edit: change return signatures from 'bool' to 'int' Grant Erickson
2024-04-05  0:20 ` Grant Erickson [this message]
2024-04-05  0:20 ` [RFC PATCH v5] edit: improve error handling of 'mbstowcs' and 'wcstombs' functions Grant Erickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240405002011.3480886-8-gerickson@nuovations.com \
    --to=gerickson@nuovations.com \
    --cc=ell@lists.linux.dev \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).