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.
bouyer-sunxi-drm
kre 2021-11-16 16:57:15 +00:00
parent 8ea2ac47d5
commit b6dd340d3c
2 changed files with 15 additions and 4 deletions

View File

@ -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, 1993, 1994\
#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 */
}

View File

@ -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;
}