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
|
///////////////////////////////////////////////////////////////////////////////
//
/// \file util.h
/// \brief Miscellaneous utility functions
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
/// \brief Safe malloc() that never returns NULL
///
/// \note xmalloc(), xrealloc(), and xstrdup() must not be used when
/// there are files open for writing, that should be cleaned up
/// before exiting.
#define xmalloc(size) xrealloc(NULL, size)
/// \brief Safe realloc() that never returns NULL
extern void *xrealloc(void *ptr, size_t size);
/// \brief Safe strdup() that never returns NULL
extern char *xstrdup(const char *src);
/// \brief Fancy version of strtoull()
///
/// \param name Name of the option to show in case of an error
/// \param value String containing the number to be parsed; may
/// contain suffixes "k", "M", "G", "Ki", "Mi", or "Gi"
/// \param min Minimum valid value
/// \param max Maximum valid value
///
/// \return Parsed value that is in the range [min, max]. Does not return
/// if an error occurs.
///
extern uint64_t str_to_uint64(const char *name, const char *value,
uint64_t min, uint64_t max);
/// \brief Check if filename is empty and print an error message
extern bool is_empty_filename(const char *filename);
/// \brief Test if stdin is a terminal
///
/// If stdin is a terminal, an error message is printed and exit status set
/// to EXIT_ERROR.
extern bool is_tty_stdin(void);
/// \brief Test if stdout is a terminal
///
/// If stdout is a terminal, an error message is printed and exit status set
/// to EXIT_ERROR.
extern bool is_tty_stdout(void);
|