A Simple X Image Viewer
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

13 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* sxiv: util.h
  2. * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef UTIL_H
  19. #define UTIL_H
  20. #include <stdio.h>
  21. #include <stdarg.h>
  22. #include <dirent.h>
  23. #include <sys/time.h>
  24. #include <sys/types.h>
  25. #include "types.h"
  26. #ifndef MIN
  27. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  28. #endif
  29. #ifndef MAX
  30. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  31. #endif
  32. #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
  33. typedef struct {
  34. DIR *dir;
  35. char *name;
  36. int d;
  37. char **stack;
  38. int stcap;
  39. int stlen;
  40. } r_dir_t;
  41. static inline
  42. bool streq(const char *a, const char *b) {
  43. return strcmp(a, b) == 0;
  44. }
  45. static inline
  46. long tv_diff(const struct timeval *t1, const struct timeval *t2) {
  47. return (t1->tv_sec - t2->tv_sec) * 1000 +
  48. (t1->tv_usec - t2->tv_usec) / 1000;
  49. }
  50. static inline
  51. void tv_set_msec(struct timeval *t, int msec) {
  52. t->tv_sec = msec / 1000;
  53. t->tv_usec = msec % 1000 * 1000;
  54. }
  55. static inline
  56. void tv_add_msec(struct timeval *t, int msec) {
  57. t->tv_sec += msec / 1000;
  58. t->tv_usec += msec % 1000 * 1000;
  59. }
  60. void* s_malloc(size_t);
  61. void* s_realloc(void*, size_t);
  62. char* s_strdup(char*);
  63. void warn(const char*, ...);
  64. void die(const char*, ...);
  65. ssize_t get_line(char**, size_t*, FILE*);
  66. void size_readable(float*, const char**);
  67. void time_readable(float*, const char**);
  68. char* absolute_path(const char*);
  69. int r_opendir(r_dir_t*, const char*);
  70. int r_closedir(r_dir_t*);
  71. char* r_readdir(r_dir_t*);
  72. int r_mkdir(const char *);
  73. #endif /* UTIL_H */