/* See LICENSE file for copyright and license details. */ #include #ifndef SINGLE_THREADED # include #else # define pthread_barrier_t PhonyBarrier #endif #include struct thread_data; #ifdef SINGLE_THREADED typedef struct { struct thread_data *threads; size_t nthreads; } pthread_barrier_t; #endif enum format { BINARY = 0, LOWERCASE_HEX = 1, UPPERCASE_HEX = 2, #define FORMAT_MASK 0x00FF WITH_ALGOSTR = 0x0100, WITH_FILENAME = 0x0200, WITH_NUL = 0x0400, WITH_LF = 0x0800 }; struct buffer { char *buf; size_t length; size_t size; }; struct algorithm { const char *algostr; char *result; size_t result_size; size_t result_length; size_t offset; struct libhashsum_hasher hasher; }; struct global_data { void (*action)(struct algorithm *, struct global_data *); enum format format; const char *file; struct buffer *buffer; struct algorithm *algorithms; size_t nalgorithms; }; struct barrier_group { pthread_barrier_t barrier; struct thread_data *threads; size_t nthreads; }; struct thread_data { struct barrier_group *group; struct global_data *global; size_t index; #ifndef SINGLE_THREADED pthread_t thread; #endif }; int patheq(const char *have, const char *want, const char **end_out); int openfile(const char *path, int *is_new_fd_out, const char **fname_out); char *hex(char *out, const unsigned char *in, size_t n, const char *xdigits); void writeall(int fd, const void *data, size_t n, const char *fname); void barrierwait(pthread_barrier_t *barrier); void barriersend(struct barrier_group *group, struct global_data *global, void (*action)(struct algorithm *, struct global_data *)); void format_result(struct algorithm *algorithm, const char *file, enum format format); int feedbuffer(int fd, struct buffer *buffer, const char *fname); void createbarriergroup(struct barrier_group *group_out, size_t count, struct global_data *global); void killbarriergroup(struct barrier_group *group, struct global_data *global); size_t inithashers(struct algorithm *algorithms, size_t nalgorithms); void destroyhashers(struct algorithm *algorithms, size_t nalgorithms); void shiftbuffer(struct algorithm *algorithms, size_t nalgorithms, struct buffer *buffer); int calculate(const char *file, struct barrier_group *group, struct global_data *global);