at v4.12-rc3 76 lines 2.1 kB view raw
1#ifndef GIT_COMPAT_UTIL_H 2#define GIT_COMPAT_UTIL_H 3 4#define _ALL_SOURCE 1 5#define _BSD_SOURCE 1 6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ 7#define _DEFAULT_SOURCE 1 8 9#include <fcntl.h> 10#include <stdbool.h> 11#include <stddef.h> 12#include <stdlib.h> 13#include <stdarg.h> 14#include <linux/types.h> 15 16#ifdef __GNUC__ 17#define NORETURN __attribute__((__noreturn__)) 18#else 19#define NORETURN 20#ifndef __attribute__ 21#define __attribute__(x) 22#endif 23#endif 24 25/* General helper functions */ 26void usage(const char *err) NORETURN; 27void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 28int error(const char *err, ...) __attribute__((format (printf, 1, 2))); 29void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); 30 31void set_warning_routine(void (*routine)(const char *err, va_list params)); 32 33static inline void *zalloc(size_t size) 34{ 35 return calloc(1, size); 36} 37 38#define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) 39 40struct dirent; 41struct strlist; 42 43int mkdir_p(char *path, mode_t mode); 44int rm_rf(const char *path); 45struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *)); 46bool lsdir_no_dot_filter(const char *name, struct dirent *d); 47int copyfile(const char *from, const char *to); 48int copyfile_mode(const char *from, const char *to, mode_t mode); 49int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); 50 51ssize_t readn(int fd, void *buf, size_t n); 52ssize_t writen(int fd, void *buf, size_t n); 53 54size_t hex_width(u64 v); 55int hex2u64(const char *ptr, u64 *val); 56 57extern unsigned int page_size; 58extern int cacheline_size; 59 60bool find_process(const char *name); 61 62int 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) 69 70const char *perf_tip(const char *dirpath); 71 72#ifndef HAVE_SCHED_GETCPU_SUPPORT 73int sched_getcpu(void); 74#endif 75 76#endif /* GIT_COMPAT_UTIL_H */