Module Name: src
Committed By: kre
Date: Tue Nov 16 16:57:15 UTC 2021
Modified Files:
src/bin/pwd: pwd.c
src/bin/sh: cd.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/bin/pwd/pwd.c
cvs rdiff -u -r1.51 -r1.52 src/bin/sh/cd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/pwd/pwd.c
diff -u src/bin/pwd/pwd.c:1.22 src/bin/pwd/pwd.c:1.23
--- src/bin/pwd/pwd.c:1.22 Mon Aug 29 14:51:19 2011
+++ src/bin/pwd/pwd.c Tue Nov 16 16:57:15 2021
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
#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 @@ main(int argc, char *argv[])
(void)printf("%s\n", p);
+ (void)fflush(stdout);
+ if (ferror(stdout))
+ err(EXIT_FAILURE, "stdout");
+
exit(EXIT_SUCCESS);
/* NOTREACHED */
}
Index: src/bin/sh/cd.c
diff -u src/bin/sh/cd.c:1.51 src/bin/sh/cd.c:1.52
--- src/bin/sh/cd.c:1.51 Sun Oct 31 02:12:01 2021
+++ src/bin/sh/cd.c Tue Nov 16 16:57:15 2021
@@ -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 @@ pwdcmd(int argc, char **argv)
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;
}