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
14 #include <linux/types.h>
17 #define NORETURN __attribute__((__noreturn__))
21 #define __attribute__(x)
25 /* General helper functions */
26 void usage(const char *err) NORETURN;
27 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
28 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
29 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
31 void set_warning_routine(void (*routine)(const char *err, va_list params));
33 int prefixcmp(const char *str, const char *prefix);
35 static inline void *zalloc(size_t size)
37 return calloc(1, size);
40 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
45 int mkdir_p(char *path, mode_t mode);
46 int rm_rf(const char *path);
47 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
48 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
49 int copyfile(const char *from, const char *to);
50 int copyfile_mode(const char *from, const char *to, mode_t mode);
51 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
53 ssize_t readn(int fd, void *buf, size_t n);
54 ssize_t writen(int fd, void *buf, size_t n);
56 size_t hex_width(u64 v);
57 int hex2u64(const char *ptr, u64 *val);
59 extern unsigned int page_size;
60 extern int cacheline_size;
67 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
69 bool find_process(const char *name);
71 int fetch_kernel_version(unsigned int *puint,
72 char *str, size_t str_sz);
73 #define KVER_VERSION(x) (((x) >> 16) & 0xff)
74 #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
75 #define KVER_SUBLEVEL(x) ((x) & 0xff)
76 #define KVER_FMT "%d.%d.%d"
77 #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
79 const char *perf_tip(const char *dirpath);
81 #ifndef HAVE_SCHED_GETCPU_SUPPORT
82 int sched_getcpu(void);
85 #endif /* GIT_COMPAT_UTIL_H */