A tool for adding anime to your anidb list.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1KB

  1. #ifndef _UTIL_H
  2. #define _UTIL_H
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #include <stdbool.h>
  6. #define MS_TO_TIMESPEC(ts, ms) { \
  7. ts->tv_sec = ms / 1000; \
  8. ts->tv_nsec = (ms % 1000) * 1000000; \
  9. }
  10. #define MS_TO_TIMESPEC_L(ts, ms) { \
  11. ts.tv_sec = ms / 1000; \
  12. ts.tv_nsec = (ms % 1000) * 1000000; \
  13. }
  14. /*
  15. * Convert bytes to a hex string
  16. * out needs to be at least (bytes_len * 2 + 1) bytes
  17. */
  18. void util_byte2hex(const uint8_t* bytes, size_t bytes_len,
  19. bool uppercase, char* out);
  20. /*
  21. * Return the user's home directory
  22. */
  23. const char *util_get_home();
  24. /*
  25. * Return the filename part of the path
  26. * This will return a pointer in fullpath
  27. * !! ONLY WORKS FOR FILES !!
  28. */
  29. char *util_basename(const char *fullpath);
  30. /*
  31. * Calculate the difference between 2 timespec structs in miliseconds
  32. *
  33. * future cannot be more in the past than past
  34. * if that makes any sense
  35. */
  36. uint64_t util_timespec_diff(const struct timespec *past,
  37. const struct timespec *future);
  38. /*
  39. * Convert a date and optionally time string into unix time
  40. * Returns 0 on error
  41. */
  42. uint64_t util_iso2unix(const char *isotime);
  43. #endif /* _UTIL_H */