Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 2 | #ifndef GIT_COMPAT_UTIL_H |
| 3 | #define GIT_COMPAT_UTIL_H |
| 4 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 5 | #define _BSD_SOURCE 1 |
Chanho Park | 512fe36 | 2014-09-12 11:10:17 +0900 | [diff] [blame] | 6 | /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ |
| 7 | #define _DEFAULT_SOURCE 1 |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 8 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 9 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 10 | #include <stdbool.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stdarg.h> |
Arnaldo Carvalho de Melo | 6c34664 | 2017-06-16 11:39:15 -0300 | [diff] [blame] | 14 | #include <linux/compiler.h> |
Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 15 | #include <linux/types.h> |
Krister Johansen | f045b8c | 2017-07-05 18:48:11 -0700 | [diff] [blame] | 16 | #include "namespaces.h" |
Frederic Weisbecker | 1fe2c10 | 2009-08-12 10:19:53 +0200 | [diff] [blame] | 17 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 18 | /* General helper functions */ |
Arnaldo Carvalho de Melo | 6c34664 | 2017-06-16 11:39:15 -0300 | [diff] [blame] | 19 | void usage(const char *err) __noreturn; |
Arnaldo Carvalho de Melo | afaed6d | 2017-06-16 11:57:54 -0300 | [diff] [blame] | 20 | void die(const char *err, ...) __noreturn __printf(1, 2); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 21 | |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 22 | static inline void *zalloc(size_t size) |
| 23 | { |
| 24 | return calloc(1, size); |
| 25 | } |
| 26 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 27 | #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) |
| 28 | |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 29 | struct dirent; |
Arnaldo Carvalho de Melo | 8ec20b1 | 2017-04-18 10:57:25 -0300 | [diff] [blame] | 30 | struct strlist; |
| 31 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 32 | int mkdir_p(char *path, mode_t mode); |
Joe Stringer | 9a9c733 | 2017-01-26 13:19:59 -0800 | [diff] [blame] | 33 | int rm_rf(const char *path); |
Masami Hiramatsu | e1ce726 | 2016-04-26 18:02:42 +0900 | [diff] [blame] | 34 | struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *)); |
| 35 | bool lsdir_no_dot_filter(const char *name, struct dirent *d); |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 36 | int copyfile(const char *from, const char *to); |
Adrian Hunter | 9a17d72 | 2013-10-14 13:43:41 +0300 | [diff] [blame] | 37 | int copyfile_mode(const char *from, const char *to, mode_t mode); |
Krister Johansen | f045b8c | 2017-07-05 18:48:11 -0700 | [diff] [blame] | 38 | int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi); |
Namhyung Kim | 9c9f5a2 | 2015-05-18 09:30:18 +0900 | [diff] [blame] | 39 | int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 40 | |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 41 | ssize_t readn(int fd, void *buf, size_t n); |
David Carrillo-Cisneros | 7c72440 | 2017-07-17 21:25:37 -0700 | [diff] [blame] | 42 | ssize_t writen(int fd, const void *buf, size_t n); |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 43 | |
Arnaldo Carvalho de Melo | 61e04b3 | 2012-04-19 13:15:24 -0300 | [diff] [blame] | 44 | size_t hex_width(u64 v); |
Jiri Olsa | b2aff5f | 2012-10-27 23:18:30 +0200 | [diff] [blame] | 45 | int hex2u64(const char *ptr, u64 *val); |
Arnaldo Carvalho de Melo | 61e04b3 | 2012-04-19 13:15:24 -0300 | [diff] [blame] | 46 | |
Arnaldo Carvalho de Melo | 0c1fe6b | 2012-10-06 14:57:10 -0300 | [diff] [blame] | 47 | extern unsigned int page_size; |
Don Zickus | 2b1b710 | 2014-05-30 16:10:05 -0400 | [diff] [blame] | 48 | extern int cacheline_size; |
Arnaldo Carvalho de Melo | 0c1fe6b | 2012-10-06 14:57:10 -0300 | [diff] [blame] | 49 | |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 50 | int fetch_kernel_version(unsigned int *puint, |
| 51 | char *str, size_t str_sz); |
Wang Nan | d3e0ce3 | 2015-11-06 13:58:09 +0000 | [diff] [blame] | 52 | #define KVER_VERSION(x) (((x) >> 16) & 0xff) |
| 53 | #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff) |
| 54 | #define KVER_SUBLEVEL(x) ((x) & 0xff) |
| 55 | #define KVER_FMT "%d.%d.%d" |
| 56 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 57 | |
Namhyung Kim | 14cbfbe | 2016-01-07 20:41:53 +0900 | [diff] [blame] | 58 | const char *perf_tip(const char *dirpath); |
| 59 | |
Arnaldo Carvalho de Melo | 120010c | 2017-03-02 12:55:49 -0300 | [diff] [blame] | 60 | #ifndef HAVE_SCHED_GETCPU_SUPPORT |
| 61 | int sched_getcpu(void); |
Arnaldo Carvalho de Melo | c7007e9 | 2016-07-12 10:29:31 -0300 | [diff] [blame] | 62 | #endif |
| 63 | |
Arnaldo Carvalho de Melo | 86bcdb5 | 2017-07-18 17:15:29 -0300 | [diff] [blame] | 64 | #ifndef HAVE_SETNS_SUPPORT |
| 65 | int setns(int fd, int nstype); |
| 66 | #endif |
| 67 | |
Borislav Petkov | 1355915 | 2013-02-20 16:32:31 +0100 | [diff] [blame] | 68 | #endif /* GIT_COMPAT_UTIL_H */ |