Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:50:02+00:00 2026-05-26T07:50:02+00:00

Here is the code of the functions: int getStream() { int fd = _dup(fileno(stdout));

  • 0

Here is the code of the functions:

int getStream()
    {
           int fd = _dup(fileno(stdout));
           freopen("tmp","w",stdout);
           return fd;
    }


void freeStream(int fd)
{
       _dup2(fd,fileno(stdout));
       close(fd);
}

The code of main program:

printf(“start tets”);
int fd = getStream();
printf(“redirection”);
freeStream(fd);

This is a part of large program which uses llvm
The problem I get after freeStream(fd): LLVM ERROR: IO failure on output stream.
I understand that the problem is with freeStream implementation.
What do you think?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:50:03+00:00Added an answer on May 26, 2026 at 7:50 am

    As Jason diagnosed, you need to fflush() the stream (stdout) before you close the underlying file (via the _dup2() call).

    Another problem is that there is no error checking in the code; you don’t know which, if any, of your function calls are failing. At least while resolving this issue, you need to monitor both freopen() and _dup2() to ensure they work.

    It is not clear that on Windows, you can reach behind the back of the <stdio.h> library and change the file descriptor. On Unix, I think it would likely work – not necessarily supported, but probably it would work. But I can easily imagine ways it fails on Windows (without being certain that my imagination is not simply being to vivid).

    Ultimately, I am not convinced there’s a portable way to reinstate stdout back to its original output after using freopen() on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the code here and I want all the functions which call SDL
I am getting this warning even though everything functions perfectly. Here is the code
Basically, here's my problem. I'm calling someone else's FORTRAN functions from my C++ code,
Here is my code: function currentCursPos(){ $(document).mousemove(function(e){ var pos= {"x":e.pageX,"y":e.pageY}; return pos }); }
Here is my code #include <iostream> using namespace std; class MyTestClass { int MyTestIVar;
I am just trying something with somebody else's code. I have two functions: int
Here is my code: function pauseSound() { var pauseSound = document.getElementById(backgroundMusic); pauseSound.pause(); } I
So here's my code: function csq($string) { $search = array(chr(145), chr(146), chr(147), chr(148), chr(151),
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
i've used jquery load method for a website pagination here is my code function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.