cache.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. char *alias_lookup(const char *alias);
  41. int split_cmdline(char *cmdline, const char ***argv);
  42. #define alloc_nr(x) (((x)+16)*3/2)
  43. /*
  44. * Realloc the buffer pointed at by variable 'x' so that it can hold
  45. * at least 'nr' entries; the number of entries currently allocated
  46. * is 'alloc', using the standard growing factor alloc_nr() macro.
  47. *
  48. * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
  49. */
  50. #define ALLOC_GROW(x, nr, alloc) \
  51. do { \
  52. if ((nr) > alloc) { \
  53. if (alloc_nr(alloc) < (nr)) \
  54. alloc = (nr); \
  55. else \
  56. alloc = alloc_nr(alloc); \
  57. x = xrealloc((x), alloc * sizeof(*(x))); \
  58. } \
  59. } while(0)
  60. static inline int is_absolute_path(const char *path)
  61. {
  62. return path[0] == '/';
  63. }
  64. const char *make_nonrelative_path(const char *path);
  65. char *strip_path_suffix(const char *path, const char *suffix);
  66. extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  67. extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  68. extern char *perf_pathdup(const char *fmt, ...)
  69. __attribute__((format (printf, 1, 2)));
  70. #ifdef NO_STRLCPY
  71. extern size_t strlcpy(char *dest, const char *src, size_t size);
  72. #endif
  73. #endif /* __PERF_CACHE_H */