1 // natVMConsole.cc - Native part of VMConsole class.
2 
3 /* Copyright (C) 2012
4    Free Software Foundation
5 
6    This file is part of libgcj.
7 
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License.  Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
10 details.  */
11 
12 #include <config.h>
13 
14 #include <termios.h>
15 #include <unistd.h>
16 
17 #include <gcj/cni.h>
18 
19 #include <java/io/Console.h>
20 #include <java/io/VMConsole.h>
21 
22 #ifndef IUCLC
23 #define IUCLC 0
24 #endif
25 
26 #define TERMIOS_ECHO_IFLAGS (IUCLC|IXON|IXOFF|IXANY)
27 #define TERMIOS_ECHO_LFLAGS (ECHO|ECHOE|ECHOK|ECHONL|TOSTOP)
28 
29 jstring
readPassword(::java::io::Console * con)30 java::io::VMConsole::readPassword(::java::io::Console *con)
31 {
32   struct termios oldt, newt;
33   jstring result;
34 
35   tcgetattr (STDIN_FILENO, &oldt);
36 
37   tcgetattr (STDIN_FILENO, &newt);
38 
39   newt.c_iflag &= ~TERMIOS_ECHO_IFLAGS;
40   newt.c_lflag &= ~TERMIOS_ECHO_LFLAGS;
41 
42   tcsetattr (STDIN_FILENO, TCSANOW, &newt);
43 
44   result = con->readLine ();
45 
46   tcsetattr (STDIN_FILENO, TCSANOW, &oldt);
47 
48   return result;
49 }
50