cache.h 4.6 KB

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