Obscure fact #37: Glibc's implementation of <i>freopen</i> opens /proc/self/fd/<n>, when the pathname is null, e.g.:<p><pre><code> freopen(NULL, "w", stdout);</code></pre>
Doesn't the Linux behavior make more sense? It basically guarantees that open() always returns a new file description. Having open() return an existing file description for some special files seems like a recipe for exploits. Dup() already exists for this purpose.
> Unix processes have <i>file descriptors</i> which point to <i>file descriptions</i> (`struct file` in Linux).<p>Also known as <i>file handles</i> referencing <i>file objects</i> (on Windows). Unix terminology is unnecessarily confusing in this place IMHO.<p>On the subject of the article itself: why was this change introduced? To give kernel support for reopen(3) since dup(3) already exists?
I can't be the only one who dreams of a radically different successor to Linux when I read stuff like this. Like, why do I need to care about file descriptors? Why is everything a file, except its not because it can be a socket, or a pipe, or a block device, or something else I haven't heard about? Why does the OS even care what my current working directory is? How are we ever going to get rid of C when the whole OS interface is defined in C? Even with the simplest program, running in a single thread (or is it pthread?), I can't control the flow of execution because suddently SIGNALS happen and who knows what'll happen then. Like, you could use select(2), but you should use pselect(2) to deal with signals, except select(2) should not be used because it can't deal with PIDs larger than 1024, so use poll(2), or maybe epoll(7), or ppoll(2) if you want to deal with signals, but what happens when you use epoll(7) and have to deal with signals? And did you notice all those numbers next to the syscall names? Wait, what do you mean syscall, is it not a function? And of course, to create a new process, you use a syscall called fork(), because processes and cutlery are intrinsically linked.<p>Honestly, the OS situation is a mess and I just want to not think about it, but not having an OS is not really an option.