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.

54 lines
1.2KB

  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. /* And convert it back */
  21. void util_hex2byte(const char *str, uint8_t* out_bytes);
  22. /*
  23. * Return the user's home directory
  24. */
  25. const char *util_get_home();
  26. /*
  27. * Return the filename part of the path
  28. * This will return a pointer in fullpath
  29. * !! ONLY WORKS FOR FILES !!
  30. */
  31. char *util_basename(const char *fullpath);
  32. /*
  33. * Calculate the difference between 2 timespec structs in miliseconds
  34. *
  35. * future cannot be more in the past than past
  36. * if that makes any sense
  37. */
  38. uint64_t util_timespec_diff(const struct timespec *past,
  39. const struct timespec *future);
  40. /*
  41. * Convert a date and optionally time string into unix time
  42. * Returns 0 on error
  43. */
  44. uint64_t util_iso2unix(const char *isotime);
  45. #endif /* _UTIL_H */