* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#endif
#endif /* not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/cd.c 294667 2016-01-24 17:01:34Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/cd.c 320340 2017-06-25 21:53:08Z jilles $");
#include <sys/types.h>
#include <sys/stat.h>
if ((phys || (rc = cdlogical(dest)) < 0) && (rc = cdphysical(dest)) < 0)
return (-1);
- if (print && iflag && curdir)
+ if (print && iflag && curdir) {
out1fmt("%s\n", curdir);
+ /*
+ * Ignore write errors to preserve the invariant that the
+ * current directory is changed iff the exit status is 0
+ * (or 1 if -e was given and the full pathname could not be
+ * determined).
+ */
+ flushout(out1);
+ outclearerror(out1);
+ }
return (rc);
}