4 ms·
Very interesting, my naive assumption up to now had honestly been that ^D was just the shortcut for a NULL byte, 0x0 and everything just thus assumed it’d reach
by donatj 4y ago
Very interesting, my naive assumption up to now had honestly been that ^D was just the shortcut for a NULL byte, 0x0 and everything just thus assumed it’d reached the end of the stream and finished up based on that.
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.
- wruza 4y agoPlease look at ascii table to see why ctrl-{key} sends a corresponding control code and why the modifier is called “control”: https://www.commfront.com/pages/ascii-chart https://www.commfront.com/pages/ascii-chart
- donatj 4y agoThe article explained it well enough. Makes sense, I just was unaware. From that chart though then could ^` generate a NULL byte?
- proto_lambda 4y agoThe chart also lists the control key combination for each control byte, for NUL, it's C-@.
- jwilk 4y ago^` works too.
- tuukkah 4y agoIf EOF was a character, you couldn't process (binary) streams that contain the character. ^@ produces the NUL character.
- 1vuio0pswjnm7 4y ago"I am curious now, would it be possible to make the keyboard generate a NULL byte either by existing keyboard shortcut or custom hardware - and how would the system handle it?" 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/wscons/wsksymdef.h https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/dev...
- layer8 4y agoThe NUL byte has no special meaning in file I/O, or the terminal. (Historically, the only special meaning was as a no-op character that does nothing.) The convention of using NUL as a termination character only exists for in-memory strings in C, and has no connection to file I/O.