What a coincidence. I recently converted the 6502 version to Python and then worked with ChatGPT to convert the Python to C. (I'm not a C programmer.)
https://github.com/gabrielsroka/gabrielsroka.github.io/tree/...
https://github.com/gabrielsroka/gabrielsroka.github.io/tree/...
If you hit Ctrl-d on this code it will burn through that loop constantly with no input. You need to check fgets()'s return code, it will be NULL on error or eof.
I assume you're talking about Linux/Unix. I'm mostly a Windows guy.
The Windows version of mprotect(2) is VirtualProtect. It would probably make more sense to allocate the buffer with VirtualAlloc with the correct flags, rather than modify a stack buffer. The Unix version of that would be to allocate with mmap(2).
Edit: https://github.com/gabrielsroka/gabrielsroka.github.io/pull/...