($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 v8] ell/term: Return error on writes if the output descriptor is invalid.
Date: Thu,  4 Apr 2024 17:36:55 -0700	[thread overview]
Message-ID: <20240405003658.3490494-7-gerickson@nuovations.com> (raw)
In-Reply-To: <20240405003658.3490494-1-gerickson@nuovations.com>

Returns -EBADF for 'putnstr' and 'vdprintf' if the output descriptor
for the terminal is invalid.
---
 ell/term.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ell/term.c b/ell/term.c
index c867b240090c..7ec92476e14e 100644
--- a/ell/term.c
+++ b/ell/term.c
@@ -391,6 +391,9 @@ LIB_EXPORT int l_term_putnstr(struct l_term *term, const char *str, size_t n)
 	if (!term)
 		return -EINVAL;
 
+	if (term->out_fd < 0)
+		return -EBADF;
+
 	res = write(term->out_fd, str, n);
 	if (res < 0)
 		return -errno;
@@ -432,6 +435,9 @@ LIB_EXPORT int l_term_vprint(struct l_term *term, const char *str, va_list ap)
 	if (!term || !str)
 		return -EINVAL;
 
+	if (term->out_fd < 0)
+		return -EBADF;
+
 	if (vdprintf(term->out_fd, str, ap) < 0)
 		return -errno;
 
-- 
2.42.0


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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05  0:36 [RFC PATCH v8] Input/Output Terminal Abstraction Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] term: Initial revision Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] ell: Add include directive for 'ell/term.h' Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] ell/Makefile: Added 'term.[ch]' to HEADERS and SOURCES Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] term: Added 'l_term_*' symbols Grant Erickson
2024-05-16  8:16   ` Martin Hundebøll
2024-05-16 15:35     ` Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] ell/term: Do not return -EPERM for 'putnstr' and 'vprint' if not running Grant Erickson
2024-04-05  0:36 ` Grant Erickson [this message]
2024-04-05  0:36 ` [RFC PATCH v8] ell/edit: Rename 'l_term_{open,close}' Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] ell/term: Add an 'l_term_is_acquired' introspection function Grant Erickson
2024-04-05  0:36 ` [RFC PATCH v8] ell/term: Added ASCII C0 and C1 control code mnemonics 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=20240405003658.3490494-7-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).