A Simple X Image Viewer
 
 
 
 
 
 

81 line
2.0 KiB

  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/types.h>
  24. #ifndef MIN
  25. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  26. #endif
  27. #ifndef MAX
  28. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  29. #endif
  30. #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
  31. #define STREQ(a,b) (!strcmp((a), (b)))
  32. #define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \
  33. ((t1)->tv_usec - (t2)->tv_usec) / 1000)
  34. #define MSEC_TO_TIMEVAL(t,tv) { \
  35. (tv)->tv_sec = (t) / 1000; \
  36. (tv)->tv_usec = (t) % 1000 * 1000; \
  37. }
  38. #define MSEC_ADD_TO_TIMEVAL(t,tv) { \
  39. (tv)->tv_sec += (t) / 1000; \
  40. (tv)->tv_usec += (t) % 1000 * 1000; \
  41. }
  42. typedef struct {
  43. DIR *dir;
  44. char *name;
  45. int d;
  46. char **stack;
  47. int stcap;
  48. int stlen;
  49. } r_dir_t;
  50. void* s_malloc(size_t);
  51. void* s_realloc(void*, size_t);
  52. char* s_strdup(char*);
  53. void warn(const char*, ...);
  54. void die(const char*, ...);
  55. ssize_t get_line(char**, size_t*, FILE*);
  56. void size_readable(float*, const char**);
  57. void time_readable(float*, const char**);
  58. char* absolute_path(const char*);
  59. int r_opendir(r_dir_t*, const char*);
  60. int r_closedir(r_dir_t*);
  61. char* r_readdir(r_dir_t*);
  62. int r_mkdir(const char *);
  63. #endif /* UTIL_H */