git: 4472fd66d006 - main - lam: fail on I/O errors

From: Allan Jude <allanjude_at_FreeBSD.org>
Date: Thu, 06 Jun 2024 17:25:55 UTC
The branch main has been updated by allanjude:

URL: https://cgit.FreeBSD.org/src/commit/?id=4472fd66d0067347e3123896ae1b33f8bd444d56

commit 4472fd66d0067347e3123896ae1b33f8bd444d56
Author:     Cosimo Cecchi <cosimo@apple.com>
AuthorDate: 2024-06-06 17:24:07 +0000
Commit:     Allan Jude <allanjude@FreeBSD.org>
CommitDate: 2024-06-06 17:24:15 +0000

    lam: fail on I/O errors
    
    I/O errors should be reported; however lam currently does not
    disambiguate between EOF because end-of-file was reached and EOF because
    an I/O error occurred.
    This commit changes lam to exit with EX_IOERR when an I/O error occurs.
    
    Reviewed by:    imp, allanjude
    Sponsored by:   Apple Inc.
    Differential Revision:  https://reviews.freebsd.org/D45437
---
 usr.bin/lam/lam.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/usr.bin/lam/lam.c b/usr.bin/lam/lam.c
index 68cb4b946575..2194ae7ab596 100644
--- a/usr.bin/lam/lam.c
+++ b/usr.bin/lam/lam.c
@@ -43,6 +43,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysexits.h>
 #include <unistd.h>
 
 #define	MAXOFILES	20
@@ -212,6 +213,9 @@ gatherline(struct openfile *ip)
 	*p = '\0';
 	if (c == EOF) {
 		ip->eof = 1;
+		if (ferror(ip->fp)) {
+			err(EX_IOERR, NULL);
+		}
 		if (ip->fp == stdin)
 			fclose(stdin);
 		morefiles--;