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 static inline void *zalloc(size_t size)
35 return calloc(1, size);
38 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
43 int mkdir_p(char *path, mode_t mode);
44 int rm_rf(const char *path);
45 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
46 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
47 int copyfile(const char *from, const char *to);
48 int copyfile_mode(const char *from, const char *to, mode_t mode);
49 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
51 ssize_t readn(int fd, void *buf, size_t n);
52 ssize_t writen(int fd, void *buf, size_t n);
54 size_t hex_width(u64 v);
55 int hex2u64(const char *ptr, u64 *val);
57 extern unsigned int page_size;
58 extern int cacheline_size;
60 bool find_process(const char *name);
62 int fetch_kernel_version(unsigned int *puint,
63 char *str, size_t str_sz);
64 #define KVER_VERSION(x) (((x) >> 16) & 0xff)
65 #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
66 #define KVER_SUBLEVEL(x) ((x) & 0xff)
67 #define KVER_FMT "%d.%d.%d"
68 #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
70 const char *perf_tip(const char *dirpath);
72 #ifndef HAVE_SCHED_GETCPU_SUPPORT
73 int sched_getcpu(void);
76 #endif /* GIT_COMPAT_UTIL_H */