grep(1): Disable use of unlocked IO in btools.
[dragonfly.git] / contrib / grep / src / system.h
1 /* Portability cruft.  Include after config.h and sys/types.h.
2    Copyright 1996, 1998-2000, 2007, 2009-2015 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
17    02110-1301, USA.  */
18
19 #ifndef GREP_SYSTEM_H
20 #define GREP_SYSTEM_H 1
21
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <errno.h>
25
26 #include "binary-io.h"
27 #include "configmake.h"
28 #include "dirname.h"
29 #include "ignore-value.h"
30 #include "minmax.h"
31 #include "same-inode.h"
32
33 #include <stdlib.h>
34 #include <stddef.h>
35 #include <limits.h>
36 #include <string.h>
37 #include <ctype.h>
38
39 enum { EXIT_TROUBLE = 2 };
40
41 #include <gettext.h>
42 #define N_(String) gettext_noop(String)
43 #define _(String) gettext(String)
44
45 #include <locale.h>
46
47 #ifndef initialize_main
48 # define initialize_main(argcp, argvp)
49 #endif
50
51 #ifndef BOOTSTRAPPING
52 #include "unlocked-io.h"
53 #endif
54
55 _GL_INLINE_HEADER_BEGIN
56 #ifndef SYSTEM_INLINE
57 # define SYSTEM_INLINE _GL_INLINE
58 #endif
59
60 #define STREQ(a, b) (strcmp (a, b) == 0)
61
62 /* Convert a possibly-signed character to an unsigned character.  This is
63    a bit safer than casting to unsigned char, since it catches some type
64    errors that the cast doesn't.  */
65 SYSTEM_INLINE unsigned char
66 to_uchar (char ch)
67 {
68   return ch;
69 }
70
71 _GL_INLINE_HEADER_END
72
73 #ifndef __has_feature
74 # define __has_feature(F) false
75 #endif
76
77 #if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
78 # define HAVE_ASAN 1
79 #else
80 # define HAVE_ASAN 0
81 #endif
82
83 #if HAVE_ASAN
84
85 /* Mark memory region [addr, addr+size) as unaddressable.
86    This memory must be previously allocated by the user program.  Accessing
87    addresses in this region from instrumented code is forbidden until
88    this region is unpoisoned.  This function is not guaranteed to poison
89    the whole region - it may poison only a subregion of [addr, addr+size)
90    due to ASan alignment restrictions.
91    Method is NOT thread-safe in the sense that no two threads can
92    (un)poison memory in the same memory region simultaneously.  */
93 void __asan_poison_memory_region (void const volatile *addr, size_t size);
94
95 /* Mark memory region [addr, addr+size) as addressable.
96    This memory must be previously allocated by the user program.  Accessing
97    addresses in this region is allowed until this region is poisoned again.
98    This function may unpoison a superregion of [addr, addr+size) due to
99    ASan alignment restrictions.
100    Method is NOT thread-safe in the sense that no two threads can
101    (un)poison memory in the same memory region simultaneously.  */
102 void __asan_unpoison_memory_region (void const volatile *addr, size_t size);
103
104 #else
105
106 static _GL_UNUSED void
107 __asan_poison_memory_region (void const volatile *addr, size_t size) { }
108 static _GL_UNUSED void
109 __asan_unpoison_memory_region (void const volatile *addr, size_t size) { }
110 #endif
111
112 #endif