A Simple X Image Viewer
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

86 wiersze
2.1 KiB

  1. /* sxiv: util.h
  2. * Copyright (c) 2012 Bert Muennich <be.muennich at googlemail.com>
  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 ABS
  27. #define ABS(a) ((a) < 0 ? -(a) : (a))
  28. #endif
  29. #ifndef MIN
  30. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  31. #endif
  32. #ifndef MAX
  33. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  34. #endif
  35. #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
  36. #define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
  37. #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
  38. ((t1)->tv_usec - (t2)->tv_usec) / 1000)
  39. #define TV_SET_MSEC(tv,t) { \
  40. (tv)->tv_sec = (t) / 1000; \
  41. (tv)->tv_usec = (t) % 1000 * 1000; \
  42. }
  43. #define TV_ADD_MSEC(tv,t) { \
  44. (tv)->tv_sec += (t) / 1000; \
  45. (tv)->tv_usec += (t) % 1000 * 1000; \
  46. }
  47. typedef struct {
  48. DIR *dir;
  49. char *name;
  50. int d;
  51. char **stack;
  52. int stcap;
  53. int stlen;
  54. } r_dir_t;
  55. void* s_malloc(size_t);
  56. void* s_realloc(void*, size_t);
  57. char* s_strdup(char*);
  58. void warn(const char*, ...);
  59. void die(const char*, ...);
  60. ssize_t get_line(char**, size_t*, FILE*);
  61. void size_readable(float*, const char**);
  62. char* absolute_path(const char*);
  63. int r_opendir(r_dir_t*, const char*);
  64. int r_closedir(r_dir_t*);
  65. char* r_readdir(r_dir_t*);
  66. int r_mkdir(const char *);
  67. #endif /* UTIL_H */