aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/util.h')
-rw-r--r--tools/perf/util/util.h177
1 files changed, 14 insertions, 163 deletions
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 0795bf304b19..4e8b6b0c551c 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -81,7 +81,7 @@
81#include <inttypes.h> 81#include <inttypes.h>
82#include "../../../include/linux/magic.h" 82#include "../../../include/linux/magic.h"
83#include "types.h" 83#include "types.h"
84 84#include <sys/ttydefaults.h>
85 85
86#ifndef NO_ICONV 86#ifndef NO_ICONV
87#include <iconv.h> 87#include <iconv.h>
@@ -152,7 +152,6 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
152extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); 152extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
153 153
154extern int prefixcmp(const char *str, const char *prefix); 154extern int prefixcmp(const char *str, const char *prefix);
155extern time_t tm_to_time_t(const struct tm *tm);
156 155
157static inline const char *skip_prefix(const char *str, const char *prefix) 156static inline const char *skip_prefix(const char *str, const char *prefix)
158{ 157{
@@ -160,119 +159,6 @@ static inline const char *skip_prefix(const char *str, const char *prefix)
160 return strncmp(str, prefix, len) ? NULL : str + len; 159 return strncmp(str, prefix, len) ? NULL : str + len;
161} 160}
162 161
163#if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
164
165#ifndef PROT_READ
166#define PROT_READ 1
167#define PROT_WRITE 2
168#define MAP_PRIVATE 1
169#define MAP_FAILED ((void*)-1)
170#endif
171
172#define mmap git_mmap
173#define munmap git_munmap
174extern void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
175extern int git_munmap(void *start, size_t length);
176
177#else /* NO_MMAP || USE_WIN32_MMAP */
178
179#include <sys/mman.h>
180
181#endif /* NO_MMAP || USE_WIN32_MMAP */
182
183#ifdef NO_MMAP
184
185/* This value must be multiple of (pagesize * 2) */
186#define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
187
188#else /* NO_MMAP */
189
190/* This value must be multiple of (pagesize * 2) */
191#define DEFAULT_PACKED_GIT_WINDOW_SIZE \
192 (sizeof(void*) >= 8 \
193 ? 1 * 1024 * 1024 * 1024 \
194 : 32 * 1024 * 1024)
195
196#endif /* NO_MMAP */
197
198#ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
199#define on_disk_bytes(st) ((st).st_size)
200#else
201#define on_disk_bytes(st) ((st).st_blocks * 512)
202#endif
203
204#define DEFAULT_PACKED_GIT_LIMIT \
205 ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
206
207#ifdef NO_PREAD
208#define pread git_pread
209extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
210#endif
211/*
212 * Forward decl that will remind us if its twin in cache.h changes.
213 * This function is used in compat/pread.c. But we can't include
214 * cache.h there.
215 */
216extern ssize_t read_in_full(int fd, void *buf, size_t count);
217
218#ifdef NO_SETENV
219#define setenv gitsetenv
220extern int gitsetenv(const char *, const char *, int);
221#endif
222
223#ifdef NO_MKDTEMP
224#define mkdtemp gitmkdtemp
225extern char *gitmkdtemp(char *);
226#endif
227
228#ifdef NO_UNSETENV
229#define unsetenv gitunsetenv
230extern void gitunsetenv(const char *);
231#endif
232
233#ifdef NO_STRCASESTR
234#define strcasestr gitstrcasestr
235extern char *gitstrcasestr(const char *haystack, const char *needle);
236#endif
237
238#ifdef NO_STRLCPY
239#define strlcpy gitstrlcpy
240extern size_t gitstrlcpy(char *, const char *, size_t);
241#endif
242
243#ifdef NO_STRTOUMAX
244#define strtoumax gitstrtoumax
245extern uintmax_t gitstrtoumax(const char *, char **, int);
246#endif
247
248#ifdef NO_HSTRERROR
249#define hstrerror githstrerror
250extern const char *githstrerror(int herror);
251#endif
252
253#ifdef NO_MEMMEM
254#define memmem gitmemmem
255void *gitmemmem(const void *haystack, size_t haystacklen,
256 const void *needle, size_t needlelen);
257#endif
258
259#ifdef FREAD_READS_DIRECTORIES
260#ifdef fopen
261#undef fopen
262#endif
263#define fopen(a,b) git_fopen(a,b)
264extern FILE *git_fopen(const char*, const char*);
265#endif
266
267#ifdef SNPRINTF_RETURNS_BOGUS
268#define snprintf git_snprintf
269extern int git_snprintf(char *str, size_t maxsize,
270 const char *format, ...);
271#define vsnprintf git_vsnprintf
272extern int git_vsnprintf(char *str, size_t maxsize,
273 const char *format, va_list ap);
274#endif
275
276#ifdef __GLIBC_PREREQ 162#ifdef __GLIBC_PREREQ
277#if __GLIBC_PREREQ(2, 1) 163#if __GLIBC_PREREQ(2, 1)
278#define HAVE_STRCHRNUL 164#define HAVE_STRCHRNUL
@@ -293,28 +179,14 @@ static inline char *gitstrchrnul(const char *s, int c)
293 * Wrappers: 179 * Wrappers:
294 */ 180 */
295extern char *xstrdup(const char *str); 181extern char *xstrdup(const char *str);
296extern void *xmalloc(size_t size) __attribute__((weak));
297extern void *xmemdupz(const void *data, size_t len);
298extern char *xstrndup(const char *str, size_t len);
299extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); 182extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
300 183
301static inline void *xzalloc(size_t size)
302{
303 void *buf = xmalloc(size);
304
305 return memset(buf, 0, size);
306}
307 184
308static inline void *zalloc(size_t size) 185static inline void *zalloc(size_t size)
309{ 186{
310 return calloc(1, size); 187 return calloc(1, size);
311} 188}
312 189
313static inline size_t xsize_t(off_t len)
314{
315 return (size_t)len;
316}
317
318static inline int has_extension(const char *filename, const char *ext) 190static inline int has_extension(const char *filename, const char *ext)
319{ 191{
320 size_t len = strlen(filename); 192 size_t len = strlen(filename);
@@ -351,8 +223,6 @@ extern unsigned char sane_ctype[256];
351#define isalpha(x) sane_istest(x,GIT_ALPHA) 223#define isalpha(x) sane_istest(x,GIT_ALPHA)
352#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) 224#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
353#define isprint(x) sane_istest(x,GIT_PRINT) 225#define isprint(x) sane_istest(x,GIT_PRINT)
354#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
355#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
356#define tolower(x) sane_case((unsigned char)(x), 0x20) 226#define tolower(x) sane_case((unsigned char)(x), 0x20)
357#define toupper(x) sane_case((unsigned char)(x), 0) 227#define toupper(x) sane_case((unsigned char)(x), 0)
358 228
@@ -363,38 +233,6 @@ static inline int sane_case(int x, int high)
363 return x; 233 return x;
364} 234}
365 235
366static inline int strtoul_ui(char const *s, int base, unsigned int *result)
367{
368 unsigned long ul;
369 char *p;
370
371 errno = 0;
372 ul = strtoul(s, &p, base);
373 if (errno || *p || p == s || (unsigned int) ul != ul)
374 return -1;
375 *result = ul;
376 return 0;
377}
378
379static inline int strtol_i(char const *s, int base, int *result)
380{
381 long ul;
382 char *p;
383
384 errno = 0;
385 ul = strtol(s, &p, base);
386 if (errno || *p || p == s || (int) ul != ul)
387 return -1;
388 *result = ul;
389 return 0;
390}
391
392#ifdef INTERNAL_QSORT
393void git_qsort(void *base, size_t nmemb, size_t size,
394 int(*compar)(const void *, const void *));
395#define qsort git_qsort
396#endif
397
398#ifndef DIR_HAS_BSD_GROUP_SEMANTICS 236#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
399# define FORCE_DIR_SET_GID S_ISGID 237# define FORCE_DIR_SET_GID S_ISGID
400#else 238#else
@@ -425,6 +263,19 @@ bool strglobmatch(const char *str, const char *pat);
425bool strlazymatch(const char *str, const char *pat); 263bool strlazymatch(const char *str, const char *pat);
426unsigned long convert_unit(unsigned long value, char *unit); 264unsigned long convert_unit(unsigned long value, char *unit);
427 265
266#ifndef ESC
267#define ESC 27
268#endif
269
270static inline bool is_exit_key(int key)
271{
272 char up;
273 if (key == CTRL('c') || key == ESC)
274 return true;
275 up = toupper(key);
276 return up == 'Q';
277}
278
428#define _STR(x) #x 279#define _STR(x) #x
429#define STR(x) _STR(x) 280#define STR(x) _STR(x)
430 281