Getting the ^D
owengage.com
owengage.com
It's not a good example, because bash disables the canonical mode. When you type ^D this happens:
read(0, "\4", 1) = 1
(And then bash ignores the read EOT character.)You could spend 8 hours describing it from power, to USB descriptors, to debouncing, to keymapping, to matrix scanning, to ptys, to editor string management algorithms to Lisp. And passing by this article as well!
To override the character for "EOF," change ^D to something else in the following command and run it:
stty eof ^DA program reading from a file handle other than a pseudo-terminal or a pseudo-terminal set to be in "raw mode" will behave as you describe.
ANSI C defines EOF, the 2nd edition by Kernighan and Ritchie page 151 states 'getchar returns the next input character each time it is called, or EOF when it encounters end of file. The symbolic constant EOF is defined in <stdio.h>.
The value is typically -1, bit tests should be written in terms of EOF so as to be independent of the specific value.'
Its value is platform dependent. As per the C++ standard[0]:
It is a macro definition of type int that expands into
a negative integral constant expression (generally, -1).
0 - https://cplusplus.com/reference/cstdio/EOF/Is this particular citation, "wrong, out of date, or just missing things"?
Sending a special EOT 0x4 that gets special terminal and kernel handling feels just a little less… elegant… than what I had imagined.
I am curious now, would it be possibly to make a keyboard generate a NULL byte either by existing keyboard shortcut or custom hardware - and how the system would handle it? My guess would be that keyboards sending NULL might not be possible over keyboard protocol at all but I genuinely have no idea.
^@ produces the NUL character.
Not sure I understand the point of the experiment, but in NetBSD kernel one can remap the keyboard, e.g., set a key to 0x00. How to do this in Linux kernel is a question for reader.
https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/dev...