Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ioctlAction(char *argument,char* infile, char* outfile){
- char substring[8];
- memcpy( substring, &argument[0], 7);
- substring[7] = '\0';
- //otvorenie terminálu
- int fp = open(infile, O_RDWR);
- if(fp == -1){
- errorHandling("I", 17);
- return -1;
- }
- //parser
- if((strcmp(substring, "ECHO[+] ")==0) || (strcmp(substring, "ECHO[+]") == 0)){
- onEcho(fp);
- }else if((strcmp(substring, "ECHO[-] ") == 0) || (strcmp(substring, "ECHO[-]") == 0)){
- offEcho(fp);
- }else if((strcmp(substring, "ECHO[x]")==0) || (strcmp(substring, "ECHO[x] ") == 0)){
- struct termios settings_real;
- struct termios settings_my;
- if(tcgetattr(fp, &settings_real) == -1){
- errorHandling("I", 17);
- return -1;
- }
- tcgetattr(fp, &settings_my);
- settings_my.c_lflag &= ~ECHO;
- //porovnávam 2 štruktúry
- if((int) settings_my.c_lflag == (int) settings_real.c_lflag){
- //hodnota je true, echo je vypnuté, treba ho zapnúť ako spÃnaÄ
- onEcho(fp);
- }else{
- //hodnota je false, echo je zapnuté, treba ho vypnúť
- offEcho(fp);
- }
- }else{
- errorHandling("I", 17);
- return -1;
- }
- int fd2 = open(outfile, O_WRONLY);
- if(fd2 == -1){
- errorHandling("I", 17);
- return -1;
- }else{
- char array[5000];
- int counter = 0;
- char temp;
- while(read(fp, &temp, 1)){
- if(temp == '\n'){
- break;
- }
- array[counter++]=temp;
- if(counter > 4999){
- break;
- }
- }
- if(appendAction("", outfile, 0, 1, array) != 0){
- errorHandling("I", 17);
- close(fp);
- close(fd2);
- return -1;
- }
- close(fp);
- close(fd2);
- return 0;
- }
- errorHandling("I", 17);
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement