#include #include #include #if defined __linux__ || defined __APPLE__ #include #else #include #endif #include "advent_utility.h" struct Point new_Point(int x, int y) { struct Point p; p.x = x; p.y = y; return p; } struct Point *new_Point_p(int x, int y) { struct Point *p = malloc(sizeof(struct Point)); p->x = x; p->y = y; return p; } int same_Point(const struct Point *a, const struct Point *b) { if (a->x == b->x && a->y == b->y) { return 1; } return 0; } int same_Point_v(const void *a, const void *b) { return same_Point((const struct Point *) a, (const struct Point *) b); } char *md5_str(const char *input) { unsigned char digest[16]; #if defined __linux__ || defined __APPLE__ MD5_CTX context; MD5_Init(&context); MD5_Update(&context, input, strlen(input)); MD5_Final(digest, &context); #else struct MD5Context context; MD5Init(&context); MD5Update(&context, input, strlen(input)); MD5Final(digest, &context); #endif char *md5string = malloc(33); for (int i = 0; i < 16; ++i) { sprintf(&md5string[i * 2], "%02x", (unsigned int) digest[i]); } return md5string; } char *capture_system(const char *cmd) { char *buf = malloc(256); FILE *tmp = popen(cmd, "r"); if (tmp == NULL) { printf("failed to open FILE *tmp\n"); exit(1); } fgets(buf, 256, tmp); return buf; }