A Simple X Image Viewer
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.

util.h 1.9 KiB

13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright 2011 Bert Muennich
  2. *
  3. * This file is part of sxiv.
  4. *
  5. * sxiv is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published
  7. * by the Free Software Foundation; either version 2 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * sxiv is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
  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. #define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
  34. #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
  35. ((t1)->tv_usec - (t2)->tv_usec) / 1000)
  36. #define TV_SET_MSEC(tv,t) { \
  37. (tv)->tv_sec = (t) / 1000; \
  38. (tv)->tv_usec = (t) % 1000 * 1000; \
  39. }
  40. #define TV_ADD_MSEC(tv,t) { \
  41. (tv)->tv_sec += (t) / 1000; \
  42. (tv)->tv_usec += (t) % 1000 * 1000; \
  43. }
  44. typedef struct {
  45. DIR *dir;
  46. char *name;
  47. int d;
  48. char **stack;
  49. int stcap;
  50. int stlen;
  51. } r_dir_t;
  52. void* s_malloc(size_t);
  53. void* s_realloc(void*, size_t);
  54. char* s_strdup(char*);
  55. void warn(const char*, ...);
  56. void die(const char*, ...);
  57. ssize_t get_line(char**, size_t*, FILE*);
  58. void size_readable(float*, const char**);
  59. char* absolute_path(const char*);
  60. int r_opendir(r_dir_t*, const char*);
  61. int r_closedir(r_dir_t*);
  62. char* r_readdir(r_dir_t*);
  63. int r_mkdir(const char *);
  64. #endif /* UTIL_H */