]> git.ipfire.org Git - thirdparty/glibc.git/blame - support/support.h
libsupport: Add support_select_normalizes_timeout
[thirdparty/glibc.git] / support / support.h
CommitLineData
c23de0aa 1/* Common extra functions.
2b778ceb 2 Copyright (C) 2016-2021 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
b2970919 26#include <stdbool.h>
c23de0aa
FW
27#include <stddef.h>
28#include <sys/cdefs.h>
561b0bec
DD
29/* For mode_t. */
30#include <sys/stat.h>
81b9d87b
L
31/* For ssize_t and off64_t. */
32#include <sys/types.h>
653200ef
AZ
33/* For locale_t. */
34#include <locale.h>
c23de0aa
FW
35
36__BEGIN_DECLS
37
38/* Write a message to standard output. Can be used in signal
39 handlers. */
40void write_message (const char *message) __attribute__ ((nonnull (1)));
41
42/* Avoid all the buffer overflow messages on stderr. */
43void ignore_stderr (void);
44
45/* Set fortification error handler. Used when tests want to verify that bad
46 code is caught by the library. */
47void set_fortify_handler (void (*handler) (int sig));
48
49/* Report an out-of-memory error for the allocation of SIZE bytes in
50 FUNCTION, terminating the process. */
51void oom_error (const char *function, size_t size)
52 __attribute__ ((nonnull (1)));
53
2714c5f3
FW
54/* Return a pointer to a memory region of SIZE bytes. The memory is
55 initialized to zero and will be shared with subprocesses (across
56 fork). The returned pointer must be freed using
57 support_shared_free; it is not compatible with the malloc
58 functions. */
59void *support_shared_allocate (size_t size);
60
61/* Deallocate a pointer returned by support_shared_allocate. */
62void support_shared_free (void *);
63
64/* Write CONTENTS to the file PATH. Create or truncate the file as
65 needed. The file mode is 0666 masked by the umask. Terminate the
66 process on error. */
67void support_write_file_string (const char *path, const char *contents);
68
2afece36
FW
69/* Quote the contents of the byte array starting at BLOB, of LENGTH
70 bytes, in such a way that the result string can be included in a C
71 literal (in single/double quotes, without putting the quotes into
72 the result). */
73char *support_quote_blob (const void *blob, size_t length);
74
47d8d9a2 75/* Quote the contents of the string, in such a way that the result
c74a91de
FW
76 string can be included in a C literal (in single/double quotes,
77 without putting the quotes into the result). */
47d8d9a2 78char *support_quote_string (const char *);
c74a91de 79
aa42b3db
FW
80/* Returns non-zero if the file descriptor is a regular file on a file
81 system which supports holes (that is, seeking and writing does not
82 allocate storage for the range of zeros). FD must refer to a
83 regular file open for writing, and initially empty. */
84int support_descriptor_supports_holes (int fd);
85
c23de0aa
FW
86/* Error-checking wrapper functions which terminate the process on
87 error. */
88
89void *xmalloc (size_t) __attribute__ ((malloc));
90void *xcalloc (size_t n, size_t s) __attribute__ ((malloc));
91void *xrealloc (void *p, size_t n);
bc79db3f 92void *xposix_memalign (size_t alignment, size_t n);
c23de0aa
FW
93char *xasprintf (const char *format, ...)
94 __attribute__ ((format (printf, 1, 2), malloc));
5840c75c 95char *xstrdup (const char *);
1ffe1ccb 96char *xstrndup (const char *, size_t);
cce35a50 97char *xsetlocale (int category, const char *locale);
653200ef
AZ
98locale_t xnewlocale (int category_mask, const char *locale, locale_t base);
99char *xuselocale (locale_t newloc);
c23de0aa 100
561b0bec
DD
101/* These point to the TOP of the source/build tree, not your (or
102 support's) subdirectory. */
103extern const char support_srcdir_root[];
104extern const char support_objdir_root[];
105
e7624d70
SL
106/* Corresponds to the path to the runtime linker used by the testsuite,
107 e.g. OBJDIR_PATH/elf/ld-linux-x86-64.so.2 */
108extern const char support_objdir_elf_ldso[];
109
561b0bec
DD
110/* Corresponds to the --prefix= passed to configure. */
111extern const char support_install_prefix[];
112/* Corresponds to the install's lib/ or lib64/ directory. */
113extern const char support_libdir_prefix[];
c7ac9caa
AZ
114/* Corresponds to the install's bin/ directory. */
115extern const char support_bindir_prefix[];
d50f0918 116/* Corresponds to the install's sbin/ directory. */
75c51570 117extern const char support_sbindir_prefix[];
cb81264f
FW
118/* Corresponds to the install's system /lib or /lib64 directory. */
119extern const char support_slibdir_prefix[];
75c51570 120/* Corresponds to the install's sbin/ directory (without prefix). */
d50f0918 121extern const char support_install_rootsbindir[];
92954ffa
CD
122/* Corresponds to the install's compiled locale directory. */
123extern const char support_complocaledir_prefix[];
561b0bec 124
603ae243
FW
125/* Copies the file at the path FROM to TO. If TO does not exist, it
126 is created. If TO is a regular file, it is truncated before
127 copying. The file mode is copied, but the permissions are not. */
128extern void support_copy_file (const char *from, const char *to);
129
81b9d87b
L
130extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *,
131 size_t, unsigned int);
132
6fbc0540 133/* Return true if PATH supports 64-bit time_t interfaces for file
b2970919 134 operations (such as fstatat or utimensat). */
6fbc0540
AZ
135extern bool support_path_support_time64_value (const char *path, int64_t at,
136 int64_t mt);
137static __inline bool support_path_support_time64 (const char *path)
138{
139 /* 1s and 2s after y2038 limit. */
140 return support_path_support_time64_value (path, 0x80000001ULL,
141 0x80000002ULL);
142}
b2970919 143
1966f47a 144/* Return true if stat supports nanoseconds resolution. */
bfddda25 145extern bool support_stat_nanoseconds (const char *path);
1966f47a 146
5628f103
AZ
147/* Return true if select modify the timeout to reflect the amount of time
148 no slept. */
149extern bool support_select_modifies_timeout (void);
150
49a40ba1
AZ
151/* Return true if select normalize the timeout input by taking in account
152 tv_usec larger than 1000000. */
153extern bool support_select_normalizes_timeout (void);
154
c23de0aa
FW
155__END_DECLS
156
157#endif /* SUPPORT_H */