void first_pipe_traitement(char *buffer, char **env, t_traite *tr, int pipefd[2]) { int tst; int directory; int error; error = pipe(pipefd); if (error == -1) exit(EXIT_FAILURE); if ((tr->pid = fork()) == -1) exit(EXIT_FAILURE); if (tr->pid == 0) { tr->buff = epure_str(buffer); tr->tab = strtab(tr->buff); tr->path = find_path(env, tr->path); directory = current_directory(tr->tab); if (directory == 2) tr->exec = test(tr->path, tr->tab[0]); close(pipefd[0]); dup2(pipefd[1], 1); execve(tr->exec, tr->tab, env); exit(0); } waitpid(tr->pid, &tst, 0); }
void second_pipe_traitement(char *buffer, char **env, t_traite *tr, int pipefd[2]) { int tst; int directory; if ((tr->pid = fork()) == -1) exit(EXIT_FAILURE); if (tr->pid == 0) { buffer = tr->tmp; buffer = cut_buff_pipe(buffer); tr->buff = epure_str(buffer); tr->tab = strtab(tr->buff); tr->path = find_path(env, tr->path); directory = current_directory(tr->tab); if (directory == 2) tr->exec = test(tr->path, tr->tab[0]); close(pipefd[1]); dup2(pipefd[0], 0); execve(tr->exec, tr->tab, env); exit(0); } close(pipefd[1]); close(pipefd[0]); wait(&tr->statut); if (WIFSIGNALED(tr->statut)) my_putstr("Segmentation fault\n"); }
void crypt_hill(char *str, int **matrice) { int i, offset = 0; if (str) { char block[BLOC]; // tableau pour stocker les chaines en int int *tab = (int*) malloc(BLOC * sizeof(int)); // tableau pour mettre les résultats int *crypt = (int*) malloc(BLOC * sizeof(int)); while (*str) { for (i = 0; i<BLOC; i++) { tab[i] = 0; crypt[i] = 0; } strncpy(block, str, BLOC); block[BLOC] = '\0'; strtab(block, tab); dprint("block = \"%s\" -> (%d,%d) -> ",block ,tab[0],tab[1]); multimat(tab, matrice, crypt); // Affichage dprint("(%d,%d) -> ",crypt[0]%mod, crypt[1]%mod); dprint("\"%c%c\"\n",alphabet[crypt[0]%mod], alphabet[crypt[1]%mod]); for (i = 0; i<BLOC; i++) str[offset+i] = alphabet[crypt[i]%mod]; offset+=BLOC; str+=BLOC; } free(tab); free(crypt); } }