-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathutils.h
74 lines (61 loc) · 1.45 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef utils_h
#define utils_h
#include <stdlib.h>
#ifndef VERSION
#define VERSION "(unknown version)"
#endif
#define DO_PRAGMA(x) _Pragma(#x)
/* Portable unroll pragma, for some reason clang defines __GNUC__ but uses the
* non-GCC unroll pragma format */
#if defined(__clang__)
#define PRAGMA_UNROLL(x) DO_PRAGMA(unroll x)
#elif defined(__GNUC__)
#define PRAGMA_UNROLL(x) DO_PRAGMA(GCC unroll x)
#else
#define PRAGMA_UNROLL(x) DO_PRAGMA(unroll x)
#endif
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define LEN(x) (sizeof(x)/sizeof(x[0]))
#ifndef sgn
#define sgn(x) ((x) < 0 ? -1 : 1)
#endif
/**
* Generate a symbol filename based on the current date and time
*
* @return filename
*/
char* gen_fname();
/**
* Format a number into a more readable format
*
* @param value value to
* @param buf buffer to write the resulting string to
*/
void humanize(size_t value, char *buf);
/**
* Format a number of seconds into HH:MM:SS format
*
* @param secs seconds
* @param buf buffer to write the resulting string to
*/
void seconds_to_str(unsigned secs, char *buf);
/**
* Convert a "human-readable" number into a float
* e.g. 137.1M = 137100.0
*
* @param human string to parse
* @return parsed float
*/
float human_to_float(const char *human);
/**
* Write usage info to stdout
*
* @param progname executable name
*/
void usage(const char *progname);
/**
* Write version info to stdout
*/
void version();
#endif