logoalt Hacker News

mgerdtslast Thursday at 7:51 PM3 repliesview on HN

What is up with fin? Is it really just writing an int 0 in the memory right after some variable present in libc or similar?

        extern fin;

        if(getpw(0, pwbuf))
                goto badpw;
        (&fin)[1] = 0;

Replies

oguz-ismail2last Thursday at 8:24 PM

Predecessor of

    extern FILE *stdin;
formerly_provenlast Thursday at 9:32 PM

I’m guessing v4 C didn’t have structs yet (v6 C does, but struct members are actually in the global namespace and are basically just sugar for offset and a type cast; member access even worked on literals. That’s why structs from early unix APIs have prefixed member names, like st_mode.

show 2 replies
flatlinelast Thursday at 8:05 PM

According to the chatbot, the first word of `fin` is the file descriptor, the second its state. "Reset stdin’s flags to a clean state".