<div dir="ltr">Hello all,<div><br></div><div>I am writing the function to take the password from the user using the termios (3). So far I have </div><div><br></div><div><div>int get_pass(unsigned char *pwd)</div><div>{</div>
<div> struct termios oflags, nflags;</div><div> char password[MAX_PASS_LEN];</div><div> char pass2[MAX_PASS_LEN];</div><div><br></div><div> /* disabling echo */</div><div> tcgetattr(fileno(stdin), &oflags);</div>
<div> nflags = oflags;</div><div> nflags.c_lflag &= ~ECHO;</div><div> nflags.c_lflag |= ECHONL;</div><div><br></div><div> if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {</div><div> perror("tcsetattr");<br>
</div><div> }</div><div><br></div><div> printf("Password: ");</div><div> fgets(password, sizeof(password), stdin);</div><div> password[strlen(password) - 1] = 0;</div><div><br></div><div> while( strcmp(password,pass2) != 0){</div>
<div> printf("Again : ");</div><div> fgets(pass2, sizeof(pass2), stdin);</div><div> pass2[strlen(pass2) - 1] = 0;</div><div> }</div><div><br></div><div> memcpy(pwd,password,strlen(password));</div>
<div><br></div><div> /* restore terminal */</div><div> if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {</div><div> perror("tcsetattr");</div><div> return EXIT_FAILURE;</div><div> }</div>
<div><br></div><div> return 0;</div><div>}</div></div><div><br></div><div><br></div><div>This works fine when I run this by itself in a separate main function. However when I put this in with my other code I get some errors that I do not know how to handle and makes my program unstable.</div>
<div><br></div><div><br></div><div><div>pdudzins@rainman:~/cs631/hw5$ ./a.out -e < test.txt > out.txt</div><div>tcsetattr: Inappropriate ioctl for device</div></div><div><br></div><div>I am not sure how to appropriately handle the terminal using tcsetattr. Has anyone run into this problem?</div>
</div>