Changeset 26798 for main/trunk/greenstone2/common-src/src/getpw/getpw.cpp
- Timestamp:
- 2013-01-29T16:22:48+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/getpw/getpw.cpp
r26649 r26798 120 120 #endif 121 121 122 123 #if defined(__ANDROID__) 124 125 // See: 126 // http://stackoverflow.com/questions/1196418/getting-a-password-in-c-without-using-getpass-3 127 128 #include <stdio.h> 129 #include <stdlib.h> 130 #include <termios.h> 131 132 char* getpass(const char* prompt) 133 { 134 struct termios oflags, nflags; 135 char* password = (char*)malloc(64); 136 137 /* disabling echo */ 138 tcgetattr(fileno(stdin), &oflags); 139 nflags = oflags; 140 nflags.c_lflag &= ~ECHO; 141 nflags.c_lflag |= ECHONL; 142 143 if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { 144 perror("tcsetattr"); 145 return NULL; 146 } 147 148 printf(prompt); 149 fgets(password, sizeof(password), stdin); 150 password[strlen(password) - 1] = 0; 151 152 /* restore terminal */ 153 if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { 154 perror("tcsetattr"); 155 return NULL; 156 } 157 158 return password; 159 } 160 #endif 161 162 163 164 122 165 int main (int argc, char *argv[]) { 123 166
Note:
See TracChangeset
for help on using the changeset viewer.