common.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #define _GNU_SOURCE
  4. #include <dirent.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <inttypes.h>
  8. #include <limits.h>
  9. #include <stdarg.h>
  10. #include <stdbool.h>
  11. #include <stdint.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <stdnoreturn.h>
  15. #include <string.h>
  16. #include <time.h>
  17. #include <unistd.h>
  18. #include <sys/mman.h>
  19. #include <sys/stat.h>
  20. #include <sys/types.h>
  21. noreturn void fatal_error(const char* fmt, ...);
  22. void setup();
  23. int open_input_fd(const char* path);
  24. void read_fd(const char* path, int fd, void* buffer, size_t size);
  25. void seek_fd(const char* path, int fd, off_t offset, int mode);
  26. off_t tell_fd(const char* path, int fd);
  27. int open_output_fd(const char* path, bool rdwr);
  28. void write_fd(const char* path, int fd, const void* buffer, size_t size);
  29. void close_fd(const char* path, int fd);
  30. void* mmap_fd(const char* path, int fd, int protection, size_t offset, size_t size);
  31. void munmap_fd(const char* path, void* address, size_t size);
  32. FILE* open_input_stdio(const char* path);
  33. void read_stdio(const char* path, FILE* f, void* buffer, size_t size);
  34. void seek_stdio(const char* path, FILE* f, off_t offset, int mode);
  35. off_t tell_stdio(const char* path, FILE* f);
  36. void close_stdio(const char* path, FILE* f);
  37. FILE* open_output_stdio(const char* path, bool rdwr);
  38. void write_stdio(const char* path, FILE* f, const void* buffer, size_t size);
  39. void* alloc_buffer(size_t size);
  40. void fill_random(void* buffer, size_t size);
  41. void copy_data(int fi, int fo, const char* input_path, const char* output_path, size_t size);
  42. #endif