blob: f486fdd3a538fb76d0060e0928f62f3634e4dcde [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnar07800602009-04-20 15:00:56 +02002#ifndef GIT_COMPAT_UTIL_H
3#define GIT_COMPAT_UTIL_H
4
Ingo Molnar07800602009-04-20 15:00:56 +02005#define _BSD_SOURCE 1
Chanho Park512fe362014-09-12 11:10:17 +09006/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7#define _DEFAULT_SOURCE 1
Ingo Molnar07800602009-04-20 15:00:56 +02008
Jiri Olsaed93d0a2018-09-13 14:54:11 +02009#include <fcntl.h>
Arnaldo Carvalho de Meloe206d552010-04-03 10:19:26 -030010#include <stdbool.h>
Ingo Molnar07800602009-04-20 15:00:56 +020011#include <stddef.h>
Arnaldo Carvalho de Melo6c346642017-06-16 11:39:15 -030012#include <linux/compiler.h>
Arnaldo Carvalho de Meload0902e2018-04-06 14:53:56 -030013#include <sys/types.h>
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020014
Ingo Molnar07800602009-04-20 15:00:56 +020015/* General helper functions */
Arnaldo Carvalho de Melo6c346642017-06-16 11:39:15 -030016void usage(const char *err) __noreturn;
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -030017void die(const char *err, ...) __noreturn __printf(1, 2);
Ingo Molnar07800602009-04-20 15:00:56 +020018
Arnaldo Carvalho de Melo76b31a22017-04-18 12:26:44 -030019struct dirent;
Arnaldo Carvalho de Melo8ec20b12017-04-18 10:57:25 -030020struct strlist;
21
Arnaldo Carvalho de Melo4cf40132009-12-27 21:37:06 -020022int mkdir_p(char *path, mode_t mode);
Joe Stringer9a9c7332017-01-26 13:19:59 -080023int rm_rf(const char *path);
Jiri Olsac69e4c32019-02-24 20:06:39 +010024int rm_rf_perf_data(const char *path);
Masami Hiramatsue1ce7262016-04-26 18:02:42 +090025struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
26bool lsdir_no_dot_filter(const char *name, struct dirent *d);
Arnaldo Carvalho de Melo4cf40132009-12-27 21:37:06 -020027
Arnaldo Carvalho de Melo61e04b32012-04-19 13:15:24 -030028size_t hex_width(u64 v);
29
Arnaldo Carvalho de Melo029c75e2018-05-17 16:31:32 -030030int sysctl__max_stack(void);
31
Kan Liang2a14c1b2020-02-24 13:59:22 -080032bool sysctl__nmi_watchdog_enabled(void);
33
Wang Nan07bc5c62015-11-06 13:55:35 +000034int fetch_kernel_version(unsigned int *puint,
35 char *str, size_t str_sz);
Wang Nand3e0ce32015-11-06 13:58:09 +000036#define KVER_VERSION(x) (((x) >> 16) & 0xff)
37#define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
38#define KVER_SUBLEVEL(x) ((x) & 0xff)
39#define KVER_FMT "%d.%d.%d"
40#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
Wang Nan07bc5c62015-11-06 13:55:35 +000041
Namhyung Kim14cbfbe2016-01-07 20:41:53 +090042const char *perf_tip(const char *dirpath);
43
Arnaldo Carvalho de Melo120010c2017-03-02 12:55:49 -030044#ifndef HAVE_SCHED_GETCPU_SUPPORT
45int sched_getcpu(void);
Arnaldo Carvalho de Meloc7007e92016-07-12 10:29:31 -030046#endif
47
Arnaldo Carvalho de Melo0a7c74e2017-04-04 13:15:04 -030048extern bool perf_singlethreaded;
49
50void perf_set_singlethreaded(void);
51void perf_set_multithreaded(void);
52
Andi Kleen94816ad2019-02-24 07:37:19 -080053char *perf_exe(char *buf, int len);
54
Arnaldo Carvalho de Melo5c61d702018-01-22 17:11:30 -030055#ifndef O_CLOEXEC
56#ifdef __sparc__
57#define O_CLOEXEC 0x400000
58#elif defined(__alpha__) || defined(__hppa__)
59#define O_CLOEXEC 010000000
60#else
61#define O_CLOEXEC 02000000
62#endif
63#endif
64
Borislav Petkov13559152013-02-20 16:32:31 +010065#endif /* GIT_COMPAT_UTIL_H */