OSDN Git Service

Avoid #include_next misbehaviour; cf. MinGW-Bug [#2330]
[mingw/mingw-org-wsl.git] / mingwrt / include / string.h
1 /*
2  * string.h
3  *
4  * ISO-C standard header, with MSVC compatible extensions.
5  *
6  * $Id$
7  *
8  * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
9  * Copyright (C) 1997-2000, 2002-2004, 2007, 2009, 2015-2017,
10  *  MinGW.org Project.
11  *
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice, this permission notice, and the following
21  * disclaimer shall be included in all copies or substantial portions of
22  * the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  *
32  */
33 #ifndef _STRING_H
34 #pragma GCC system_header
35 #define _STRING_H
36
37 /* All MinGW system headers must include this...
38  */
39 #include <_mingw.h>
40
41 #ifndef RC_INVOKED
42 /* ISO-C requires this header to expose definitions for NULL and size_t,
43  * retaining compatiblity with their fundamental <stddef.h> definitions.
44  */
45 #define __need_NULL
46 #define __need_size_t
47 #ifndef __STRICT_ANSI__
48  /* MSVC extends this requirement to include a definition of wchar_t,
49   * (which contravenes strict ISO-C standards conformity).
50   */
51 # define __need_wchar_t
52 #endif
53 #include <stddef.h>
54
55 #if _EMULATE_GLIBC
56 /* GNU's glibc declares strcasecmp() and strncasecmp() in <string.h>,
57  * contravening POSIX.1-2008 which requires them to be declared only in
58  * <strings.h>; we may emulate this anomalous glibc behaviour, which is
59  * ostensibly to support BSD usage, (in spite of such usage now being
60  * obsolete in BSD), by simply including our <strings.h> here.
61  */
62 #include <strings.h>
63 #endif
64
65 _BEGIN_C_DECLS
66
67 #define __STRING_H_SOURCED__
68 /* Prototypes for the ISO-C Standard library string functions.
69  */
70 _CRTIMP __cdecl __MINGW_NOTHROW  void *memchr (const void *, int, size_t) __MINGW_ATTRIB_PURE;
71 _CRTIMP __cdecl __MINGW_NOTHROW  int memcmp (const void *, const void *, size_t) __MINGW_ATTRIB_PURE;
72 _CRTIMP __cdecl __MINGW_NOTHROW  void *memcpy (void *, const void *, size_t);
73 _CRTIMP __cdecl __MINGW_NOTHROW  void *memmove (void *, const void *, size_t);
74 _CRTIMP __cdecl __MINGW_NOTHROW  void *memset (void *, int, size_t);
75 _CRTIMP __cdecl __MINGW_NOTHROW  char *strcat (char *, const char *);
76 _CRTIMP __cdecl __MINGW_NOTHROW  char *strchr (const char *, int) __MINGW_ATTRIB_PURE;
77 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmp (const char *, const char *) __MINGW_ATTRIB_PURE;
78 _CRTIMP __cdecl __MINGW_NOTHROW  int strcoll (const char *, const char *); /* Compare using locale */
79 _CRTIMP __cdecl __MINGW_NOTHROW  char *strcpy (char *, const char *);
80 _CRTIMP __cdecl __MINGW_NOTHROW  size_t strcspn (const char *, const char *) __MINGW_ATTRIB_PURE;
81 _CRTIMP __cdecl __MINGW_NOTHROW  char *strerror (int); /* NOTE: NOT an old name wrapper. */
82
83 _CRTIMP __cdecl __MINGW_NOTHROW  size_t strlen (const char *) __MINGW_ATTRIB_PURE;
84 _CRTIMP __cdecl __MINGW_NOTHROW  char *strncat (char *, const char *, size_t);
85 _CRTIMP __cdecl __MINGW_NOTHROW  int strncmp (const char *, const char *, size_t) __MINGW_ATTRIB_PURE;
86 _CRTIMP __cdecl __MINGW_NOTHROW  char *strncpy (char *, const char *, size_t);
87 _CRTIMP __cdecl __MINGW_NOTHROW  char *strpbrk (const char *, const char *) __MINGW_ATTRIB_PURE;
88 _CRTIMP __cdecl __MINGW_NOTHROW  char *strrchr (const char *, int) __MINGW_ATTRIB_PURE;
89 _CRTIMP __cdecl __MINGW_NOTHROW  size_t strspn (const char *, const char *) __MINGW_ATTRIB_PURE;
90 _CRTIMP __cdecl __MINGW_NOTHROW  char *strstr (const char *, const char *) __MINGW_ATTRIB_PURE;
91 _CRTIMP __cdecl __MINGW_NOTHROW  char *strtok (char *, const char *);
92 _CRTIMP __cdecl __MINGW_NOTHROW  size_t strxfrm (char *, const char *, size_t);
93
94 #ifndef __STRICT_ANSI__
95 /*
96  * Extra non-ANSI functions provided by the CRTDLL library
97  */
98 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strerror (const char *);
99 _CRTIMP __cdecl __MINGW_NOTHROW  void *_memccpy (void *, const void *, int, size_t);
100 _CRTIMP __cdecl __MINGW_NOTHROW  int _memicmp (const void *, const void *, size_t);
101 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strdup (const char *) __MINGW_ATTRIB_MALLOC;
102 _CRTIMP __cdecl __MINGW_NOTHROW  int _strcmpi (const char *, const char *);
103 _CRTIMP __cdecl __MINGW_NOTHROW  int _stricoll (const char *, const char *);
104 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strlwr (char *);
105 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strnset (char *, int, size_t);
106 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strrev (char *);
107 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strset (char *, int);
108 _CRTIMP __cdecl __MINGW_NOTHROW  char *_strupr (char *);
109 _CRTIMP __cdecl __MINGW_NOTHROW  void _swab (const char *, char *, size_t);
110
111 /* MSVC's non-ANSI _stricmp() and _strnicmp() functions must also be
112  * prototyped here, but we need to share them with <strings.h>, where
113  * we declare their POSIX strcasecmp() and strncasecmp() equivalents;
114  * get the requisite prototypes by selective <strings.h> inclusion,
115  * (noting that we've already done so, if emulating glibc).
116  */
117 #if !_EMULATE_GLIBC
118 #include <strings.h>
119 #endif
120
121 # ifdef __MSVCRT__
122  /* These were not present in the CRTDLL prior to the first release of
123   * MSVCRT.DLL, but are available in all versions of that library.
124   */
125 _CRTIMP __cdecl __MINGW_NOTHROW  int _strncoll(const char *, const char *, size_t);
126 _CRTIMP __cdecl __MINGW_NOTHROW  int _strnicoll(const char *, const char *, size_t);
127 # endif
128
129 # ifndef _NO_OLDNAMES
130  /* Non-underscore decorated versions of non-ANSI functions. They live in the
131   * OLDNAMES libraries, whence they provide a little extra portability.
132   */
133 _CRTIMP __cdecl __MINGW_NOTHROW  void *memccpy (void *, const void *, int, size_t);
134 _CRTIMP __cdecl __MINGW_NOTHROW  int memicmp (const void *, const void *, size_t);
135 _CRTIMP __cdecl __MINGW_NOTHROW  char *strdup (const char *) __MINGW_ATTRIB_MALLOC;
136 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmpi (const char *, const char *);
137 _CRTIMP __cdecl __MINGW_NOTHROW  int stricmp (const char *, const char *);
138 _CRTIMP __cdecl __MINGW_NOTHROW  int stricoll (const char *, const char *);
139 _CRTIMP __cdecl __MINGW_NOTHROW  char *strlwr (char *);
140 _CRTIMP __cdecl __MINGW_NOTHROW  int strnicmp (const char *, const char *, size_t);
141 _CRTIMP __cdecl __MINGW_NOTHROW  char *strnset (char *, int, size_t);
142 _CRTIMP __cdecl __MINGW_NOTHROW  char *strrev (char *);
143 _CRTIMP __cdecl __MINGW_NOTHROW  char *strset (char *, int);
144 _CRTIMP __cdecl __MINGW_NOTHROW  char *strupr (char *);
145
146 #  ifndef _UWIN
147   /* FIXME: Do we really care that UWin doesn't support this?  We are
148    * under no obligation to support UWin.
149    */
150 _CRTIMP __cdecl __MINGW_NOTHROW  void swab (const char *, char *, size_t);
151
152 #  endif /* ! _UWIN */
153 # endif /* ! _NO_OLDNAMES */
154
155 /* MSVC also expects <string.h> to declare duplicates of the wchar_t
156  * string functions which are nominally declared in <wchar.h>, (which
157  * is where ISO-C specifies that they should be declared).  For the
158  * convenience of applications which rely on this Microsoft anomaly,
159  * inclusion of <wchar.h>, within the current __STRING_H_SOURCED__
160  * scope, will selectively expose the required function prototypes;
161  * however, strictly ISO-C conforming applications should include
162  * <wchar.h> directly; they should not rely on this MSVC specific
163  * anomalous behaviour.  (We use the quoted form of inclusion here,
164  * to ensure that we get our own "wchar.h", and not any predecessor
165  * which may have been insinuated into the system include path, and
166  * so could interfere with our mechanism for partial inclusion of
167  * shared header content).
168  */
169 #include "wchar.h"
170
171 #endif /* ! __STRICT_ANSI__ */
172
173 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL
174 /* MSVCR80.DLL adds a (mostly) POSIX.1-2008 conforming strnlen(); (it's
175  * also available in MSVCRT.DLL from _WIN32_WINNT_VISTA onwards, but we
176  * pretend otherwise, since recent GCC will try to use the function when
177  * it can be found in libmsvcrt.a, so breaking it for use on WinXP and
178  * earlier).
179  */
180 _CRTIMP __cdecl __MINGW_NOTHROW  char *strnlen (const char *, size_t);
181
182 #elif _POSIX_C_SOURCE >= 200809L
183 /* Emulation, to support recent POSIX.1; we prefer this for ALL versions
184  * of MSVCRT.DLL, (even those which already provide strnlen()); to avoid
185  * the GCC breakage noted above.  (Note that we implement strnlen() with
186  * the alternative external name, __mingw_strnlen() in libmingwex.a, to
187  * avoid possible link time collision with MSVCR80.DLL's implementation,
188  * then map this to strnlen() via a __CRT_ALIAS, with stubs designated
189  * for linking from within the appropriate oldname libraries.
190  */
191 extern size_t __mingw_strnlen (const char *, size_t);
192
193 __JMPSTUB__(( LIB=coldname; FUNCTION=strnlen ))
194 __CRT_ALIAS size_t strnlen (const char *__text, size_t __maxlen)
195 { return __mingw_strnlen (__text, __maxlen); }
196
197 #endif  /* _POSIX_C_SOURCE >= 200809L */
198
199 #undef __STRING_H_SOURCED__
200
201 _END_C_DECLS
202
203 #endif  /* ! RC_INVOKED */
204 #endif  /* !_STRING_H: $RCSfile$: end of file */