Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin Make pwd (both /bin/pwd and the /bin/sh built-in version...



details:   https://anonhg.NetBSD.org/src/rev/23a3957c0b48
branches:  trunk
changeset: 1026287:23a3957c0b48
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Nov 16 16:57:15 2021 +0000

description:
Make pwd (both /bin/pwd and the /bin/sh built-in version) check for
write errors on stdout, and indicate an error if that happens.

diffstat:

 bin/pwd/pwd.c |   8 ++++++--
 bin/sh/cd.c   |  11 +++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diffs (63 lines):

diff -r 495af84690c9 -r 23a3957c0b48 bin/pwd/pwd.c
--- a/bin/pwd/pwd.c     Tue Nov 16 11:28:29 2021 +0000
+++ b/bin/pwd/pwd.c     Tue Nov 16 16:57:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pwd.c,v 1.22 2011/08/29 14:51:19 joerg Exp $ */
+/* $NetBSD: pwd.c,v 1.23 2021/11/16 16:57:15 kre Exp $ */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)pwd.c      8.3 (Berkeley) 4/1/94";
 #else
-__RCSID("$NetBSD: pwd.c,v 1.22 2011/08/29 14:51:19 joerg Exp $");
+__RCSID("$NetBSD: pwd.c,v 1.23 2021/11/16 16:57:15 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -107,6 +107,10 @@
 
        (void)printf("%s\n", p);
 
+       (void)fflush(stdout);
+       if (ferror(stdout))
+               err(EXIT_FAILURE, "stdout");
+
        exit(EXIT_SUCCESS);
        /* NOTREACHED */
 }
diff -r 495af84690c9 -r 23a3957c0b48 bin/sh/cd.c
--- a/bin/sh/cd.c       Tue Nov 16 11:28:29 2021 +0000
+++ b/bin/sh/cd.c       Tue Nov 16 16:57:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd.c,v 1.51 2021/10/31 02:12:01 kre Exp $      */
+/*     $NetBSD: cd.c,v 1.52 2021/11/16 16:57:15 kre Exp $      */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)cd.c       8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: cd.c,v 1.51 2021/10/31 02:12:01 kre Exp $");
+__RCSID("$NetBSD: cd.c,v 1.52 2021/11/16 16:57:15 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -364,8 +364,15 @@
                if (curdir == NULL)
                        error("Unable to find current directory");
        }
+
+       flushout(out1);         /* make sure buffer is empty */
+       clr_err(out1);          /* and forget any earlier errors */
        out1str(curdir);
        out1c('\n');
+       flushout(out1);
+       if (io_err(out1))
+               error("stdout: %s", strerror(errno));
+
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index