#include "utils.h" #include #include #include #include #include void *malloc_s(unsigned long amount) { void *memory = malloc(amount); if (memory == NULL) { printf("Error: Memory allocation failed"); exit(EXIT_FAILURE); } return memory; } unsigned int str_to_uint(char *str, char **err) { if (*str == '-') { *err = "Less than 0"; return 0; } char *str_waste; unsigned long num = strtoul(str, &str_waste, 10); if (strlen(str_waste) != 0) { *err = "Not a number"; return 0; } if (num > (unsigned long)UINT_MAX) { *err = "Too large"; return 0; } return (unsigned int)num; }