woody-woodpacker/srcs/utils.c

37 lines
758 B
C

#include "../includes/woody.h"
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size)
{
if (file_size > offset_to_data && file_size >= (offset_to_data + supposed_data_size))
return (file + offset_to_data);
return NULL;
}
int get_symbols_count(int sh_size, int sh_entsize)
{
if (sh_size <= 0 || sh_entsize <= 0)
return 0;
return (sh_size / sh_entsize);
}
char *get_string(char *str, char *end_file)
{
char *search_end = str;
while (search_end < end_file)
{
if (*search_end == 0)
return str;
++search_end;
}
return NULL;
}
int ft_put_error(char *str)
{
ft_putstr_fd("Error: ", STDERR_FILENO);
ft_putstr_fd(str, 2);
ft_putstr_fd("\n", STDERR_FILENO);
return EXIT_FAILURE;
}