#include #include #include #include #include #include "Messages.h" #define SUCCESS_COUNT (sizeof(success_messages) / sizeof(char*) - 1) #define FAILURE_COUNT (sizeof(failure_messages) / sizeof(char*) - 1) static const char ANSI_RED[] = "\x1b[31m"; static const char ANSI_RESET[] = "\x1b[0m"; static const char* get_random_message(const char* messages[], size_t count) { return messages[rand() % count]; } int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); srand((unsigned int)ts.tv_nsec); pid_t pid = fork(); if (pid < 0) { perror("fork"); return 1; } if (pid == 0) { execvp(argv[1], &argv[1]); perror(argv[1]); _exit(127); } int status; waitpid(pid, &status, 0); const char* message; if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { message = get_random_message(success_messages, SUCCESS_COUNT); } else { message = get_random_message(failure_messages, FAILURE_COUNT); } printf("%s%s <3%s\n", ANSI_RED, message, ANSI_RESET); return 0; }