char *getpass(char *prompt) { static char result[64*2]; struct termios t; tcflag_t ol; int tv; int fd = open("/dev/tty", O_RDWR); if (fd == -1) return NULL; /* display the prompt */ write(fd, prompt, strlen(prompt)); tv = tcgetattr(fd, &t); ol = t.c_lflag; t.c_lflag &= ~ECHO|ECHOE|ECHOK; if (tv == 0) tcsetattr(fd, TCSANOW, &t); /* read the input */ if (_gets(fd, result, sizeof(result) - 1) == NULL) result[0] = 0; t.c_lflag = ol; if (tv == 0) tcsetattr(0, TCSANOW, &t); /* The newline isn't echoed as we have echo off, so we need to output it as the end of the task */ write(fd, "\n", 1); close(fd); return result; }
int main (int argc, char const* argv[]) { char s[255]; _gets(s); printf("%s", s); un_gets(s); _gets(s); printf("%s", s); _gets(s); printf("%s", s); un_gets(s); _gets(s); printf("%s", s); return 0; }
/* FIXME: should use /dev/tty interface eventually */ char *getpass(char *prompt) { static char result[128]; struct termios t; tcflag_t ol; int tv; /* display the prompt */ fputs(prompt, stdout); fflush(stdout); tv = tcgetattr(0, &t); ol = t.c_lflag; t.c_lflag &= ~ECHO|ECHOE|ECHOK; if (tv == 0) tcsetattr(0, TCSANOW, &t); /* read the input */ if (_gets(result, sizeof(result) - 1) == NULL) result[0] = 0; t.c_lflag = ol; if (tv == 0) tcsetattr(0, TCSANOW, &t); return result; }
int main() { char buf[64]; _printf("\n----------------welcome------------------\n"); _printf("s5pv210 farsight:\n"); _printf("CPU cortex A8 1GHz\n"); while(1) { _printf("fs@farsight#"); _gets(buf); //if( strncmp(buf, "run buzzer.bin", 14) == 0) //{ // _run_buzzer(); //} //else { _printf("error cmd :%s\n", buf); } } }
static inline char *gets(void) { CONSOLE_INIT("console"); _gets(&_buf_gets,255); return &_buf_gets; }