Use GCC builtins for round functions if desired.
[glibc.git] / support / support.h
blobc10234404a6fc53a19c9b20a204fd64d15c68b52
1 /* Common extra functions.
2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 /* This header file should only contain definitions compatible with
20 C90. (Using __attribute__ is fine because <features.h> provides a
21 fallback.) */
23 #ifndef SUPPORT_H
24 #define SUPPORT_H
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>
33 __BEGIN_DECLS
35 /* Write a message to standard output. Can be used in signal
36 handlers. */
37 void write_message (const char *message) __attribute__ ((nonnull (1)));
39 /* Avoid all the buffer overflow messages on stderr. */
40 void ignore_stderr (void);
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));
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)));
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);
58 /* Deallocate a pointer returned by support_shared_allocate. */
59 void support_shared_free (void *);
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);
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);
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). */
75 char *support_quote_string (const char *);
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);
83 /* Error-checking wrapper functions which terminate the process on
84 error. */
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);
89 void *xposix_memalign (size_t alignment, size_t n);
90 char *xasprintf (const char *format, ...)
91 __attribute__ ((format (printf, 1, 2), malloc));
92 char *xstrdup (const char *);
93 char *xstrndup (const char *, size_t);
94 char *xsetlocale (int category, const char *locale);
96 /* These point to the TOP of the source/build tree, not your (or
97 support's) subdirectory. */
98 extern const char support_srcdir_root[];
99 extern const char support_objdir_root[];
101 /* Corresponds to the path to the runtime linker used by the testsuite,
102 e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
103 extern const char support_objdir_elf_ldso[];
105 /* Corresponds to the --prefix= passed to configure. */
106 extern const char support_install_prefix[];
107 /* Corresponds to the install's lib/ or lib64/ directory. */
108 extern const char support_libdir_prefix[];
109 /* Corresponds to the install's bin/ directory. */
110 extern const char support_bindir_prefix[];
111 /* Corresponds to the install's sbin/ directory. */
112 extern const char support_sbindir_prefix[];
113 /* Corresponds to the install's sbin/ directory (without prefix). */
114 extern const char support_install_rootsbindir[];
116 extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *,
117 size_t, unsigned int);
119 __END_DECLS
121 #endif /* SUPPORT_H */