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
13 #include <sys/statfs.h>
21 #include <sys/param.h>
22 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <sys/ioctl.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
34 extern char buildid_dir[];
37 #define NORETURN __attribute__((__noreturn__))
41 #define __attribute__(x)
45 #define PERF_GTK_DSO "libperf-gtk.so"
47 /* General helper functions */
48 void usage(const char *err) NORETURN;
49 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
50 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
51 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
53 void set_warning_routine(void (*routine)(const char *err, va_list params));
55 int prefixcmp(const char *str, const char *prefix);
56 void set_buildid_dir(const char *dir);
58 static inline void *zalloc(size_t size)
60 return calloc(1, size);
63 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
68 int mkdir_p(char *path, mode_t mode);
69 int rm_rf(const char *path);
70 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
71 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
72 int copyfile(const char *from, const char *to);
73 int copyfile_mode(const char *from, const char *to, mode_t mode);
74 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
76 ssize_t readn(int fd, void *buf, size_t n);
77 ssize_t writen(int fd, void *buf, size_t n);
79 struct perf_event_attr;
81 void event_attr_init(struct perf_event_attr *attr);
83 size_t hex_width(u64 v);
84 int hex2u64(const char *ptr, u64 *val);
86 void dump_stack(void);
87 void sighandler_dump_stack(int sig);
89 extern unsigned int page_size;
90 extern int cacheline_size;
91 extern int sysctl_perf_event_max_stack;
92 extern int sysctl_perf_event_max_contexts_per_stack;
99 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
101 int perf_event_paranoid(void);
103 void mem_bswap_64(void *src, int byte_size);
104 void mem_bswap_32(void *src, int byte_size);
106 const char *get_filename_for_perf_kvm(void);
107 bool find_process(const char *name);
109 #ifdef HAVE_ZLIB_SUPPORT
110 int gzip_decompress_to_file(const char *input, int output_fd);
113 #ifdef HAVE_LZMA_SUPPORT
114 int lzma_decompress_to_file(const char *input, int output_fd);
117 int get_stack_size(const char *str, unsigned long *_size);
119 int fetch_kernel_version(unsigned int *puint,
120 char *str, size_t str_sz);
121 #define KVER_VERSION(x) (((x) >> 16) & 0xff)
122 #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
123 #define KVER_SUBLEVEL(x) ((x) & 0xff)
124 #define KVER_FMT "%d.%d.%d"
125 #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
127 const char *perf_tip(const char *dirpath);
128 int fetch_current_timestamp(char *buf, size_t sz);
130 #ifndef HAVE_SCHED_GETCPU_SUPPORT
131 int sched_getcpu(void);
134 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
136 #endif /* GIT_COMPAT_UTIL_H */