Repository navigation
Conversation
Reads and writes terminal attributes, and is the last unimplemented tool. Verified against GNU 9.4 in a pty: all 13 cases byte-identical, including the non-tty error path. -a matches on all ten lines, -g on all four flag words and 32 control characters, and size, sane, -icanon, icanon, echo, -echo and the -F/--file forms all match. Four things were measured rather than recalled, and each was a bug: V's termios.Termios has a different layout from glibc's struct termios. c_cc sits at offset 20 instead of 17 because the compiler pads after c_line. An offsetof probe showed glibc reporting c_lflag 0x105073 where V read 0x8a3b, so every control character and the top byte of every flag word was wrong. This port includes termios.h and uses C.termios directly. The \ format does not apply to a C-typed field. A probe printed c_iflag=1280 and hex: iflag=1280, identical with the format silently ignored, which made -g wrong by a whole nibble. Each word is cast to u32 first. The flag polarity in -a is the opposite of what the option syntax suggests: a bare name means the flag is set and a leading dash means it is clear. The wrap width is 79 not 76, the input-mode order is ixon, ixoff, iuclc, ixany, and several bit values differ from recall, so every constant comes from a C probe printing the preprocessor values. Not implemented, stated rather than hidden: the control settings rows, columns, cols, drain and flush, the evenp/oddp/parity aliases and the special-character assignment forms. The suite is stty_nix_test.v because termios.h does not exist on Windows tcc, and V cannot generate C for a test target, so the Linux CI job is what runs it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sttyreads and writes terminal attributes, and is the last unimplemented tool.Verified against GNU 9.4 in a pty — all 13 cases byte-identical, including the non-tty error path:
stty -a/--allstty -g/--savestty sizestty -icanon/icanonstty echo/-echostty sanestty -F/--file=sttyon a non-ttyFour things had to be measured rather than recalled, and each one was a bug:
termios.Termioshas a different layout from glibc'sstruct termios.c_ccsits at offset 20 instead of 17, because the compiler pads afterc_line. Anoffsetofprobe on this host showed glibc reportingc_lflag 0x105073where V read0x8a3b— every control character and the top byte of every flag word was wrong. This port includes<termios.h>and usesC.termiosdirectly, importingterm.termiosonly so its declarations come into scope.${x}does not hex-format a C-typed field. A probe printedc_iflag=1280andhex: iflag=1280— identical, with the format silently ignored, which made-goutput wrong by a whole nibble. Each word is cast tou32before formatting.-a. GNU prints a bare name for a set flag and a leading dash for a clear one, which is the opposite of what the option syntax suggests.ixon, ixoff, iuclc, ixany— GNU'sioxn/ixoffbit values also differ from the value recall suggests, so every constant below comes from a C probe printing the preprocessor values rather than from memory.Not implemented, stated rather than hidden: the
-i/-o/-ebuffer-size options ofstdbuf-style control, therows/columns/cols/drain/flushsettings, thestty -Fdevice-name quoting beyond space handling,evenp/oddp/parity(they are the same bits asparenb/parodd), and the special-character assignment formserase ^C,intr ^X,min 1,time 0. The full list of boolean modes is present, and-a,-g,size,saneand the flag mutations match byte for byte.Note: the test suite is
stty_nix_test.vbecausetermios.hdoes not exist on Windows' tcc, andsttyis already inbuild.vsh's Windows ignore list. V cannot generate C for a test target, sov testcannot run this suite on Windows at all; the Linux CI job is what executes it.