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