]> icculus.org git repositories - icculus/xz.git/blob - src/xz/util.h
Cleanups to the code that detects the amount of RAM and
[icculus/xz.git] / src / xz / util.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       util.h
4 /// \brief      Miscellaneous utility functions
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2.1 of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 /// \brief      Safe malloc() that never returns NULL
21 ///
22 /// \note       xmalloc(), xrealloc(), and xstrdup() must not be used when
23 ///             there are files open for writing, that should be cleaned up
24 ///             before exiting.
25 #define xmalloc(size) xrealloc(NULL, size)
26
27
28 /// \brief      Safe realloc() that never returns NULL
29 extern void *xrealloc(void *ptr, size_t size);
30
31
32 /// \brief      Safe strdup() that never returns NULL
33 extern char *xstrdup(const char *src);
34
35
36 /// \brief      Fancy version of strtoull()
37 ///
38 /// \param      name    Name of the option to show in case of an error
39 /// \param      value   String containing the number to be parsed; may
40 ///                     contain suffixes "k", "M", "G", "Ki", "Mi", or "Gi"
41 /// \param      min     Minimum valid value
42 /// \param      max     Maximum valid value
43 ///
44 /// \return     Parsed value that is in the range [min, max]. Does not return
45 ///             if an error occurs.
46 ///
47 extern uint64_t str_to_uint64(const char *name, const char *value,
48                 uint64_t min, uint64_t max);
49
50
51 /// \brief      Check if filename is empty and print an error message
52 extern bool is_empty_filename(const char *filename);
53
54
55 /// \brief      Test if stdin is a terminal
56 ///
57 /// If stdin is a terminal, an error message is printed and exit status set
58 /// to EXIT_ERROR.
59 extern bool is_tty_stdin(void);
60
61
62 /// \brief      Test if stdout is a terminal
63 ///
64 /// If stdout is a terminal, an error message is printed and exit status set
65 /// to EXIT_ERROR.
66 extern bool is_tty_stdout(void);