Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 1 | #ifndef GIT_COMPAT_UTIL_H |
| 2 | #define GIT_COMPAT_UTIL_H |
| 3 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 4 | #define _ALL_SOURCE 1 |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 5 | #define _BSD_SOURCE 1 |
Chanho Park | 512fe36 | 2014-09-12 11:10:17 +0900 | [diff] [blame] | 6 | /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ |
| 7 | #define _DEFAULT_SOURCE 1 |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 8 | #define HAS_BOOL |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 9 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 10 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 11 | #include <stdbool.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 12 | #include <stddef.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdarg.h> |
Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 15 | #include <linux/types.h> |
Frederic Weisbecker | 1fe2c10 | 2009-08-12 10:19:53 +0200 | [diff] [blame] | 16 | |
Stephane Eranian | 45de34b | 2010-06-01 21:25:01 +0200 | [diff] [blame] | 17 | extern char buildid_dir[]; |
Arnaldo Carvalho de Melo | 2890284 | 2009-11-23 17:51:08 -0200 | [diff] [blame] | 18 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 19 | #ifdef __GNUC__ |
| 20 | #define NORETURN __attribute__((__noreturn__)) |
| 21 | #else |
| 22 | #define NORETURN |
| 23 | #ifndef __attribute__ |
| 24 | #define __attribute__(x) |
| 25 | #endif |
| 26 | #endif |
| 27 | |
Namhyung Kim | fc67297 | 2013-09-13 15:27:43 +0900 | [diff] [blame] | 28 | #define PERF_GTK_DSO "libperf-gtk.so" |
| 29 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 30 | /* General helper functions */ |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 31 | void usage(const char *err) NORETURN; |
| 32 | void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); |
| 33 | int error(const char *err, ...) __attribute__((format (printf, 1, 2))); |
| 34 | void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 35 | |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 36 | void set_warning_routine(void (*routine)(const char *err, va_list params)); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 37 | |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 38 | int prefixcmp(const char *str, const char *prefix); |
| 39 | void set_buildid_dir(const char *dir); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 40 | |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 41 | static inline void *zalloc(size_t size) |
| 42 | { |
| 43 | return calloc(1, size); |
| 44 | } |
| 45 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 46 | #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) |
| 47 | |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 48 | struct dirent; |
Arnaldo Carvalho de Melo | 8ec20b1 | 2017-04-18 10:57:25 -0300 | [diff] [blame] | 49 | struct strlist; |
| 50 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 51 | int mkdir_p(char *path, mode_t mode); |
Joe Stringer | 9a9c733 | 2017-01-26 13:19:59 -0800 | [diff] [blame] | 52 | int rm_rf(const char *path); |
Masami Hiramatsu | e1ce726 | 2016-04-26 18:02:42 +0900 | [diff] [blame] | 53 | struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *)); |
| 54 | bool lsdir_no_dot_filter(const char *name, struct dirent *d); |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 55 | int copyfile(const char *from, const char *to); |
Adrian Hunter | 9a17d72 | 2013-10-14 13:43:41 +0300 | [diff] [blame] | 56 | int copyfile_mode(const char *from, const char *to, mode_t mode); |
Namhyung Kim | 9c9f5a2 | 2015-05-18 09:30:18 +0900 | [diff] [blame] | 57 | int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 58 | |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 59 | ssize_t readn(int fd, void *buf, size_t n); |
Jiri Olsa | bc3a502 | 2013-11-28 11:30:16 +0100 | [diff] [blame] | 60 | ssize_t writen(int fd, void *buf, size_t n); |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 61 | |
Joerg Roedel | 1aed267 | 2012-01-04 17:54:20 +0100 | [diff] [blame] | 62 | struct perf_event_attr; |
| 63 | |
| 64 | void event_attr_init(struct perf_event_attr *attr); |
| 65 | |
Arnaldo Carvalho de Melo | 61e04b3 | 2012-04-19 13:15:24 -0300 | [diff] [blame] | 66 | size_t hex_width(u64 v); |
Jiri Olsa | b2aff5f | 2012-10-27 23:18:30 +0200 | [diff] [blame] | 67 | int hex2u64(const char *ptr, u64 *val); |
Arnaldo Carvalho de Melo | 61e04b3 | 2012-04-19 13:15:24 -0300 | [diff] [blame] | 68 | |
Arnaldo Carvalho de Melo | 0c1fe6b | 2012-10-06 14:57:10 -0300 | [diff] [blame] | 69 | extern unsigned int page_size; |
Don Zickus | 2b1b710 | 2014-05-30 16:10:05 -0400 | [diff] [blame] | 70 | extern int cacheline_size; |
Arnaldo Carvalho de Melo | a29d5c9 | 2016-05-16 21:16:54 -0300 | [diff] [blame] | 71 | extern int sysctl_perf_event_max_stack; |
| 72 | extern int sysctl_perf_event_max_contexts_per_stack; |
Arnaldo Carvalho de Melo | 0c1fe6b | 2012-10-06 14:57:10 -0300 | [diff] [blame] | 73 | |
Jiri Olsa | 27050f5 | 2013-09-01 12:36:13 +0200 | [diff] [blame] | 74 | struct parse_tag { |
| 75 | char tag; |
| 76 | int mult; |
| 77 | }; |
| 78 | |
| 79 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags); |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 80 | |
Adrian Hunter | 1a47245 | 2013-12-11 14:36:23 +0200 | [diff] [blame] | 81 | int perf_event_paranoid(void); |
Dongsheng Yang | e1a2b17 | 2013-12-06 17:25:51 -0500 | [diff] [blame] | 82 | |
Adrian Hunter | 71db07b | 2013-12-11 14:36:32 +0200 | [diff] [blame] | 83 | void mem_bswap_64(void *src, int byte_size); |
| 84 | void mem_bswap_32(void *src, int byte_size); |
| 85 | |
Jiri Olsa | 63914ac | 2014-08-01 17:46:54 +0200 | [diff] [blame] | 86 | bool find_process(const char *name); |
Namhyung Kim | e92ce12 | 2014-10-31 16:51:38 +0900 | [diff] [blame] | 87 | |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 88 | int fetch_kernel_version(unsigned int *puint, |
| 89 | char *str, size_t str_sz); |
Wang Nan | d3e0ce3 | 2015-11-06 13:58:09 +0000 | [diff] [blame] | 90 | #define KVER_VERSION(x) (((x) >> 16) & 0xff) |
| 91 | #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff) |
| 92 | #define KVER_SUBLEVEL(x) ((x) & 0xff) |
| 93 | #define KVER_FMT "%d.%d.%d" |
| 94 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 95 | |
Namhyung Kim | 14cbfbe | 2016-01-07 20:41:53 +0900 | [diff] [blame] | 96 | const char *perf_tip(const char *dirpath); |
| 97 | |
Arnaldo Carvalho de Melo | 120010c | 2017-03-02 12:55:49 -0300 | [diff] [blame] | 98 | #ifndef HAVE_SCHED_GETCPU_SUPPORT |
| 99 | int sched_getcpu(void); |
Arnaldo Carvalho de Melo | c7007e9 | 2016-07-12 10:29:31 -0300 | [diff] [blame] | 100 | #endif |
| 101 | |
Borislav Petkov | 1355915 | 2013-02-20 16:32:31 +0100 | [diff] [blame] | 102 | #endif /* GIT_COMPAT_UTIL_H */ |