Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stderr redirection #3373

Merged
merged 1 commit into from Jun 7, 2015
Merged

Fix stderr redirection #3373

merged 1 commit into from Jun 7, 2015

Conversation

AMDmi3
Copy link
Contributor

@AMDmi3 AMDmi3 commented Mar 26, 2015

You cannot modify dereferenced FILE, this is UB. FILE may also be
opaque type so this code may not compile (and in fact it doesn't
compile on DragonFlyBSD). freopen is quite enough to do the thing.

@robn
Copy link
Member

robn commented Mar 26, 2015

freopen has been seen to fail (though I don't remember which platform), which is why the fallback us there. Unfortunately I don't remember the details and can't find them anywhere, so I don't remember why.

I'm happy to switch to just freopen for now, and if it causes problems somewhere then we can bring the fallback path back wrapped in some defines.

Does freopen preserve buffering modes? I can't find anything conclusive. If not, then we should probably still set line-buffering explicitly.

You cannot modify dereferenced FILE, this is UB. FILE may also be
opaque type so this code may not compile (and in fact it doesn't
compile on DragonFlyBSD). freopen is quite enough to do the thing.
@AMDmi3
Copy link
Contributor Author

AMDmi3 commented Mar 27, 2015

Does freopen preserve buffering modes?

Can't find explicit statements regarding this in the standard, but my guess is that it doesn't (at least unless first argument is NULL) - it closes the old stream and opens the new one just like fopen will do.

I've actually missed that setvbuf is called even if freopen succeeds, redoing the patch.

@johnbartholomew johnbartholomew merged commit b63c4a6 into pioneerspacesim:master Jun 7, 2015
@johnbartholomew
Copy link
Contributor

I'm not sure why this wasn't merged back in March, but it sounds from robn's comment like he intended to merge it, so I've done that.

@AMDmi3 AMDmi3 deleted the redirect-stdio-fix branch December 5, 2016 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants