News for hackers. Stuff that matters.
Re:#include </etc/shadow> by adwn on Tuesday December 17, 2019 @12:47AM (#21811015)
> Why is this surprising? Do programmers not read books anymore? [...]

No need to be condescending. Three reasons:

1) A sophisticated compiler might read the length of a file before loading it, so that it can allocate a buffer of the right size. Doesn't work with /dev/stdin.

2) Alternatively, it might read the file via mmap(). Doesn't work with /dev/stdin.

3) Furthermore, it might check whether the file is a regular file. If not, it is almost certainly not what the programmer had in mind.

Re:#include </etc/shadow> by zonidjan on Tuesday December 17, 2019 @03:04AM (#21811611)
> 1) A sophisticated compiler might read the length of a file before loading it, so that it can allocate a buffer of the right size. Doesn't work with /dev/stdin.

gcc does this. It appears to be why /proc files don't work. gcc sees that stat calls it a 'regular file' and 0 bytes long, and actually performs a read() syscall with a length of 0.

> 3) Furthermore, it might check whether the file is a regular file. If not, it is almost certainly not what the programmer had in mind.

gcc probably does this. (It would explain why /dev/stdin works)