cache.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef __PERF_CACHE_H
  2. #define __PERF_CACHE_H
  3. #include <stdbool.h>
  4. #include "util.h"
  5. #include "strbuf.h"
  6. #include "../perf.h"
  7. #define CMD_EXEC_PATH "--exec-path"
  8. #define CMD_PERF_DIR "--perf-dir="
  9. #define CMD_WORK_TREE "--work-tree="
  10. #define CMD_DEBUGFS_DIR "--debugfs-dir="
  11. #define PERF_DIR_ENVIRONMENT "PERF_DIR"
  12. #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
  13. #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
  14. #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
  15. #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
  16. typedef int (*config_fn_t)(const char *, const char *, void *);
  17. extern int perf_default_config(const char *, const char *, void *);
  18. extern int perf_config(config_fn_t fn, void *);
  19. extern int perf_config_int(const char *, const char *);
  20. extern int perf_config_bool(const char *, const char *);
  21. extern int config_error_nonbool(const char *);
  22. extern const char *perf_config_dirname(const char *, const char *);
  23. /* pager.c */
  24. extern void setup_pager(void);
  25. extern const char *pager_program;
  26. extern int pager_in_use(void);
  27. extern int pager_use_color;
  28. extern int use_browser;
  29. #if defined(NEWT_SUPPORT) || defined(GTK2_SUPPORT)
  30. void setup_browser(bool fallback_to_pager);
  31. void exit_browser(bool wait_for_ok);
  32. #ifdef NEWT_SUPPORT
  33. int ui__init(void);
  34. void ui__exit(bool wait_for_ok);
  35. #else
  36. static inline int ui__init(void)
  37. {
  38. return -1;
  39. }
  40. static inline void ui__exit(bool wait_for_ok __maybe_unused) {}
  41. #endif
  42. #ifdef GTK2_SUPPORT
  43. int perf_gtk__init(void);
  44. void perf_gtk__exit(bool wait_for_ok);
  45. #else
  46. static inline int perf_gtk__init(void)
  47. {
  48. return -1;
  49. }
  50. static inline void perf_gtk__exit(bool wait_for_ok __maybe_unused) {}
  51. #endif
  52. #else /* NEWT_SUPPORT || GTK2_SUPPORT */
  53. static inline void setup_browser(bool fallback_to_pager)
  54. {
  55. if (fallback_to_pager)
  56. setup_pager();
  57. }
  58. static inline void exit_browser(bool wait_for_ok __maybe_unused) {}
  59. #endif /* NEWT_SUPPORT || GTK2_SUPPORT */
  60. char *alias_lookup(const char *alias);
  61. int split_cmdline(char *cmdline, const char ***argv);
  62. #define alloc_nr(x) (((x)+16)*3/2)
  63. /*
  64. * Realloc the buffer pointed at by variable 'x' so that it can hold
  65. * at least 'nr' entries; the number of entries currently allocated
  66. * is 'alloc', using the standard growing factor alloc_nr() macro.
  67. *
  68. * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
  69. */
  70. #define ALLOC_GROW(x, nr, alloc) \
  71. do { \
  72. if ((nr) > alloc) { \
  73. if (alloc_nr(alloc) < (nr)) \
  74. alloc = (nr); \
  75. else \
  76. alloc = alloc_nr(alloc); \
  77. x = xrealloc((x), alloc * sizeof(*(x))); \
  78. } \
  79. } while(0)
  80. static inline int is_absolute_path(const char *path)
  81. {
  82. return path[0] == '/';
  83. }
  84. const char *make_nonrelative_path(const char *path);
  85. char *strip_path_suffix(const char *path, const char *suffix);
  86. extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  87. extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  88. extern char *perf_pathdup(const char *fmt, ...)
  89. __attribute__((format (printf, 1, 2)));
  90. #ifndef HAVE_STRLCPY
  91. extern size_t strlcpy(char *dest, const char *src, size_t size);
  92. #endif
  93. #endif /* __PERF_CACHE_H */