cache.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifdef NO_NEWT_SUPPORT
  30. static inline void setup_browser(bool fallback_to_pager)
  31. {
  32. if (fallback_to_pager)
  33. setup_pager();
  34. }
  35. static inline void exit_browser(bool wait_for_ok __used) {}
  36. #else
  37. void setup_browser(bool fallback_to_pager);
  38. void exit_browser(bool wait_for_ok);
  39. #endif
  40. #ifdef NO_GTK2_SUPPORT
  41. static inline void perf_gtk_setup_browser(int argc __used, const char *argv[] __used, bool fallback_to_pager)
  42. {
  43. if (fallback_to_pager)
  44. setup_pager();
  45. }
  46. static inline void perf_gtk_exit_browser(bool wait_for_ok __used) {}
  47. #else
  48. void perf_gtk_setup_browser(int argc, const char *argv[], bool fallback_to_pager);
  49. void perf_gtk_exit_browser(bool wait_for_ok);
  50. #endif
  51. char *alias_lookup(const char *alias);
  52. int split_cmdline(char *cmdline, const char ***argv);
  53. #define alloc_nr(x) (((x)+16)*3/2)
  54. /*
  55. * Realloc the buffer pointed at by variable 'x' so that it can hold
  56. * at least 'nr' entries; the number of entries currently allocated
  57. * is 'alloc', using the standard growing factor alloc_nr() macro.
  58. *
  59. * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
  60. */
  61. #define ALLOC_GROW(x, nr, alloc) \
  62. do { \
  63. if ((nr) > alloc) { \
  64. if (alloc_nr(alloc) < (nr)) \
  65. alloc = (nr); \
  66. else \
  67. alloc = alloc_nr(alloc); \
  68. x = xrealloc((x), alloc * sizeof(*(x))); \
  69. } \
  70. } while(0)
  71. static inline int is_absolute_path(const char *path)
  72. {
  73. return path[0] == '/';
  74. }
  75. const char *make_nonrelative_path(const char *path);
  76. char *strip_path_suffix(const char *path, const char *suffix);
  77. extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  78. extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  79. extern char *perf_pathdup(const char *fmt, ...)
  80. __attribute__((format (printf, 1, 2)));
  81. #ifdef NO_STRLCPY
  82. extern size_t strlcpy(char *dest, const char *src, size_t size);
  83. #endif
  84. #endif /* __PERF_CACHE_H */