by emilfihlman · 6y ago · 0 comments
If you close stderr, 2 becomes available and can be handed out.
Also it's not exactly guaranteed that 0, 1 and 2 are the fd numbers for stdin, out and err on program start, but they are hard coded and standard.
E: It's implementation defined, ie not guaranteed. Your platform may make guarantees about it, but it is not an actual standard.
Yes, it is.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/s...
> On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively.
Then, after program startup, if it is closed, then fd 2 could be assigned to something else.
> The following symbolic values in <unistd.h> define the file descriptors that shall be associated with the C-language stdin, stdout, and stderr when the application is started:
> STDIN_FILENO Standard input value, stdin. Its value is 0.
> STDOUT_FILENO Standard output value, stdout. Its value is 1.
> STDERR_FILENO Standard error value, stderr. Its value is 2.