]>
Commit | Line | Data |
---|---|---|
c23de0aa | 1 | /* Common extra functions. |
04277e02 | 2 | Copyright (C) 2016-2019 Free Software Foundation, Inc. |
c23de0aa FW |
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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
c23de0aa FW |
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> | |
561b0bec DD |
28 | /* For mode_t. */ |
29 | #include <sys/stat.h> | |
81b9d87b L |
30 | /* For ssize_t and off64_t. */ |
31 | #include <sys/types.h> | |
c23de0aa FW |
32 | |
33 | __BEGIN_DECLS | |
34 | ||
35 | /* Write a message to standard output. Can be used in signal | |
36 | handlers. */ | |
37 | void write_message (const char *message) __attribute__ ((nonnull (1))); | |
38 | ||
39 | /* Avoid all the buffer overflow messages on stderr. */ | |
40 | void ignore_stderr (void); | |
41 | ||
42 | /* Set fortification error handler. Used when tests want to verify that bad | |
43 | code is caught by the library. */ | |
44 | void 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. */ | |
48 | void oom_error (const char *function, size_t size) | |
49 | __attribute__ ((nonnull (1))); | |
50 | ||
2714c5f3 FW |
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. */ | |
56 | void *support_shared_allocate (size_t size); | |
57 | ||
58 | /* Deallocate a pointer returned by support_shared_allocate. */ | |
59 | void 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. */ | |
64 | void support_write_file_string (const char *path, const char *contents); | |
65 | ||
2afece36 FW |
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). */ | |
70 | char *support_quote_blob (const void *blob, size_t length); | |
71 | ||
47d8d9a2 | 72 | /* Quote the contents of the string, in such a way that the result |
c74a91de FW |
73 | string can be included in a C literal (in single/double quotes, |
74 | without putting the quotes into the result). */ | |
47d8d9a2 | 75 | char *support_quote_string (const char *); |
c74a91de | 76 | |
aa42b3db FW |
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. */ | |
81 | int support_descriptor_supports_holes (int fd); | |
82 | ||
c23de0aa FW |
83 | /* Error-checking wrapper functions which terminate the process on |
84 | error. */ | |
85 | ||
86 | void *xmalloc (size_t) __attribute__ ((malloc)); | |
87 | void *xcalloc (size_t n, size_t s) __attribute__ ((malloc)); | |
88 | void *xrealloc (void *p, size_t n); | |
bc79db3f | 89 | void *xposix_memalign (size_t alignment, size_t n); |
c23de0aa FW |
90 | char *xasprintf (const char *format, ...) |
91 | __attribute__ ((format (printf, 1, 2), malloc)); | |
5840c75c | 92 | char *xstrdup (const char *); |
1ffe1ccb | 93 | char *xstrndup (const char *, size_t); |
c23de0aa | 94 | |
561b0bec DD |
95 | /* These point to the TOP of the source/build tree, not your (or |
96 | support's) subdirectory. */ | |
97 | extern const char support_srcdir_root[]; | |
98 | extern const char support_objdir_root[]; | |
99 | ||
e7624d70 SL |
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 */ | |
102 | extern const char support_objdir_elf_ldso[]; | |
103 | ||
561b0bec DD |
104 | /* Corresponds to the --prefix= passed to configure. */ |
105 | extern const char support_install_prefix[]; | |
106 | /* Corresponds to the install's lib/ or lib64/ directory. */ | |
107 | extern const char support_libdir_prefix[]; | |
c7ac9caa AZ |
108 | /* Corresponds to the install's bin/ directory. */ |
109 | extern const char support_bindir_prefix[]; | |
d50f0918 | 110 | /* Corresponds to the install's sbin/ directory. */ |
75c51570 FW |
111 | extern const char support_sbindir_prefix[]; |
112 | /* Corresponds to the install's sbin/ directory (without prefix). */ | |
d50f0918 | 113 | extern const char support_install_rootsbindir[]; |
561b0bec | 114 | |
81b9d87b L |
115 | extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *, |
116 | size_t, unsigned int); | |
117 | ||
c23de0aa FW |
118 | __END_DECLS |
119 | ||
120 | #endif /* SUPPORT_H */ |