A tool for adding anime to your anidb list.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

68 lignes
1.6KB

  1. #ifndef _UTIL_H
  2. #define _UTIL_H
  3. #include <sys/stat.h>
  4. #include <time.h>
  5. #include <stdint.h>
  6. #include <stddef.h>
  7. #include <stdbool.h>
  8. #include "error.h"
  9. #define MS_TO_TIMESPEC(ts, ms) { \
  10. ts->tv_sec = ms / 1000; \
  11. ts->tv_nsec = (ms % 1000) * 1000000; \
  12. }
  13. #define MS_TO_TIMESPEC_L(ts, ms) { \
  14. ts.tv_sec = ms / 1000; \
  15. ts.tv_nsec = (ms % 1000) * 1000000; \
  16. }
  17. /*
  18. * Convert bytes to a hex string
  19. * out needs to be at least (bytes_len * 2 + 1) bytes
  20. */
  21. void util_byte2hex(const uint8_t* bytes, size_t bytes_len,
  22. bool uppercase, char* out);
  23. /* And convert it back */
  24. void util_hex2byte(const char *str, uint8_t* out_bytes);
  25. /*
  26. * Return the user's home directory
  27. */
  28. const char *util_get_home();
  29. /*
  30. * Return the filename part of the path
  31. * This will return a pointer in fullpath
  32. * !! ONLY WORKS FOR FILES !!
  33. */
  34. char *util_basename(const char *fullpath);
  35. /*
  36. * Calculate the difference between 2 timespec structs in miliseconds
  37. *
  38. * future cannot be more in the past than past
  39. * if that makes any sense
  40. */
  41. uint64_t util_timespec_diff(const struct timespec *past,
  42. const struct timespec *future);
  43. /*
  44. * Convert a date and optionally time string into unix time
  45. * Returns 0 on error
  46. */
  47. uint64_t util_iso2unix(const char *isotime);
  48. /*
  49. * Iterate over a given path and call the 'cb' function for each file
  50. * If 'cb' returns anything other than NOERR, the iteration will stop and
  51. * that error will be returned.
  52. * !! THIS FUNCTION IS NOT THREAD SAFE !!
  53. */
  54. typedef enum error (*util_itercb)(const char *path, const struct stat *fstat, void *data);
  55. enum error util_iterpath(const char *path, util_itercb cb, void *data);
  56. #endif /* _UTIL_H */