Advertisement
Tobiahao

SO1_TERMINAL_01

Jan 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. /*
  2. Napisz program, który sprawdzi, czy z deskryptorem standardowego wejścia (STDIN_FILENO lub wartość 0) jest związany terminal. Jeśli tak, to program powinien wypisać nazwę pliku urządzenia tego terminala, oraz kilka jego bieżących ustawień.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <termios.h>
  9.  
  10. int main(void)
  11. {
  12.     if(isatty(STDIN_FILENO)){
  13.         struct termios termios_p;
  14.         tcgetattr(STDIN_FILENO, &termios_p);
  15.  
  16.         printf("Nazwa terminala: %s\n", ttyname(STDIN_FILENO));
  17.  
  18.         if(termios_p.c_lflag & ECHO)
  19.             printf("* Echo wlaczone\n");
  20.         else
  21.             printf("* Echo wylaczone\n");
  22.  
  23.         if(termios_p.c_lflag & OPOST)
  24.             printf("* Opost wlaczone\n");
  25.         else
  26.             printf("* Opost wylaczone\n");
  27.  
  28.         if(termios_p.c_cflag & CREAD)
  29.             printf("* Cread wlaczone\n");
  30.         else
  31.             printf("* Cread wylaczone\n");
  32.     }
  33.     else{
  34.         perror("isatty");
  35.         return EXIT_FAILURE;
  36.     }
  37.  
  38.     return EXIT_SUCCESS;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement