Re: STDOUT_FILENO and STDERR_FILENO



John Emmas schreef op ma 20-05-2013 om 14:06 [+0100]:
Also (in 
theory) it should only attempt to write to the console if stdout / 
stderr appears to be valid (hopefully Windows would set them to NULL if 
they weren't valid?).

The documentation about the Win32 API function fileno() has this to say
about that specific situation:

  In Visual C++ 2005, there is a behavior change. If stdout or
  stderr is not associated with an output stream (for example, in
  a Windows application without a console window), the file
  descriptor returned is -2. In previous versions, the file
  descriptor returned was -1. This change allows applications
  to distinguish this condition from an error.

http://msdn.microsoft.com/en-us/library/zs6wbdhx%28v=vs.80%29.aspx

So when there is no valid stdout/stderr the fileno call will return
either -1 or -2. When this value is passed as argument to a write call,
then the write call itself will fail with an 'invalid file descriptor',
but other than that there's shouldn't be any major issues with it.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]