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.

40 lignes
988B

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "util.h"
  4. void util_byte2hex(const uint8_t* bytes, size_t bytes_len,
  5. bool uppercase, char* out)
  6. {
  7. const char* hex = (uppercase) ? "0123456789ABCDEF" : "0123456789abcdef";
  8. for (size_t i = 0; i < bytes_len; i++) {
  9. *out++ = hex[bytes[i] >> 4];
  10. *out++ = hex[bytes[i] & 0xF];
  11. }
  12. *out = '\0';
  13. }
  14. const char *util_get_home()
  15. {
  16. const char *home_env = getenv("HOME");
  17. return home_env; /* TODO this can be null, use other methods as fallback */
  18. }
  19. char *util_basename(const char *fullpath)
  20. {
  21. char *name_part = strrchr(fullpath, '/');
  22. if (name_part)
  23. name_part++;
  24. else
  25. name_part = (char*)fullpath;
  26. return name_part;
  27. }
  28. uint64_t util_timespec_diff(const struct timespec *past,
  29. const struct timespec *future)
  30. {
  31. int64_t sdiff = future->tv_sec - past->tv_sec;
  32. int64_t nsdiff = future->tv_nsec - past->tv_nsec;
  33. return sdiff * 1000 + (nsdiff / 1000000);
  34. }