xref: /reactos/sdk/lib/fslib/vfatlib/check/common.h (revision f4d29a74)
1 /* common.h - Common functions
2 
3    Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4    Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
5 
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19    The complete text of the GNU General Public License
20    can be found in /usr/share/common-licenses/GPL-3 file.
21 */
22 
23 #ifndef _COMMON_H
24 #define _COMMON_H
25 
26 #ifndef __REACTOS__
27 void die(const char *msg, ...)
28     __attribute((noreturn, format(printf, 1, 2)));
29 #else
30 DECLSPEC_NORETURN // __attribute((noreturn))
31 void die_func(const char *msg, ...);
32 #define die(msg, ...)   \
33 do {                    \
34     die_func("DIE! (%s:%d) " msg "\n", __RELFILE__, __LINE__, ##__VA_ARGS__);  \
35 } while (0)
36 #endif
37 
38 /* Displays a prinf-style message and terminates the program. */
39 
40 #ifndef __REACTOS__
41 void pdie(const char *msg, ...)
42     __attribute((noreturn, format(printf, 1, 2)));
43 #else
44 DECLSPEC_NORETURN // __attribute((noreturn))
45 void pdie_func(const char *msg, ...);
46 #define pdie(msg, ...)   \
47 do {                    \
48     pdie_func("P-DIE! (%s:%d) " msg "\n", __RELFILE__, __LINE__, ##__VA_ARGS__);  \
49 } while (0)
50 #endif
51 
52 /* Like die, but appends an error message according to the state of errno. */
53 
54 #ifndef __REACTOS__
55 void *alloc(int size);
56 #else
57 void *vfalloc(int size);
58 void *vfcalloc(int size, int count);
59 void vffree(void *ptr);
60 #endif
61 
62 /* mallocs SIZE bytes and returns a pointer to the data. Terminates the program
63    if malloc fails. */
64 
65 void *qalloc(void **root, int size);
66 
67 /* Like alloc, but registers the data area in a list described by ROOT. */
68 
69 void qfree(void **root);
70 
71 /* Deallocates all qalloc'ed data areas described by ROOT. */
72 
73 #ifndef __REACTOS__
74 int min(int a, int b);
75 #endif
76 
77 /* Returns the smaller integer value of a and b. */
78 
79 char get_key(const char *valid, const char *prompt);
80 
81 /* Displays PROMPT and waits for user input. Only characters in VALID are
82    accepted. Terminates the program on EOF. Returns the character. */
83 
84 #endif
85