]> icculus.org git repositories - icculus/xz.git/blob - src/lzma/util.h
Oh well, big messy commit again. Some highlights:
[icculus/xz.git] / src / lzma / 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 #ifndef UTIL_H
21 #define UTIL_H
22
23 /// \brief      Safe malloc() that never returns NULL
24 ///
25 /// \note       xmalloc(), xrealloc(), and xstrdup() must not be used when
26 ///             there are files open for writing, that should be cleaned up
27 ///             before exiting.
28 #define xmalloc(size) xrealloc(NULL, size)
29
30
31 /// \brief      Safe realloc() that never returns NULL
32 extern void *xrealloc(void *ptr, size_t size);
33
34
35 /// \brief      Safe strdup() that never returns NULL
36 extern char *xstrdup(const char *src);
37
38
39 /// \brief      Fancy version of strtoull()
40 ///
41 /// \param      name    Name of the option to show in case of an error
42 /// \param      value   String containing the number to be parsed; may
43 ///                     contain suffixes "k", "M", "G", "Ki", "Mi", or "Gi"
44 /// \param      min     Minimum valid value
45 /// \param      max     Maximum valid value
46 ///
47 /// \return     Parsed value that is in the range [min, max]. Does not return
48 ///             if an error occurs.
49 ///
50 extern uint64_t str_to_uint64(const char *name, const char *value,
51                 uint64_t min, uint64_t max);
52
53
54 /// \brief      Check if filename is empty and print an error message
55 extern bool is_empty_filename(const char *filename);
56
57
58 /// \brief      Test if stdin is a terminal
59 ///
60 /// If stdin is a terminal, an error message is printed and exit status set
61 /// to EXIT_ERROR.
62 extern bool is_tty_stdin(void);
63
64
65 /// \brief      Test if stdout is a terminal
66 ///
67 /// If stdout is a terminal, an error message is printed and exit status set
68 /// to EXIT_ERROR.
69 extern bool is_tty_stdout(void);
70
71 #endif