void good_pipe(t_env *env, int pipefd[2], int pipe_check) { if (pipe_check == 1) { close(pipefd[1]); if (env->fd.fd_in != 0) { close(pipefd[0]); close(env->fd.fd_in); (env->fd.fd_out != 0) ? (close(env->fd.fd_out)) : 0; my_putstr_err("Ambiguous input redirect.\n"); exit(0); } env->fd.fd_in = pipefd[0]; } if (pipe_check == 0) { if (env->fd.fd_out != 1) { close(env->fd.fd_out); (env->fd.fd_in != 0) ? (close(env->fd.fd_in)) : 0; my_putstr_err("Ambiguous output redirect.\n"); exit(0); } env->fd.fd_out = pipefd[1]; } }
int main(int ac, char **av) { t_ray *ray; if (ac < 2) { my_putstr_err("Error : No .ini file.\nAborting...\n"); return (0); } if ((ray = bunny_malloc(sizeof(t_ray))) == NULL) return (1); if ((init_my_struct(ray)) == 1) { my_putstr_err("Fatal error ! Malloc failed\n"); return (1); } ini_loader(ac, av, ray); if ((ray->pix = bunny_new_pixelarray(ray->width, ray->height)) == NULL) return (1); ray->win = bunny_start(ray->width, ray->height, false, "Raytracer 1 | uberti_l"); bunny_set_loop_main_function(main_loop); bunny_loop(ray->win, 60, ray); bunny_delete_clipable(&ray->pix->clipable); bunny_stop(ray->win); bunny_free(ray); return (0); }
void fork_handler(t_shell *shell, char **args) { pid_t p; p = fork(); if (p == 0) { if (execve(args[0], args, shell->env) == -1) { if (shell->env == NULL) { my_putstr_err(args[0]); my_putstr_err(": Command not found.\n"); exit(0); } do_execve(shell->env, args); } exit(0); } else if (p != -1) { waitpid(0, &shell->status, 0); } else my_putstr_err("FATAL ERROR : Fork failed\n"); }
int xopen(char *str, int flags) { int fd; fd = open(str, flags); if (fd == -1) { my_putstr_err("Error: file "); my_putstr_err(str); xexit(" not accessible\n"); } return (fd); }
int transfer_wt_to_cells(t_maze *maze, char **wt) { int i; int j; i = 0; while (wt[i]) i++; maze->h = i; if ((maze->cells = malloc(sizeof(char *) * i)) == NULL) return (1); i = -1; while (++i < maze->h) if ((maze->cells[i] = strdup(wt[i])) == NULL) return (1); i = -1; while (++i < maze->h) { j = -1; while (++j < maze->w) maze->cells[i][j] = (maze->cells[i][j] == '*') ? (0) : (1); } free_tab(wt, maze->h); if (maze->w > 1000 || maze->h > 1000) return (my_putstr_err(TOO_MUCH)); return (0); }
int encrypt(int ac, char **av) { int nb; int len_m_matrix; int i; int *key_matrix; int *message_matrix; if (my_strlen(av[2]) <= 4) { nb = 2; key_matrix = disp_key(ac, av, nb); } else if (my_strlen(av[2]) <= 9) { nb = 3; key_matrix = disp_key(ac, av, nb); } else { my_putstr_err("Usage: la key ne doit pas depasser les 9 caractères.\n"); return (84); } message_matrix = message_in_matrix(ac, av, nb); len_m_matrix = len_message_matrix(message_matrix); disp_encrypted_message(key_matrix, message_matrix, len_m_matrix, nb); return (0); }
int main(int ac, char **av) { t_maze *maze; if (ac != 2) return (my_putstr_err(USAGE)); if ((maze = init_maze()) == NULL) return (my_putstr_err(ERR_MALLOC)); if (open_file(maze, av[1]) == 0) return (my_putstr_err(WRONG_FORMAT)); if (solve_maze(maze) == 1) display_maze(maze); else printf("%s\n", NOTHING); free_all(maze); return (0); }
void my_putstr(char *str) { if (write(1, str, my_strlen(str)) == -1) { my_putstr_err("write failed\n"); return ; } }
int main(int ac, char **av) { if (ac != 4) { my_putstr_err("Usage: ./102cipher message key flag\n"); return (84); } if (av[3][0] == '0') encrypt(ac, av); else if (av[3][0] == '1') decrypt(ac, av); else { my_putstr_err("Usage: le flag doit être égal à 0 ou 1.\n"); return (84); } return (0); }
int *exit_prepare_tab(int *tab, int *max) { my_putstr_err("Invalid character\n"); if (tab != NULL) free(tab); if (max != NULL) free(max); return (NULL); }
int xopen(const char *path, int flag) { int fd; fd = open(path, flag); if (fd == -1) { my_putstr_err("error: open: An error has occured.\n"); exit(EXIT_FAILURE); } return (fd); }
int maze_checker(char *maze, const int ret) { int i; i = -1; maze[ret] = '\0'; while (maze[++i] != '\0') if (maze[i] != 'X' && maze[i] != '*' && maze[i] != '\n') { free(maze); return (my_putstr_err(WRONG_FORMAT)); } return (0); }
int move_to_it(t_shell *shell) { if (shell->old_dir == NULL) find_oldpwd(shell); if (shell->cd_move[0] == '-') { my_cd_go_back(shell); return (0); } if (chdir(shell->cd_move) == -1) { my_putstr_err(shell->cd_move); my_putstr_err(": No such file or directory.\n"); return (1); } free(shell->cd_move); if ((shell->cd_move = malloc(100)) == NULL) exit(84); getcwd(shell->cd_move, 100); set_oldpwd_and_pwd(shell); free(shell->cd_move); find_oldpwd(shell); return (0); }
int my_cd_go_back(t_shell *shell) { if (shell->old_dir == NULL) { my_putstr_err(": No such file or directory.\n"); return (1); } my_putstr(shell->old_dir); my_putchar('\n'); chdir(shell->old_dir); free(shell->old_dir); find_oldpwd(shell); set_oldpwd_and_pwd(shell); free(shell->cd_move); return (0); }
static int write_header(int fd_dest, header_t *header, t_parser *parser) { int magic; int prog_size; magic = COREWAR_EXEC_MAGIC; swap_bytes((char *)&magic, sizeof(magic)); header->magic = magic; prog_size = parser->current_address; swap_bytes((char *)&prog_size, sizeof(int)); header->prog_size = prog_size; if (write(fd_dest, header, sizeof(*header)) == -1) { my_putstr_err("Cannot write in the file", 2); return (1); } return (0); }
static int parse_line_instruction(t_parser *parser, char **my_tab) { if (is_defined(my_tab[0]) == 1) { if (compressor(&my_tab) == 1) { my_putstr_err("Can’t perform malloc", 2); return (1); } if (is_number_valid(my_tab, my_tab[0]) == 1) parser->current_address += get_incsize(my_tab); else return (syntax_error_and_return(parser->line_nb)); if (valid_args(my_tab) == 0) return (syntax_error_and_return(parser->line_nb)); } else return (syntax_error_and_return(parser->line_nb)); return (0); }
int assemble(int fd_src, char *name) { int fd_dest; char *new_name; header_t header; t_parser parser; if ((new_name = get_new_name(name)) == NULL) return (1); if ((fd_dest = open(new_name, O_WRONLY | O_CREAT | O_TRUNC, 00600)) == -1) { my_putstr_err("Can't create the .cor file", 2); return (1); } if (parse_file(fd_src, &parser, fd_dest, &header) == 1) return (1); free(new_name); if (close(fd_dest) == -1) return (1); if (close(fd_src) == -1) return (1); return (0); }
void exit_no_tetri() { my_putstr_err("There is no tetrimino on tetriminos/ file !\n"); exit(1); }