Skip to content

Commit d7cf4f2

Browse files
committed
52509: manage internals of stdio objects when performing redirections.
1 parent 85545af commit d7cf4f2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2024-01-28 Bart Schaefer <[email protected]>
2+
3+
* 52509: configure.ac, Src/utils.c: manage internals of stdio
4+
objects when performing redirections.
5+
16
2024-01-28 Oliver Kiddle <[email protected]>
27

38
* 52500: Src/Zle/zle.h, Src/Zle/zle_refresh.c, Src/prompt.c:

Src/utils.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,28 @@ redup(int x, int y)
20082008
{
20092009
int ret = y;
20102010

2011+
#ifdef HAVE_FPURGE
2012+
/* Make sure buffers are cleared when changing descriptor for a
2013+
* FILE object. No fflush() here because the only way anything
2014+
* can legitimately be left in the buffer is when an error has
2015+
* occurred, so attempting flush here would at best error again
2016+
* and at worst squirt out something unexpected.
2017+
*/
2018+
if (stdout && y == fileno(stdout))
2019+
fpurge(stdout);
2020+
if (stderr && y == fileno(stderr))
2021+
fpurge(stderr);
2022+
if (shout && y == fileno(shout))
2023+
fpurge(shout);
2024+
if (xtrerr && y == fileno(xtrerr))
2025+
fpurge(xtrerr);
2026+
#ifndef _IONBF
2027+
/* See init.c setupshin() -- stdin otherwise unbuffered */
2028+
if (stdin && y == fileno(stdin))
2029+
fpurge(stdin);
2030+
#endif
2031+
#endif
2032+
20112033
if(x < 0)
20122034
zclose(y);
20132035
else if (x != y) {

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
12951295
select poll \
12961296
readlink faccessx fchdir ftruncate \
12971297
fstat lstat lchown fchown fchmod \
1298-
fseeko ftello \
1298+
fpurge fseeko ftello \
12991299
mkfifo _mktemp mkstemp \
13001300
waitpid wait3 \
13011301
sigaction sigblock sighold sigrelse sigsetmask sigprocmask \

0 commit comments

Comments
 (0)