1/* Common extra functions.
2 Copyright (C) 2016-2019 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/* For mode_t. */
29#include <sys/stat.h>
30/* For ssize_t and off64_t. */
31#include <sys/types.h>
32
33__BEGIN_DECLS
34
35/* Write a message to standard output. Can be used in signal
36 handlers. */
37void write_message (const char *message) __attribute__ ((nonnull (1)));
38
39/* Avoid all the buffer overflow messages on stderr. */
40void ignore_stderr (void);
41
42/* Set fortification error handler. Used when tests want to verify that bad
43 code is caught by the library. */
44void set_fortify_handler (void (*handler) (int sig));
45
46/* Report an out-of-memory error for the allocation of SIZE bytes in
47 FUNCTION, terminating the process. */
48void oom_error (const char *function, size_t size)
49 __attribute__ ((nonnull (1)));
50
51/* Return a pointer to a memory region of SIZE bytes. The memory is
52 initialized to zero and will be shared with subprocesses (across
53 fork). The returned pointer must be freed using
54 support_shared_free; it is not compatible with the malloc
55 functions. */
56void *support_shared_allocate (size_t size);
57
58/* Deallocate a pointer returned by support_shared_allocate. */
59void support_shared_free (void *);
60
61/* Write CONTENTS to the file PATH. Create or truncate the file as
62 needed. The file mode is 0666 masked by the umask. Terminate the
63 process on error. */
64void support_write_file_string (const char *path, const char *contents);
65
66/* Quote the contents of the byte array starting at BLOB, of LENGTH
67 bytes, in such a way that the result string can be included in a C
68 literal (in single/double quotes, without putting the quotes into
69 the result). */
70char *support_quote_blob (const void *blob, size_t length);
71
72/* Quote the contents of the string, in such a way that the result
73 string can be included in a C literal (in single/double quotes,
74 without putting the quotes into the result). */
75char *support_quote_string (const char *);
76
77/* Returns non-zero if the file descriptor is a regular file on a file
78 system which supports holes (that is, seeking and writing does not
79 allocate storage for the range of zeros). FD must refer to a
80 regular file open for writing, and initially empty. */
81int support_descriptor_supports_holes (int fd);
82
83/* Error-checking wrapper functions which terminate the process on
84 error. */
85
86void *xmalloc (size_t) __attribute__ ((malloc));
87void *xcalloc (size_t n, size_t s) __attribute__ ((malloc));
88void *xrealloc (void *p, size_t n);
89void *xposix_memalign (size_t alignment, size_t n);
90char *xasprintf (const char *format, ...)
91 __attribute__ ((format (printf, 1, 2), malloc));
92char *xstrdup (const char *);
93char *xstrndup (const char *, size_t);
94
95/* These point to the TOP of the source/build tree, not your (or
96 support's) subdirectory. */
97extern const char support_srcdir_root[];
98extern const char support_objdir_root[];
99
100/* Corresponds to the path to the runtime linker used by the testsuite,
101 e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
102extern const char support_objdir_elf_ldso[];
103
104/* Corresponds to the --prefix= passed to configure. */
105extern const char support_install_prefix[];
106/* Corresponds to the install's lib/ or lib64/ directory. */
107extern const char support_libdir_prefix[];
108
109extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *,
110 size_t, unsigned int);
111
112__END_DECLS
113
114#endif /* SUPPORT_H */
115