Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1.  
  2. int ioctlAction(char *argument,char* infile, char* outfile){
  3.  
  4. char substring[8];
  5. memcpy( substring, &argument[0], 7);
  6. substring[7] = '\0';
  7.  
  8. //otvorenie terminálu
  9. int fp = open(infile, O_RDWR);
  10. if(fp == -1){
  11. errorHandling("I", 17);
  12. return -1;
  13. }
  14.  
  15. //parser
  16. if((strcmp(substring, "ECHO[+] ")==0) || (strcmp(substring, "ECHO[+]") == 0)){
  17. onEcho(fp);
  18.  
  19. }else if((strcmp(substring, "ECHO[-] ") == 0) || (strcmp(substring, "ECHO[-]") == 0)){
  20.  
  21. offEcho(fp);
  22.  
  23. }else if((strcmp(substring, "ECHO[x]")==0) || (strcmp(substring, "ECHO[x] ") == 0)){
  24. struct termios settings_real;
  25. struct termios settings_my;
  26.  
  27. if(tcgetattr(fp, &settings_real) == -1){
  28. errorHandling("I", 17);
  29. return -1;
  30. }
  31.  
  32. tcgetattr(fp, &settings_my);
  33. settings_my.c_lflag &= ~ECHO;
  34.  
  35. //porovnávam 2 štruktúry
  36. if((int) settings_my.c_lflag == (int) settings_real.c_lflag){
  37. //hodnota je true, echo je vypnuté, treba ho zapnúť ako spínač
  38. onEcho(fp);
  39. }else{
  40. //hodnota je false, echo je zapnuté, treba ho vypnúť
  41. offEcho(fp);
  42. }
  43. }else{
  44. errorHandling("I", 17);
  45. return -1;
  46. }
  47.  
  48. int fd2 = open(outfile, O_WRONLY);
  49. if(fd2 == -1){
  50.  
  51. errorHandling("I", 17);
  52. return -1;
  53. }else{
  54.  
  55. char array[5000];
  56. int counter = 0;
  57. char temp;
  58. while(read(fp, &temp, 1)){
  59. if(temp == '\n'){
  60. break;
  61. }
  62. array[counter++]=temp;
  63. if(counter > 4999){
  64. break;
  65. }
  66. }
  67.  
  68. if(appendAction("", outfile, 0, 1, array) != 0){
  69. errorHandling("I", 17);
  70. close(fp);
  71. close(fd2);
  72. return -1;
  73. }
  74. close(fp);
  75. close(fd2);
  76. return 0;
  77. }
  78.  
  79. errorHandling("I", 17);
  80. return -1;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement