util.h 1.7 KB
Newer Older
1 2 3 4
#ifndef GIT_COMPAT_UTIL_H
#define GIT_COMPAT_UTIL_H

#define _BSD_SOURCE 1
5 6
/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE 1
7

8
#include <stdbool.h>
9 10 11
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
12
#include <linux/compiler.h>
B
Borislav Petkov 已提交
13
#include <linux/types.h>
14
#include "namespaces.h"
15

16
/* General helper functions */
17
void usage(const char *err) __noreturn;
18
void die(const char *err, ...) __noreturn __printf(1, 2);
19

20 21 22 23 24
static inline void *zalloc(size_t size)
{
	return calloc(1, size);
}

25 26
#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })

27
struct dirent;
28 29
struct strlist;

30
int mkdir_p(char *path, mode_t mode);
31
int rm_rf(const char *path);
32 33
struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
bool lsdir_no_dot_filter(const char *name, struct dirent *d);
34
int copyfile(const char *from, const char *to);
A
Adrian Hunter 已提交
35
int copyfile_mode(const char *from, const char *to, mode_t mode);
36
int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
37

38
ssize_t readn(int fd, void *buf, size_t n);
39
ssize_t writen(int fd, const void *buf, size_t n);
40

41
size_t hex_width(u64 v);
42
int hex2u64(const char *ptr, u64 *val);
43

44
extern unsigned int page_size;
45
extern int cacheline_size;
46

47 48
int fetch_kernel_version(unsigned int *puint,
			 char *str, size_t str_sz);
49 50 51 52 53
#define KVER_VERSION(x)		(((x) >> 16) & 0xff)
#define KVER_PATCHLEVEL(x)	(((x) >> 8) & 0xff)
#define KVER_SUBLEVEL(x)	((x) & 0xff)
#define KVER_FMT	"%d.%d.%d"
#define KVER_PARAM(x)	KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
54

55 56
const char *perf_tip(const char *dirpath);

57 58
#ifndef HAVE_SCHED_GETCPU_SUPPORT
int sched_getcpu(void);
59 60
#endif

61 62 63 64
#ifndef HAVE_SETNS_SUPPORT
int setns(int fd, int nstype);
#endif

65
#endif /* GIT_COMPAT_UTIL_H */