#include "../includes/woody.h" int get_elf_file(t_efl_content *file_content) { int fd; off_t off; fd = open(file_content->file_path, O_RDONLY); if (fd < 0) { ft_printf("Error: Failed to open \'%s\'\n", file_content->file_path); return EXIT_FAILURE; } off = lseek(fd, 0, SEEK_END); if (off == -1) { close(fd); ft_printf("Error: Failed to read file offset \'%s\'\n", file_content->file_path); return EXIT_FAILURE; } file_content->file_size = off; file_content->file = mmap(NULL, file_content->file_size, PROT_READ, MAP_PRIVATE, fd, 0); if (file_content->file == MAP_FAILED) { close(fd); ft_printf("Error: Failed to map file \'%s\'\n", file_content->file_path); return EXIT_FAILURE; } close(fd); return EXIT_SUCCESS; } int main(int ac, char **av) { t_efl_content file_content; if (ac != 2) { return ft_put_error("Woody_woodpacker take 1 argument\n"); } file_content.file_path = av[1]; int ret = get_elf_file(&file_content); if (ret == EXIT_FAILURE) return ret; return woody(&file_content); }