cache.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __PERF_CACHE_H
  2. #define __PERF_CACHE_H
  3. #include "util.h"
  4. #include "strbuf.h"
  5. #include "../perf.h"
  6. #define CMD_EXEC_PATH "--exec-path"
  7. #define CMD_PERF_DIR "--perf-dir="
  8. #define CMD_WORK_TREE "--work-tree="
  9. #define CMD_DEBUGFS_DIR "--debugfs-dir="
  10. #define PERF_DIR_ENVIRONMENT "PERF_DIR"
  11. #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
  12. #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
  13. #define DB_ENVIRONMENT "PERF_OBJECT_DIRECTORY"
  14. #define INDEX_ENVIRONMENT "PERF_INDEX_FILE"
  15. #define GRAFT_ENVIRONMENT "PERF_GRAFT_FILE"
  16. #define TEMPLATE_DIR_ENVIRONMENT "PERF_TEMPLATE_DIR"
  17. #define CONFIG_ENVIRONMENT "PERF_CONFIG"
  18. #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
  19. #define CEILING_DIRECTORIES_ENVIRONMENT "PERF_CEILING_DIRECTORIES"
  20. #define PERFATTRIBUTES_FILE ".perfattributes"
  21. #define INFOATTRIBUTES_FILE "info/attributes"
  22. #define ATTRIBUTE_MACRO_PREFIX "[attr]"
  23. #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
  24. typedef int (*config_fn_t)(const char *, const char *, void *);
  25. extern int perf_default_config(const char *, const char *, void *);
  26. extern int perf_config_from_file(config_fn_t fn, const char *, void *);
  27. extern int perf_config(config_fn_t fn, void *);
  28. extern int perf_parse_ulong(const char *, unsigned long *);
  29. extern int perf_config_int(const char *, const char *);
  30. extern unsigned long perf_config_ulong(const char *, const char *);
  31. extern int perf_config_bool_or_int(const char *, const char *, int *);
  32. extern int perf_config_bool(const char *, const char *);
  33. extern int perf_config_string(const char **, const char *, const char *);
  34. extern int perf_config_set(const char *, const char *);
  35. extern int perf_config_set_multivar(const char *, const char *, const char *, int);
  36. extern int perf_config_rename_section(const char *, const char *);
  37. extern const char *perf_etc_perfconfig(void);
  38. extern int check_repository_format_version(const char *var, const char *value, void *cb);
  39. extern int perf_config_system(void);
  40. extern int perf_config_global(void);
  41. extern int config_error_nonbool(const char *);
  42. extern const char *config_exclusive_filename;
  43. #define MAX_PERFNAME (1000)
  44. extern char perf_default_email[MAX_PERFNAME];
  45. extern char perf_default_name[MAX_PERFNAME];
  46. extern int user_ident_explicitly_given;
  47. extern const char *perf_log_output_encoding;
  48. extern const char *perf_mailmap_file;
  49. /* IO helper functions */
  50. extern void maybe_flush_or_die(FILE *, const char *);
  51. extern int copy_fd(int ifd, int ofd);
  52. extern int copy_file(const char *dst, const char *src, int mode);
  53. extern ssize_t write_in_full(int fd, const void *buf, size_t count);
  54. extern void write_or_die(int fd, const void *buf, size_t count);
  55. extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
  56. extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
  57. extern void fsync_or_die(int fd, const char *);
  58. /* pager.c */
  59. extern void setup_pager(void);
  60. extern const char *pager_program;
  61. extern int pager_in_use(void);
  62. extern int pager_use_color;
  63. extern const char *editor_program;
  64. extern const char *excludes_file;
  65. char *alias_lookup(const char *alias);
  66. int split_cmdline(char *cmdline, const char ***argv);
  67. #define alloc_nr(x) (((x)+16)*3/2)
  68. /*
  69. * Realloc the buffer pointed at by variable 'x' so that it can hold
  70. * at least 'nr' entries; the number of entries currently allocated
  71. * is 'alloc', using the standard growing factor alloc_nr() macro.
  72. *
  73. * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
  74. */
  75. #define ALLOC_GROW(x, nr, alloc) \
  76. do { \
  77. if ((nr) > alloc) { \
  78. if (alloc_nr(alloc) < (nr)) \
  79. alloc = (nr); \
  80. else \
  81. alloc = alloc_nr(alloc); \
  82. x = xrealloc((x), alloc * sizeof(*(x))); \
  83. } \
  84. } while(0)
  85. static inline int is_absolute_path(const char *path)
  86. {
  87. return path[0] == '/';
  88. }
  89. const char *make_absolute_path(const char *path);
  90. const char *make_nonrelative_path(const char *path);
  91. const char *make_relative_path(const char *abs, const char *base);
  92. int normalize_path_copy(char *dst, const char *src);
  93. int longest_ancestor_length(const char *path, const char *prefix_list);
  94. char *strip_path_suffix(const char *path, const char *suffix);
  95. extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  96. extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  97. /* perf_mkstemp() - create tmp file honoring TMPDIR variable */
  98. extern int perf_mkstemp(char *path, size_t len, const char *template);
  99. extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
  100. __attribute__((format (printf, 3, 4)));
  101. extern char *perf_snpath(char *buf, size_t n, const char *fmt, ...)
  102. __attribute__((format (printf, 3, 4)));
  103. extern char *perf_pathdup(const char *fmt, ...)
  104. __attribute__((format (printf, 1, 2)));
  105. extern size_t strlcpy(char *dest, const char *src, size_t size);
  106. #endif /* __PERF_CACHE_H */