1 | /* Common extra functions. |
2 | Copyright (C) 2016-2017 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ |
18 | |
19 | /* This header file should only contain definitions compatible with |
20 | C90. (Using __attribute__ is fine because <features.h> provides a |
21 | fallback.) */ |
22 | |
23 | #ifndef SUPPORT_H |
24 | #define SUPPORT_H |
25 | |
26 | #include <stddef.h> |
27 | #include <sys/cdefs.h> |
28 | |
29 | __BEGIN_DECLS |
30 | |
31 | /* Write a message to standard output. Can be used in signal |
32 | handlers. */ |
33 | void write_message (const char *message) __attribute__ ((nonnull (1))); |
34 | |
35 | /* Avoid all the buffer overflow messages on stderr. */ |
36 | void ignore_stderr (void); |
37 | |
38 | /* Set fortification error handler. Used when tests want to verify that bad |
39 | code is caught by the library. */ |
40 | void set_fortify_handler (void (*handler) (int sig)); |
41 | |
42 | /* Report an out-of-memory error for the allocation of SIZE bytes in |
43 | FUNCTION, terminating the process. */ |
44 | void oom_error (const char *function, size_t size) |
45 | __attribute__ ((nonnull (1))); |
46 | |
47 | /* Return a pointer to a memory region of SIZE bytes. The memory is |
48 | initialized to zero and will be shared with subprocesses (across |
49 | fork). The returned pointer must be freed using |
50 | support_shared_free; it is not compatible with the malloc |
51 | functions. */ |
52 | void *support_shared_allocate (size_t size); |
53 | |
54 | /* Deallocate a pointer returned by support_shared_allocate. */ |
55 | void support_shared_free (void *); |
56 | |
57 | /* Write CONTENTS to the file PATH. Create or truncate the file as |
58 | needed. The file mode is 0666 masked by the umask. Terminate the |
59 | process on error. */ |
60 | void support_write_file_string (const char *path, const char *contents); |
61 | |
62 | /* Error-checking wrapper functions which terminate the process on |
63 | error. */ |
64 | |
65 | void *xmalloc (size_t) __attribute__ ((malloc)); |
66 | void *xcalloc (size_t n, size_t s) __attribute__ ((malloc)); |
67 | void *xrealloc (void *p, size_t n); |
68 | char *xasprintf (const char *format, ...) |
69 | __attribute__ ((format (printf, 1, 2), malloc)); |
70 | char *xstrdup (const char *); |
71 | |
72 | __END_DECLS |
73 | |
74 | #endif /* SUPPORT_H */ |
75 | |