[Argh, resending, b/c got the recipient-list wrong]
Perhaps this has changed in the N years since last I worked with sgttyb/termios. But back in the day, the answer was "there is no portable way; the usual way is to manipulate terminal (actually, serial-port) attributes".
This is less difficult than it seems: there should be support in ncurses for it, and there should be a portable API between glibc (on Unixes) and cygwin (on Winders).
I *do* think it would be worth looking at (for instance) the code of sudo, to see what libraries it calls.
OK, I'm done, lemme adjust this onion on my belt,
--chet--
P.S. i re-reading the above (for resend) I'm being unclear. So I'll restate: the standard way that I've seen this done (many times over the years) is to manipulate the state of the serial-port and the "line-discipline" (that is, the equivalent of using the "stty" command). This is not connected with issuing terminal escape-sequences, because the former changes what is actually sent on the wire, whereas the latter changes only what is displayed in the virtual or real terminal. E.g. "stty -echo" disables the echoing of characters in the line-discipline -- whatever you type into a TTY, the kernel-level terminal-driver will not echo those chars back. Whereas telling the terminal emulator (or real terminal) to not display chars, doesn't change that the chars are actually sent.
It's possible that this is a difference without relevance at this point in the evolution of UNIX software. But for sure, it was manipulation of line-discipline characteristics, that was the means of disabling echo, "back in the day".