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.
 
 
 
 
 
 

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