Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Also it's not exactly guaranteed that 0, 1 and 2 are the fd numbers for stdin, out and err on program start

Yes, it is.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/s...



You’re right, but it’s more than that: stderr is defined to be fd 2. Whatever is assigned to that fd, is the stderr. If you close it and open something else, that something becomes your stderr.


You must differentiate between a guarantee by an actual standard and platform specific documentation.


That is a guarantee by an actual standard. More specifically, it's one of the things that POSIX.1-2017 guarantees but the ISO C standard does not. In practical terms this means that all Unix-like systems use the traditional fd numbers for stdin, stdout and stderr but it's possible that non-Unix systems might not.


(Standard C doesn't have file descriptors at all, it has FILE * file handles).


Can you tell me what the "std" in "IEEE Std 1003.1-2017" stands for?


He linked an actual standard.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: