1 #ifndef GIT_COMPAT_UTIL_H
2 #define GIT_COMPAT_UTIL_H
6 /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7 #define _DEFAULT_SOURCE 1
21 #include <sys/ioctl.h>
22 #include <linux/types.h>
24 extern char buildid_dir[];
27 #define NORETURN __attribute__((__noreturn__))
31 #define __attribute__(x)
35 #define PERF_GTK_DSO "libperf-gtk.so"
37 /* General helper functions */
38 void usage(const char *err) NORETURN;
39 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
40 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
41 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
43 void set_warning_routine(void (*routine)(const char *err, va_list params));
45 int prefixcmp(const char *str, const char *prefix);
46 void set_buildid_dir(const char *dir);
48 static inline void *zalloc(size_t size)
50 return calloc(1, size);
53 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
58 int mkdir_p(char *path, mode_t mode);
59 int rm_rf(const char *path);
60 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
61 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
62 int copyfile(const char *from, const char *to);
63 int copyfile_mode(const char *from, const char *to, mode_t mode);
64 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
66 ssize_t readn(int fd, void *buf, size_t n);
67 ssize_t writen(int fd, void *buf, size_t n);
69 struct perf_event_attr;
71 void event_attr_init(struct perf_event_attr *attr);
73 size_t hex_width(u64 v);
74 int hex2u64(const char *ptr, u64 *val);
76 extern unsigned int page_size;
77 extern int cacheline_size;
78 extern int sysctl_perf_event_max_stack;
79 extern int sysctl_perf_event_max_contexts_per_stack;
86 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
88 int perf_event_paranoid(void);
90 void mem_bswap_64(void *src, int byte_size);
91 void mem_bswap_32(void *src, int byte_size);
93 bool find_process(const char *name);
95 int fetch_kernel_version(unsigned int *puint,
96 char *str, size_t str_sz);
97 #define KVER_VERSION(x) (((x) >> 16) & 0xff)
98 #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
99 #define KVER_SUBLEVEL(x) ((x) & 0xff)
100 #define KVER_FMT "%d.%d.%d"
101 #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
103 const char *perf_tip(const char *dirpath);
105 #ifndef HAVE_SCHED_GETCPU_SUPPORT
106 int sched_getcpu(void);
109 #endif /* GIT_COMPAT_UTIL_H */