1/* -*- Mode: C -*-  */
2
3autogen definitions fixincl;
4
5/* Define all the fixes we know about for repairing damaged headers.
6   Please see the README before adding or changing entries in this file.
7
8   This is the sort command:
9
10   blocksort output=inclhack.sorted \
11          pattern='^/\*$' \
12          trailer='^/\*EOF\*[/]' \
13          input=inclhack.def \
14          key=$'hackname[ \t]*=[ \t]*(.*);'
15
16   Set up a debug test so we can make the templates emit special
17   code while debugging these fixes:  */
18
19#ifdef DEBUG
20FIXINC_DEBUG = yes;
21#endif
22
23/* On AIX when _LARGE_FILES is defined stdio.h defines fopen to
24 * fopen64 etc. and this causes problems when building with g++
25 * because cstdio udefs everything from stdio.h, leaving us with
26 * ::fopen has not been declared errors. This fixes stdio.h to
27 * undef those defines and use __asm__ to alias the symbols if
28 * building with g++ and -D_LARGE_FILES
29 */
30fix = {
31    hackname  = AAB_aix_stdio;
32    files     = stdio.h;
33    select    = "define fopen fopen64";
34    mach      = "*-*-aix*";
35    test-text = ''; /* no way to test */
36
37    c_fix     = wrap;
38
39    c_fix_arg = "";
40
41    c_fix_arg = <<- _EOArg_
42
43	#if defined __GNUG__ && defined _LARGE_FILES && defined __cplusplus
44	#define __need__aix_stdio_h_fix
45	#ifdef __need__aix_stdio_h_fix
46	#undef fseeko
47	#undef ftello
48	#undef fgetpos
49	#undef fsetpos
50	#undef fopen
51	#undef freopen
52	/* Alias the symbols using asm */
53	extern "C" {
54	extern int fgetpos(FILE *, fpos64_t *) __asm__("fgetpos64");
55	extern FILE *fopen(const char *, const char *) __asm__("fopen64");
56	extern FILE *freopen(const char *, const char *, FILE *) __asm__("freopen64");
57	extern int fseeko(FILE *, off64_t, int) __asm__("fseeko64");
58	extern int fsetpos(FILE *, const fpos64_t *) __asm__("fsetpos64");
59	extern off64_t ftello(FILE *) __asm__("ftello64");
60	}
61	#endif
62	#endif
63
64	_EOArg_;
65};
66
67/* On AIX when _LARGE_FILES is defined fcntl.h defines open to
68 * open64 and creat to creat64.  This fixes fcntl.h to
69 * undef those defines and use __asm__ to alias the symbols if
70 * building with g++ and -D_LARGE_FILES
71 */
72fix = {
73    hackname  = AAB_aix_fcntl;
74    files     = fcntl.h;
75    select    = "define open[ \t]open64";
76    mach      = "*-*-aix*";
77    test-text = ''; /* no way to test */
78
79    c_fix     = wrap;
80
81    c_fix_arg = "";
82
83    c_fix_arg = <<- _EOArg_
84
85	#if defined __GNUG__ && defined _LARGE_FILES && defined __cplusplus
86	#define __need__aix_fcntl_h_fix
87	#ifdef __need__aix_fcntl_h_fix
88	#undef open
89	#undef creat
90	#undef openat
91	/* Alias the symbols using asm */
92	extern "C" {
93	extern int open(const char *, int, ...) __asm__("open64");
94	extern int creat(const char *, mode_t) __asm__("creat64");
95	#if (_XOPEN_SOURCE >= 700)
96	extern int openat(int, const char *, int, ...) __asm__("open64at");
97	#endif
98	}
99	#endif
100	#endif
101
102	_EOArg_;
103};
104
105/*
106 *  On Mac OS 10.3.9, the 'long double' functions are available in
107 *  libSystem, but are not prototyped in math.h.
108 */
109fix = {
110  hackname  = AAB_darwin7_9_long_double_funcs;
111  mach      = "*-*-darwin7.9*";
112  files     = architecture/ppc/math.h;
113  bypass    = "powl";
114  replace = <<- _EndOfHeader_
115	/* This file prototypes the long double functions available on Mac OS
116	   10.3.9.  */
117	#ifndef __MATH__
118	# undef __APPLE_CC__
119	# define __APPLE_CC__  1345
120	# include_next <architecture/ppc/math.h>
121	# undef __APPLE_CC__
122	# define __APPLE_CC__ 1
123	# ifndef __LIBMLDBL_COMPAT
124	#  ifdef __LONG_DOUBLE_128__
125	#   define __LIBMLDBL_COMPAT(sym) __asm("_" #sym "$LDBL128")
126	#  else
127	#   define __LIBMLDBL_COMPAT(sym)
128	#  endif /* __LONG_DOUBLE_128__ */
129	# endif /* __LIBMLDBL_COMPAT */
130	# ifdef __cplusplus
131	   extern "C" {
132	# endif
133	  extern long double acosl( long double ) __LIBMLDBL_COMPAT(acosl);
134	  extern long double asinl( long double ) __LIBMLDBL_COMPAT(asinl);
135	  extern long double atanl( long double ) __LIBMLDBL_COMPAT(atanl);
136	  extern long double atan2l( long double, long double ) __LIBMLDBL_COMPAT(atan2l);
137	  extern long double cosl( long double ) __LIBMLDBL_COMPAT(cosl);
138	  extern long double sinl( long double ) __LIBMLDBL_COMPAT(sinl);
139	  extern long double tanl( long double ) __LIBMLDBL_COMPAT(tanl);
140	  extern long double acoshl( long double ) __LIBMLDBL_COMPAT(acoshl);
141	  extern long double asinhl( long double ) __LIBMLDBL_COMPAT(asinhl);
142	  extern long double atanhl( long double ) __LIBMLDBL_COMPAT(atanhl);
143	  extern long double coshl( long double ) __LIBMLDBL_COMPAT(coshl);
144	  extern long double sinhl( long double ) __LIBMLDBL_COMPAT(sinhl);
145	  extern long double tanhl( long double ) __LIBMLDBL_COMPAT(tanhl);
146	  extern long double expl( long double ) __LIBMLDBL_COMPAT(expl);
147	  extern long double exp2l( long double ) __LIBMLDBL_COMPAT(exp2l);
148	  extern long double expm1l( long double ) __LIBMLDBL_COMPAT(expm1l);
149	  extern long double logl( long double ) __LIBMLDBL_COMPAT(logl);
150	  extern long double log10l( long double ) __LIBMLDBL_COMPAT(log10l);
151	  extern long double log2l( long double ) __LIBMLDBL_COMPAT(log2l);
152	  extern long double log1pl( long double ) __LIBMLDBL_COMPAT(log1pl);
153	  extern long double logbl( long double ) __LIBMLDBL_COMPAT(logbl);
154	  extern long double modfl( long double, long double * ) __LIBMLDBL_COMPAT(modfl);
155	  extern long double ldexpl( long double, int ) __LIBMLDBL_COMPAT(ldexpl);
156	  extern long double frexpl( long double, int * ) __LIBMLDBL_COMPAT(frexpl);
157	  extern int ilogbl( long double ) __LIBMLDBL_COMPAT(ilogbl);
158	  extern long double scalbnl( long double, int ) __LIBMLDBL_COMPAT(scalbnl);
159	  extern long double scalblnl( long double, long int ) __LIBMLDBL_COMPAT(scalblnl);
160	  extern long double fabsl( long double ) __LIBMLDBL_COMPAT(fabsl);
161	  extern long double cbrtl( long double ) __LIBMLDBL_COMPAT(cbrtl);
162	  extern long double hypotl( long double, long double ) __LIBMLDBL_COMPAT(hypotl);
163	  extern long double powl( long double, long double ) __LIBMLDBL_COMPAT(powl);
164	  extern long double sqrtl( long double ) __LIBMLDBL_COMPAT(sqrtl);
165	  extern long double erfl( long double ) __LIBMLDBL_COMPAT(erfl);
166	  extern long double erfcl( long double ) __LIBMLDBL_COMPAT(erfcl);
167	  extern long double lgammal( long double ) __LIBMLDBL_COMPAT(lgammal);
168	  extern long double tgammal( long double ) __LIBMLDBL_COMPAT(tgammal);
169	  extern long double ceill( long double ) __LIBMLDBL_COMPAT(ceill);
170	  extern long double floorl( long double ) __LIBMLDBL_COMPAT(floorl);
171	  extern long double nearbyintl( long double ) __LIBMLDBL_COMPAT(nearbyintl);
172	  extern long double rintl( long double ) __LIBMLDBL_COMPAT(rintl);
173	  extern long int lrintl( long double ) __LIBMLDBL_COMPAT(lrintl);
174	  extern long long int llrintl( long double ) __LIBMLDBL_COMPAT(llrintl);
175	  extern long double roundl( long double ) __LIBMLDBL_COMPAT(roundl);
176	  extern long int lroundl( long double ) __LIBMLDBL_COMPAT(lroundl);
177	  extern long long int llroundl( long double ) __LIBMLDBL_COMPAT(llroundl);
178	  extern long double truncl( long double ) __LIBMLDBL_COMPAT(truncl);
179	  extern long double fmodl( long double, long double) __LIBMLDBL_COMPAT(fmodl);
180	  extern long double remainderl( long double, long double ) __LIBMLDBL_COMPAT(remainderl);
181	  extern long double remquol( long double, long double, int * ) __LIBMLDBL_COMPAT(remquol);
182	  extern long double copysignl( long double, long double ) __LIBMLDBL_COMPAT(copysignl);
183	  extern long double nanl( const char * ) __LIBMLDBL_COMPAT(nanl);
184	  extern long double nextafterl( long double, long double ) __LIBMLDBL_COMPAT(nextafterl);
185	  extern long double nexttowardl( long double, long double ) __LIBMLDBL_COMPAT(nexttowardl);
186	  extern long double fdiml( long double, long double ) __LIBMLDBL_COMPAT(fdiml);
187	  extern long double fmaxl( long double, long double ) __LIBMLDBL_COMPAT(fmaxl);
188	  extern long double fminl( long double, long double ) __LIBMLDBL_COMPAT(fminl);
189	  extern long double fmal( long double, long double, long double ) __LIBMLDBL_COMPAT(fmal);
190	# ifdef __cplusplus
191	   }
192	# endif
193	#endif /* __MATH__ */
194	_EndOfHeader_;
195};
196
197/*
198 *  This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n)
199 */
200fix = {
201    hackname = AAB_fd_zero_asm_posix_types_h;
202    files    = asm/posix_types.h;
203    mach     = 'i[34567]86-*-linux*';
204    bypass   = '} while';
205    bypass   = 'x86_64';
206    bypass   = 'posix_types_64';
207
208    /*
209     * Define _POSIX_TYPES_H_WRAPPER at the end of the wrapper, not
210     * the start, so that if #include_next gets another instance of
211     * the wrapper, this will follow the #include_next chain until
212     * we arrive at the real <asm/posix_types.h>.
213     */
214    replace  = <<-  _EndOfHeader_
215	/* This file fixes a bug in the __FD_ZERO macro
216	   for older versions of the Linux kernel. */
217	#ifndef _POSIX_TYPES_H_WRAPPER
218	#include <features.h>
219	 #include_next <asm/posix_types.h>
220
221	#if defined(__FD_ZERO) && !defined(__GLIBC__)
222	#undef __FD_ZERO
223	#define __FD_ZERO(fdsetp) \
224	  do { \
225	    int __d0, __d1; \
226		__asm__ __volatile__("cld ; rep ; stosl" \
227			: "=&c" (__d0), "=&D" (__d1) \
228			: "a" (0), "0" (__FDSET_LONGS), \
229			  "1" ((__kernel_fd_set *) (fdsetp)) :"memory"); \
230	  } while (0)
231	#endif
232
233	#define _POSIX_TYPES_H_WRAPPER
234	#endif /* _POSIX_TYPES_H_WRAPPER */
235	_EndOfHeader_;
236};
237
238/*
239 *  This fixes __FD_ZERO bug for glibc-1.x
240 */
241fix = {
242    hackname = AAB_fd_zero_gnu_types_h;
243    files    = gnu/types.h;
244    mach     = 'i[34567]86-*-linux*';
245
246    /*
247     * Define _TYPES_H_WRAPPER at the end of the wrapper, not
248     * the start, so that if #include_next gets another instance of
249     * the wrapper, this will follow the #include_next chain until
250     * we arrive at the real <gnu/types.h>.
251     */
252    replace  = <<-  _EndOfHeader_
253	/* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */
254	#ifndef _TYPES_H_WRAPPER
255	#include <features.h>
256	#include_next <gnu/types.h>
257
258	#if defined(__FD_ZERO) && !defined(__GLIBC__)
259	#undef __FD_ZERO
260	# define __FD_ZERO(fdsetp) \
261	  do { \
262	    int __d0, __d1; \
263	        __asm__ __volatile__("cld ; rep ; stosl" \
264	        : "=&c" (__d0), "=&D" (__d1) \
265	        : "a" (0), "0" (__FDSET_LONGS), \
266	          "1" ((__fd_set *) (fdsetp)) :"memory"); \
267	  } while (0)
268	#endif
269
270	#define _TYPES_H_WRAPPER
271	#endif /* _TYPES_H_WRAPPER */
272	_EndOfHeader_;
273};
274
275/*
276 *  This fixes __FD_ZERO bug for glibc-2.0.x
277 */
278fix = {
279    hackname = AAB_fd_zero_selectbits_h;
280    files    = selectbits.h;
281    mach     = 'i[34567]86-*-linux*';
282
283    /*
284     * Define _SELECTBITS_H_WRAPPER at the end of the wrapper, not
285     * the start, so that if #include_next gets another instance of
286     * the wrapper, this will follow the #include_next chain until
287     * we arrive at the real <selectbits.h>.
288     */
289    replace  = <<-  _EndOfHeader_
290	/* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */
291	#ifndef _SELECTBITS_H_WRAPPER
292	  #include <features.h>
293	  #include_next <selectbits.h>
294
295	  #if defined(__FD_ZERO) && defined(__GLIBC__) \\
296	  && defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\
297	  && __GLIBC_MINOR__ == 0
298	     #undef __FD_ZERO
299	     #define __FD_ZERO(fdsetp) \\
300	     do { \\
301	        int __d0, __d1; \\
302	      __asm__ __volatile__ ("cld; rep; stosl" \\
303                        : "=&c" (__d0), "=&D" (__d1) \\
304                        : "a" (0), "0" (sizeof (__fd_set) \\
305                                        / sizeof (__fd_mask)), \\
306                          "1" ((__fd_mask *) (fdsetp)) \\
307                        : "memory"); \\
308	      } while (0)
309	  #endif
310
311	  #define _SELECTBITS_H_WRAPPER
312	#endif /* _SELECTBITS_H_WRAPPER */
313	_EndOfHeader_;
314};
315
316/*
317 * Solaris <sys/varargs.h> is a DDK (aka kernel-land) header providing
318 * the same interface as <stdarg.h>.  No idea why they couldn't have just
319 * used the standard header.
320 */
321fix = {
322    hackname = AAB_solaris_sys_varargs_h;
323    files    = "sys/varargs.h";
324    mach     = '*-*-solaris*';
325    replace  = <<-  _EndOfHeader_
326	#ifdef __STDC__
327	  #include <stdarg.h>
328	#else
329	  #include <varargs.h>
330	#endif
331	_EndOfHeader_;
332};
333
334/*
335 *  Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
336 *  declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
337 *  many other systems have similar text but correct versions of the file.
338 *  To ensure only Sun's is fixed, we grep for a likely unique string.
339 *  Fix also on sysV68 R3V7.1 (head/memory.h\t50.1\t )
340 */
341fix = {
342    hackname = AAB_sun_memcpy;
343    files    = memory.h;
344    select   = "/\\*\t@\\(#\\)"
345             "(head/memory.h\t50.1\t "
346             "|memory\\.h 1\\.[2-4] 8./../.. SMI; from S5R2 1\\.2\t)\\*/";
347
348    replace = <<-  _EndOfHeader_
349	/* This file was generated by fixincludes */
350	#ifndef __memory_h__
351	  #define __memory_h__
352
353	  #ifdef __STDC__
354	    extern void *memccpy();
355	    extern void *memchr();
356	    extern void *memcpy();
357	    extern void *memset();
358	  #else
359	    extern char *memccpy();
360	    extern char *memchr();
361	    extern char *memcpy();
362	    extern char *memset();
363	  #endif /* __STDC__ */
364
365	  extern int memcmp();
366
367	#endif /* __memory_h__ */
368	_EndOfHeader_;
369};
370
371/*
372 * Fix assert.h on VxWorks:
373 */
374fix = {
375    hackname    = AAB_vxworks_assert;
376    files       = assert.h;
377    mach        = "*-*-vxworks*";
378
379    replace     = <<- _EndOfHeader_
380	#ifndef _ASSERT_H
381	#define _ASSERT_H
382
383	#ifdef assert
384	#undef assert
385	#endif
386
387	#if defined(__STDC__) || defined(__cplusplus)
388	extern void __assert (const char*);
389	#else
390	extern void __assert ();
391	#endif
392
393	#ifdef NDEBUG
394	#define assert(ign) ((void)0)
395	#else
396
397	#define ASSERT_STRINGIFY(str) ASSERT_STRINGIFY_HELPER(str)
398	#define ASSERT_STRINGIFY_HELPER(str) #str
399
400	#define assert(test) ((void) \
401	        ((test) ? ((void)0) : \
402	        __assert("Assertion failed: " ASSERT_STRINGIFY(test) ", file " \
403	        __FILE__ ", line " ASSERT_STRINGIFY(__LINE__) "\n")))
404
405	#endif
406
407	#endif
408	_EndOfHeader_;
409};
410
411/*
412 * Add needed include to regs.h (NOT the gcc header) on VxWorks
413 */
414
415fix = {
416    hackname    = AAB_vxworks_regs_vxtypes;
417    files       = regs.h;
418    mach        = "*-*-vxworks*";
419
420    replace     = <<- _EndOfHeader_
421	#ifndef _REGS_H
422	#define _REGS_H
423	#include <types/vxTypesOld.h>
424	#include_next <arch/../regs.h>
425	#endif
426	_EndOfHeader_;
427};
428
429/*
430 * Make VxWorks stdint.h a bit more compliant - add typedefs
431 */
432fix = {
433    hackname    = AAB_vxworks_stdint;
434    files       = stdint.h;
435    mach        = "*-*-vxworks*";
436
437    replace     = <<- _EndOfHeader_
438	#ifndef _STDINT_H
439	#define _STDINT_H
440	/* get int*_t, uint*_t */
441	#include <types/vxTypes.h>
442
443	/* get legacy vxworks types for compatibility */
444	#include <types/vxTypesOld.h>
445
446	typedef long intptr_t;
447	typedef unsigned long uintptr_t;
448
449	typedef int64_t intmax_t;
450	typedef uint64_t uintmax_t;
451
452	typedef int8_t int_least8_t;
453	typedef int16_t int_least16_t;
454	typedef int32_t int_least32_t;
455	typedef int64_t int_least64_t;
456
457	typedef uint8_t uint_least8_t;
458	typedef uint16_t uint_least16_t;
459	typedef uint32_t uint_least32_t;
460	typedef uint64_t uint_least64_t;
461
462	typedef int8_t int_fast8_t;
463	typedef int int_fast16_t;
464	typedef int32_t int_fast32_t;
465	typedef int64_t int_fast64_t;
466
467	typedef uint8_t uint_fast8_t;
468	typedef unsigned int uint_fast16_t;
469	typedef uint32_t uint_fast32_t;
470	typedef uint64_t uint_fast64_t;
471
472	/* Ranges */
473	#define UINT8_MAX (~(uint8_t)0)
474	#define UINT8_MIN 0
475	#define UINT16_MAX (~(uint16_t)0)
476	#define UINT16_MIN 0
477	#define UINT32_MAX (~(uint32_t)0)
478	#define UINT32_MIN 0
479	#define UINT64_MAX (~(uint64_t)0)
480	#define UINT64_MIN 0
481
482	#define UINTPTR_MAX (~(uintptr_t)0)
483	#define UINTPTR_MIN 0
484
485	/* Need to do int_fast16_t as well, as type
486	   size may be architecture dependent */
487	#define UINT_FAST16_MAX (~(uint_fast16_t)0)
488	#define UINT_FAST16_MAX 0
489
490	#define INT8_MAX (UINT8_MAX>>1)
491	#define INT8_MIN (INT8_MAX+1)
492	#define INT16_MAX (UINT16_MAX>>1)
493	#define INT16_MIN (INT16_MAX+1)
494	#define INT32_MAX (UINT32_MAX>>1)
495	#define INT32_MIN (INT32_MAX+1)
496	#define INT64_MAX (UINT64_MAX>>1)
497	#define INT64_MIN (INT64_MAX+1)
498
499	#define INTPTR_MAX (UINTPTR_MAX>>1)
500	#define INTPTR_MIN (INTPTR_MAX+1)
501
502	#define INT_FAST16_MAX (UINT_FAST16_MAX>>1)
503	#define INT_FAST16_MIN (INT_FAST16_MAX+1)
504
505	/* now define equiv. constants */
506	#define UINT_FAST8_MAX UINT8_MAX
507	#define UINT_FAST8_MIN UINT_FAST8_MIN
508	#define INT_FAST8_MAX INT8_MAX
509	#define INT_FAST8_MIN INT8_MIN
510	#define UINT_FAST32_MAX UINT32_MAX
511	#define UINT_FAST32_MIN UINT32_MIN
512	#define INT_FAST32_MAX INT32_MAX
513	#define INT_FAST32_MIN INT32_MIN
514	#define UINT_FAST64_MAX UINT64_MAX
515	#define UINT_FAST64_MIN UINT64_MIN
516	#define INT_FAST64_MAX INT64_MAX
517	#define INT_FAST64_MIN INT64_MIN
518
519	#define UINT_LEAST8_MAX UINT8_MAX
520	#define UINT_LEAST8_MIN UINT8_MIN
521	#define INT_LEAST8_MAX INT8_MAX
522	#define INT_LEAST8_MIN INT8_MIN
523	#define UINT_LEAST16_MAX UINT16_MAX
524	#define UINT_LEAST16_MIN UINT16_MIN
525	#define INT_LEAST16_MAX INT16_MAX
526	#define INT_LEAST16_MIN INT16_MIN
527	#define UINT_LEAST32_MAX UINT32_MAX
528	#define UINT_LEAST32_MIN UINT32_MIN
529	#define INT_LEAST32_MAX INT32_MAX
530	#define INT_LEAST32_MIN INT32_MIN
531	#define UINT_LEAST64_MAX UINT64_MAX
532	#define UINT_LEAST64_MIN UINT64_MIN
533	#define INT_LEAST64_MAX INT64_MAX
534	#define INT_LEAST64_MIN INT64_MIN
535
536	#define UINTMAX_MAX UINT64_MAX
537	#define UINTMAX_MIN UINT64_MIN
538	#define INTMAX_MAX INT64_MAX
539	#define INTMAX_MIN INT64_MIN
540
541	#endif
542	_EndOfHeader_;
543};
544
545/*
546 *  This hack makes makes unistd.h more POSIX-compliant on VxWorks
547 */
548fix = {
549    hackname    = AAB_vxworks_unistd;
550    files       = unistd.h;
551    mach        = "*-*-vxworks*";
552
553    replace     = <<- _EndOfHeader_
554	#ifndef _UNISTD_H
555	#define _UNISTD_H
556	#include_next <unistd.h>
557	#include <ioLib.h>
558	#ifndef STDIN_FILENO
559	#define STDIN_FILENO 0
560	#endif
561	#ifndef STDOUT_FILENO
562	#define STDOUT_FILENO 1
563	#endif
564	#ifndef STDERR_FILENO
565	#define STDERR_FILENO 2
566	#endif
567	#endif /* _UNISTD_H */
568	_EndOfHeader_;
569};
570
571/*
572 * assert.h on AIX 7 redefines static_assert as _Static_assert without
573 * protecting C++.
574 */
575fix = {
576    hackname  = aix_assert;
577    mach      = "*-*-aix*";
578    files     = assert.h;
579    select    = "#define[ \t]static_assert[ \t]_Static_assert";
580    c_fix     = format;
581    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
582    test_text = "#define static_assert _Static_assert";
583};
584
585/*
586 * complex.h on AIX 5 and AIX 6 define _Complex_I and I in terms of __I,
587 * which only is provided by AIX xlc C99.
588 */
589fix = {
590    hackname  = aix_complex;
591    mach      = "*-*-aix*";
592    files     = complex.h;
593    select    = "#define[ \t]_Complex_I[ \t]__I";
594    c_fix     = format;
595    c_fix_arg = "#define _Complex_I (__extension__ 1.0iF)";
596    test_text = "#define _Complex_I	__I\n";
597};
598
599/*
600 *  malloc.h on AIX6 uses XLC++ specific builtin syntax
601 */
602fix = {
603    hackname  = aix_malloc;
604    mach      = "*-*-aix*";
605    files     = "malloc.h";
606    select    = "#ifdef __cplusplus";
607    c_fix     = format;
608    c_fix_arg = "#if (defined(__cplusplus) && defined(__IBMCPP__))";
609    test_text = "#ifdef __cplusplus";
610};
611
612/*
613 * net/if_arp.h defines a variable fc_softc instead of adding a
614 * typedef for the struct on AIX 5.2, 5.3, 6.1 and 7.1
615 */
616fix = {
617    hackname  = aix_net_if_arp;
618    mach      = "*-*-aix*";
619    files     = "net/if_arp.h";
620    select    = "^struct  fc_softc \\{";
621    c_fix     = format;
622    c_fix_arg = "typedef struct _fc_softc {";
623    test_text = "struct  fc_softc {\n  int a;\n};";
624};
625
626/*
627 *  Fix AIX definition of NULL for G++.
628 */
629fix = {
630    hackname  = aix_null;
631    mach      = "*-*-aix*";
632    files     = curses.h, dbm.h, locale.h, stdio.h, stdlib.h, string.h,
633    time.h, unistd.h, wchar.h, sys/dir.h, sys/param.h, sys/types.h;
634    bypass    = __null;
635    select    = "#define[ \t]+NULL[ \t]+\\(*0L*\\)*";
636    c_fix     = format;
637    c_fix_arg = <<- _EOFix_
638	#ifndef NULL
639	#ifdef __cplusplus
640	#ifdef __GNUG__
641	#define NULL __null
642	#else /* ! __GNUG__  */
643	#define NULL 0L
644	#endif /* __GNUG__  */
645	#else /* ! __cplusplus  */
646	#define NULL ((void *)0)
647	#endif /* __cplusplus  */
648	#endif /* !NULL  */
649	_EOFix_;
650    test_text = "# define\tNULL \t(0L)  /* typed NULL */";
651};
652
653/*
654 *  pthread.h on AIX defines PTHREAD_ONCE_INIT, PTHREAD_MUTEX_INITIALIZER,
655 *  PTHREAD_COND_INITIALIZER and PTHREAD_RWLOCK_INITIALIZER without enough
656 *  braces.
657 */
658fix = {
659    hackname  = aix_once_init_1;
660    mach      = "*-*-aix*";
661    files     = "pthread.h";
662    select    = "#define[ \t]PTHREAD_ONCE_INIT \\\\\n"
663		"\\{ \\\\\n";
664    c_fix     = format;
665    c_fix_arg = "#define PTHREAD_ONCE_INIT \\\n"
666		"{{ \\\n";
667    test_text = "#define PTHREAD_ONCE_INIT \\\\\n"
668		"{ \\\\\n";
669};
670
671fix = {
672    hackname  = aix_once_init_2;
673    mach      = "*-*-aix*";
674    files     = "pthread.h";
675    select    = "[ \t]0 \\\\\n"
676		"\\}\n";
677    c_fix     = format;
678    c_fix_arg = "	0 \\\n"
679		"}}\n";
680    test_text = "	0 \\\\\n"
681		"}\n";
682};
683
684fix = {
685    hackname  = aix_mutex_initializer_1;
686    mach      = "*-*-aix*";
687    files     = "pthread.h";
688    select    = "#define[ \t]PTHREAD_MUTEX_INITIALIZER \\\\\n"
689		"\\{ \\\\\n";
690    c_fix     = format;
691    c_fix_arg = "#define PTHREAD_MUTEX_INITIALIZER \\\n"
692		"{{ \\\n";
693    test_text = "#define PTHREAD_MUTEX_INITIALIZER \\\\\n"
694		"{ \\\\\n";
695};
696
697fix = {
698    hackname  = aix_cond_initializer_1;
699    mach      = "*-*-aix*";
700    files     = "pthread.h";
701    select    = "#define[ \t]PTHREAD_COND_INITIALIZER \\\\\n"
702		"\\{ \\\\\n";
703    c_fix     = format;
704    c_fix_arg = "#define PTHREAD_COND_INITIALIZER \\\n"
705		"{{ \\\n";
706    test_text = "#define PTHREAD_COND_INITIALIZER \\\\\n"
707		"{ \\\\\n";
708};
709
710fix = {
711    hackname  = aix_rwlock_initializer_1;
712    mach      = "*-*-aix*";
713    files     = "pthread.h";
714    select    = "#define[ \t]PTHREAD_RWLOCK_INITIALIZER \\\\\n"
715		"\\{ \\\\\n";
716    c_fix     = format;
717    c_fix_arg = "#define PTHREAD_RWLOCK_INITIALIZER \\\n"
718		"{{ \\\n";
719    test_text = "#define PTHREAD_RWLOCK_INITIALIZER \\\\\n"
720		"{ \\\\\n";
721};
722
723/*
724 *  pthread.h on AIX 4.3.3 tries to define a macro without whitspace
725 *  which violates a requirement of ISO C.
726 */
727fix = {
728    hackname  = aix_pthread;
729    files     = "pthread.h";
730    select    = "(#define [A-Za-z_0-9]+)(\\\\\n[^A-Za-z_0-9 \t\n(])";
731    c_fix     = format;
732    c_fix_arg = "%1 %2";
733    test_text = "#define PTHREAD_MUTEX_INITIALIZER\\\\\n"
734                "{...init stuff...}";
735};
736
737/*
738 *  AIX stdint.h fixes.
739 */
740fix = {
741    hackname  = aix_stdint_1;
742    mach      = "*-*-aix*";
743    files     = stdint-aix.h, stdint.h;
744    select    = "#define[ \t]UINT8_MAX[ \t]\\(255U\\)\n"
745		"#define[ \t]UINT16_MAX[ \t]\\(65535U\\)";
746    c_fix     = format;
747    c_fix_arg = "#define UINT8_MAX	(255)\n"
748		"#define UINT16_MAX	(65535)";
749    test_text = "#define UINT8_MAX	(255U)\n"
750		"#define UINT16_MAX	(65535U)";
751};
752
753/*
754 * aix_stdint_2
755 */
756fix = {
757    hackname  = aix_stdint_2;
758    mach      = "*-*-aix*";
759    files     = stdint-aix.h, stdint.h;
760    select    = "#define[ \t]INTPTR_MIN[ \t]INT64_MIN\n"
761		"#define[ \t]INTPTR_MAX[ \t]INT64_MAX\n"
762		"#define[ \t]UINTPTR_MAX[ \t]UINT64_MAX\n"
763		"#else\n"
764		"#define[ \t]INTPTR_MIN[ \t]INT32_MIN\n"
765		"#define[ \t]INTPTR_MAX[ \t]INT32_MAX\n"
766		"#define[ \t]UINTPTR_MAX[ \t]UINT32_MAX";
767    c_fix     = format;
768    c_fix_arg = "#define INTPTR_MIN	(-INTPTR_MAX-1)\n"
769		"#define INTPTR_MAX	9223372036854775807L\n"
770		"#define UINTPTR_MAX	18446744073709551615UL\n"
771		"#else\n"
772		"#define INTPTR_MIN	(-INTPTR_MAX-1)\n"
773		"#define INTPTR_MAX	2147483647L\n"
774		"#define UINTPTR_MAX	4294967295UL";
775    test_text = "#define INTPTR_MIN	INT64_MIN\n"
776		"#define INTPTR_MAX	INT64_MAX\n"
777		"#define UINTPTR_MAX	UINT64_MAX\n"
778		"#else\n"
779		"#define INTPTR_MIN	INT32_MIN\n"
780		"#define INTPTR_MAX	INT32_MAX\n"
781		"#define UINTPTR_MAX	UINT32_MAX";
782};
783
784/*
785 * aix_stdint_3
786 */
787fix = {
788    hackname  = aix_stdint_3;
789    mach      = "*-*-aix*";
790    files     = stdint-aix.h, stdint.h;
791    select    = "#define[ \t]PTRDIFF_MIN[ \t]INT64_MIN\n"
792		"#define[ \t]PTRDIFF_MAX[ \t]INT64_MAX\n"
793		"#else\n"
794		"#define[ \t]PTRDIFF_MIN[ \t]*INT32_MIN\n"
795		"#define[ \t]PTRDIFF_MAX[ \t]*INT32_MAX";
796    c_fix     = format;
797    c_fix_arg = "#define PTRDIFF_MIN	(-9223372036854775807L - 1)\n"
798		"#define PTRDIFF_MAX	9223372036854775807L\n"
799		"#else\n"
800		"#define PTRDIFF_MIN	(-2147483647L - 1)\n"
801		"#define PTRDIFF_MAX	2147483647L";
802    test_text = "#define PTRDIFF_MIN	INT64_MIN\n"
803		"#define PTRDIFF_MAX	INT64_MAX\n"
804		"#else\n"
805		"#define PTRDIFF_MIN     INT32_MIN\n"
806		"#define PTRDIFF_MAX	INT32_MAX";
807};
808
809/*
810 * aix_stdint_4
811 */
812fix = {
813    hackname  = aix_stdint_4;
814    mach      = "*-*-aix*";
815    files     = stdint-aix.h, stdint.h;
816    select    = "#define[ \t]SIZE_MAX[ \t]UINT64_MAX\n"
817		"#else\n"
818		"#define[ \t]SIZE_MAX[ \t]*UINT32_MAX";
819    c_fix     = format;
820    c_fix_arg = "#define SIZE_MAX	18446744073709551615UL\n"
821		"#else\n"
822		"#define SIZE_MAX	4294967295UL";
823    test_text = "#define SIZE_MAX	UINT64_MAX\n"
824		"#else\n"
825		"#define SIZE_MAX        UINT32_MAX";
826};
827
828/*
829 * aix_stdint_5
830 */
831fix = {
832    hackname  = aix_stdint_5;
833    mach      = "*-*-aix*";
834    files     = stdint-aix.h, stdint.h;
835    select    = "#define[ \t]UINT8_C\\(c\\)[ \t]__CONCAT__\\(c,U\\)\n"
836		"#define[ \t]UINT16_C\\(c\\)[ \t]__CONCAT__\\(c,U\\)";
837    c_fix     = format;
838    c_fix_arg = "#define UINT8_C(c)	c\n"
839		"#define UINT16_C(c)	c";
840    test_text = "#define UINT8_C(c)	__CONCAT__(c,U)\n"
841		"#define UINT16_C(c)	__CONCAT__(c,U)";
842};
843
844/*
845 *  sys/machine.h on AIX 4.3.3 puts whitespace between a \ and a newline
846 *  in an otherwise harmless (and #ifed out) macro definition
847 */
848fix = {
849    hackname  = aix_sysmachine;
850    files     = sys/machine.h;
851    select    = "\\\\ +\n";
852    c_fix     = format;
853    c_fix_arg = "\\\n";
854    test_text = "#define FOO \\\n"
855    " bar \\ \n baz \\ \n bat";
856};
857
858/*
859 *  sys/wait.h on AIX 5.2 defines macros that have both signed and
860 *  unsigned types in conditional expressions.
861 */
862fix = {
863    hackname  = aix_syswait_2;
864    files     = sys/wait.h;
865    select    = '\? (\(\(\(\(unsigned[^)]*\)[^)]*\) >> [^)]*\) \& 0xff\) : -1)';
866    c_fix     = format;
867    c_fix_arg = "? (int)%1";
868    test_text = "#define WSTOPSIG(__x)    "
869        "(int)(WIFSTOPPED(__x) ? ((((unsigned int)__x) >> 8) & 0xff) : -1)";
870};
871
872/*
873 *  sys/signal.h on some versions of AIX uses volatile in the typedef of
874 *  sig_atomic_t, which causes gcc to generate a warning about duplicate
875 *  volatile when a sig_atomic_t variable is declared volatile, as
876 *  required by ANSI C.
877 */
878fix = {
879    hackname  = aix_volatile;
880    files     = sys/signal.h;
881    select    = "typedef volatile int sig_atomic_t";
882    c_fix     = format;
883    c_fix_arg = "typedef int sig_atomic_t";
884    test_text = "typedef volatile int sig_atomic_t;";
885};
886
887/*
888 *  Fix __assert declaration in assert.h on Alpha OSF/1.
889 */
890fix = {
891    hackname  = alpha___assert;
892    files     = "assert.h";
893    select    = '__assert\(char \*, char \*, int\)';
894    c_fix     = format;
895    c_fix_arg = "__assert(const char *, const char *, int)";
896    test_text = 'extern void __assert(char *, char *, int);';
897};
898
899/*
900 *  Fix assert macro in assert.h on Alpha OSF/1.
901 *  The superfluous int cast breaks C++.
902 */
903fix = {
904    hackname  = alpha_assert;
905    files     = "assert.h";
906    select    = "(#[ \t]*" 'define assert\(EX\).*)\(\(int\) \(EX\)\)';
907    c_fix     = format;
908    c_fix_arg = "%1(EX)";
909    test_text = '#define assert(EX) (((int) (EX)) ? (void)0 '
910                ': __assert(#EX, __FILE__, __LINE__))';
911};
912
913/*
914 *  Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
915 */
916fix = {
917    hackname  = alpha_getopt;
918    files     = "stdio.h";
919    files     = "stdlib.h";
920    select    = 'getopt\(int, char \*\[\], *char \*\)';
921    c_fix     = format;
922    c_fix_arg = "getopt(int, char *const[], const char *)";
923    test_text = 'extern int getopt(int, char *[], char *);';
924};
925
926/*
927 *  Fix missing semicolon on Alpha OSF/4 in <net/if.h>
928 */
929fix = {
930    hackname  = alpha_if_semicolon;
931    files     = net/if.h;
932    select    = "struct[ \t]+sockaddr[ \t]+vmif_paddr[ \t]+/\\*";
933    c_fix     = format;
934    c_fix_arg = "struct sockaddr vmif_paddr;\t/*";
935    test_text = '     struct  sockaddr vmif_paddr     /* protocol address */';
936};
937
938/*
939 * Remove erroneous parentheses in sym.h on Alpha OSF/1.
940 */
941fix = {
942    hackname  = alpha_parens;
943    files     = sym.h;
944    select    = '#ifndef\(__mips64\)';
945    c_fix     = format;
946    c_fix_arg = "#ifndef __mips64";
947    test_text = "#ifndef(__mips64) /* bogus */\nextern int foo;\n#endif";
948};
949
950/*
951 *  Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
952 *  And OpenBSD.
953 */
954fix = {
955    hackname = alpha_sbrk;
956    files    = unistd.h;
957    select   = "char[ \t]*\\*[\t ]*sbrk[ \t]*\\(";
958    c_fix     = format;
959    c_fix_arg = "void *sbrk(";
960    test_text = "extern char* sbrk(ptrdiff_t increment);";
961};
962
963/*
964 *  For C++, avoid any typedef or macro definition of bool,
965 *  and use the built in type instead.
966 *  HP/UX 10.20 also has it in curses_colr/curses.h.
967 */
968fix = {
969    hackname  = avoid_bool_define;
970    files     = curses.h;
971    files     = curses_colr/curses.h;
972    files     = term.h;
973    files     = tinfo.h;
974
975    select    = "#[ \t]*define[ \t]+bool[ \t]";
976    bypass    = "__cplusplus";
977
978    c_fix     = format;
979    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
980    c_fix_arg = "^[ \t]*#[ \t]*define[ \t]+bool[ \t].*";
981
982    test_text = "# define bool\t char \n";
983};
984
985/*
986 * avoid_bool_type
987 */
988fix = {
989    hackname = avoid_bool_type;
990    files    = curses.h;
991    files    = curses_colr/curses.h;
992    files    = term.h;
993    files    = tinfo.h;
994
995    select    = "^[ \t]*typedef[ \t].*[ \t]bool[ \t]*;";
996    bypass    = "__cplusplus";
997
998    c_fix     = format;
999    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
1000
1001    test_text = "typedef unsigned int\tbool \t; /* bool\n type */";
1002};
1003
1004/*
1005 *  For C++, avoid any typedef definition of wchar_t,
1006 *  and use the built in type instead.
1007 *  Don't do this for headers that are smart enough to do the right
1008 *  thing (recent [n]curses.h and Xlib.h).
1009 *  Don't do it for <linux/nls.h> which is never used from C++ anyway,
1010 *  and will be broken by the edit.
1011 */
1012
1013fix = {
1014    hackname = avoid_wchar_t_type;
1015
1016    select    = "^[ \t]*typedef[ \t].*[ \t]wchar_t[ \t]*;";
1017    bypass    = "__cplusplus";
1018    bypass    = "_LINUX_NLS_H";
1019    bypass    = "XFree86: xc/lib/X11/Xlib\\.h";
1020
1021    c_fix     = format;
1022    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
1023
1024    test_text = "typedef unsigned short\twchar_t \t; /* wchar_t\n type */";
1025};
1026
1027/*
1028 *  Fix `typedef struct term;' on hppa1.1-hp-hpux9.
1029 */
1030fix = {
1031    hackname  = bad_struct_term;
1032    files     = curses.h;
1033    select    = "^[ \t]*typedef[ \t]+struct[ \t]+term[ \t]*;";
1034    c_fix     = format;
1035    c_fix_arg = "struct term;";
1036
1037    test_text = 'typedef struct term;';
1038};
1039
1040/*
1041 *  Fix one other error in this file:
1042 *  a mismatched quote not inside a C comment.
1043 */
1044fix = {
1045    hackname  = badquote;
1046    files     = sundev/vuid_event.h;
1047    select    = "doesn't";
1048    c_fix     = format;
1049    c_fix_arg = "does not";
1050
1051    test_text = "/* doesn't have matched single quotes */";
1052};
1053
1054/*
1055 *  check for broken assert.h that needs stdio.h
1056 */
1057fix = {
1058    hackname  = broken_assert_stdio;
1059    files     = assert.h;
1060    select    = stderr;
1061    bypass    = "include.*stdio\\.h";
1062    c_fix     = wrap;
1063    c_fix_arg = "#include <stdio.h>\n";
1064    test_text = "extern FILE* stderr;";
1065};
1066
1067/*
1068 *  check for broken assert.h that needs stdlib.h
1069 */
1070fix = {
1071    hackname  = broken_assert_stdlib;
1072    files     = assert.h;
1073    select    = 'exit *\(|abort *\(';
1074    bypass    = "include.*stdlib\\.h";
1075    c_fix     = wrap;
1076    c_fix_arg = "#ifdef __cplusplus\n"
1077                "#include <stdlib.h>\n"
1078                "#endif\n";
1079    test_text = "extern void exit ( int );";
1080};
1081
1082/*
1083 *  Remove `extern double cabs' declarations from math.h.
1084 *  This conflicts with C99.  Discovered on AIX.
1085 *  Darwin hides its broken cabs in architecture-specific subdirs.
1086 */
1087fix = {
1088    hackname = broken_cabs;
1089    files    = math.h, "architecture/*/math.h";
1090    select   = "^extern[ \t]+double[ \t]+cabs";
1091
1092    sed       = "s/^extern[ \t]*double[ \t]*cabs[ \t]*\([^\\\)]*\);//";
1093    sed       = "s/^extern[ \t]*long[ \t]*double[ \t]*cabsl[ \t]*\([^\\\)]*\);//";
1094
1095    test_text = "#ifdef __STDC__\n"
1096                "extern     double   cabs(struct dbl_hypot);\n"
1097                "#else\n"
1098                "extern     double   cabs();\n"
1099                "#endif\n"
1100                "extern double cabs ( _Complex z );";
1101};
1102
1103/*
1104 * Fixup Darwin's broken check for __builtin_nanf.
1105 */
1106fix = {
1107    hackname  = broken_nan;
1108    /*
1109     *  It is tempting to omit the first "files" entry.  Do not.
1110     *  The testing machinery will take the first "files" entry as the name
1111     *  of a test file to play with.  It would be a nuisance to have a directory
1112     *  with the name "*".
1113     */
1114    files     = "architecture/ppc/math.h";
1115    files     = "architecture/*/math.h";
1116    select    = '#if defined\(__APPLE_CC__\) && \(__APPLE_CC__ >= 1345\)';
1117    bypass    = "powl";
1118    c_fix     = format;
1119    c_fix_arg = "#if 1";
1120    test_text = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)";
1121};
1122
1123/*
1124 *  Various systems derived from BSD4.4 contain a macro definition
1125 *  for vfscanf that interacts badly with requirements of builtin-attrs.def.
1126 *  Known to be fixed in FreeBSD 5 system headers.
1127 */
1128fix = {
1129    hackname  = bsd_stdio_attrs_conflict;
1130    mach      = "*-*-*bsd*";
1131    mach      = "*-*-*darwin*";
1132    files     = stdio.h;
1133    select    = "^#define[ \t]*vfscanf[ \t]*__svfscanf[ \t]*$";
1134    c_fix     = format;
1135    c_fix_arg = '#define _BSD_STRING(_BSD_X) _BSD_STRINGX(_BSD_X)' "\n"
1136		'#define _BSD_STRINGX(_BSD_X) #_BSD_X' "\n"
1137		'int vfscanf(FILE *, const char *, __builtin_va_list) '
1138		'__asm__ (_BSD_STRING(__USER_LABEL_PREFIX__) "__svfscanf");';
1139    test_text = '#define  vfscanf	__svfscanf';
1140};
1141
1142/*
1143 *  Old Linux kernel's <compiler.h> header breaks Traditional CPP
1144 */
1145fix = {
1146    hackname  = complier_h_tradcpp;
1147    files     = linux/compiler.h;
1148
1149    select    = "#define __builtin_warning\\(x, y\\.\\.\\.\\) \\(1\\)";
1150    c_fix     = format;
1151    c_fix_arg = "/* __builtin_warning(x, y...) is obsolete */";
1152
1153    test_text = "#define __builtin_warning(x, y...) (1)";
1154};
1155
1156/*
1157 *  Fix various macros used to define ioctl numbers.
1158 *  The traditional syntax was:
1159 *
1160 *    #define _CTRL(n, x) (('n'<<8)+x)
1161 *    #define TCTRLCFOO _CTRL(T, 1)
1162 *
1163 *  but this does not work with the C standard, which disallows macro
1164 *  expansion inside strings.  We have to rewrite it thus:
1165 *
1166 *    #define _CTRL(n, x) ((n<<8)+x)
1167 *    #define TCTRLCFOO  _CTRL('T', 1)
1168 *
1169 *  The select expressions match too much, but the c_fix code is cautious.
1170 *
1171 *  CTRL might be: CTRL _CTRL ISCTRL BSD43_CTRL ...
1172 */
1173fix = {
1174    hackname  = ctrl_quotes_def;
1175    select    = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z][,)]";
1176    c_fix     = char_macro_def;
1177    c_fix_arg = "CTRL";
1178
1179    /*
1180     *  This is two tests in order to ensure that the "CTRL(c)" can
1181     *  be selected in isolation from the multi-arg format
1182     */
1183    test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)\n";
1184    test_text = "#define _CTRL(c) ('c'&037)";
1185};
1186
1187/*
1188 *  Fix various macros used to define ioctl numbers.
1189 */
1190fix = {
1191    hackname  = ctrl_quotes_use;
1192    select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
1193    c_fix     = char_macro_use;
1194    c_fix_arg = "CTRL";
1195    test_text = "#define TCTRLFOO BSD43_CTRL(T, 1)";
1196};
1197
1198/*
1199 *  sys/mman.h on HP/UX is not C++ ready,
1200 *  even though NO_IMPLICIT_EXTERN_C is defined on HP/UX.
1201 *
1202 *  rpc/types.h on OSF1/2.0 is not C++ ready,
1203 *  even though NO_IMPLICIT_EXTERN_C is defined for the alpha.
1204 *
1205 *  The problem is the declaration of malloc.
1206 */
1207fix = {
1208    hackname = cxx_unready;
1209    files    = sys/mman.h;
1210    files    = rpc/types.h;
1211    select   = '[^#]+malloc.*;';  /* Catch any form of declaration
1212				     not within a macro.  */
1213    bypass   = '"C"|__BEGIN_DECLS';
1214
1215    c_fix     = wrap;
1216    c_fix_arg = "#ifdef __cplusplus\n"
1217                "extern \"C\" {\n"
1218                "#endif\n";
1219    c_fix_arg = "#ifdef __cplusplus\n"
1220                "}\n"
1221                "#endif\n";
1222    test_text = "extern void* malloc( size_t );";
1223};
1224
1225/*
1226 *  For the AAB_darwin7_9_long_double_funcs fix to be useful,
1227 *  you have to not use "" includes.
1228 */
1229fix = {
1230    hackname  = darwin_9_long_double_funcs_2;
1231    mach      = "*-*-darwin7.9*";
1232    files     = math.h;
1233    select    = '#include[ \t]+\"';
1234    c_fix     = format;
1235    c_fix_arg = "%1<%2.h>";
1236
1237    c_fix_arg = '([ \t]*#[ \t]*include[ \t]+)"([a-z0-9/]+)\.h"';
1238
1239    test_text = '#include "architecture/ppc/math.h"';
1240};
1241
1242/*
1243 *  On darwin8 and earlier, mach-o/swap.h isn't properly guarded
1244 *  by 'extern "C"'.  On darwin7 some mach/ headers aren't properly guarded.
1245 */
1246fix = {
1247  hackname  = darwin_externc;
1248  mach      = "*-*-darwin*";
1249  files     = mach-o/swap.h;
1250  files     = mach/mach_time.h;
1251  files     = mach/mach_traps.h;
1252  files     = mach/message.h;
1253  files     = mach/mig.h;
1254  files     = mach/semaphore.h;
1255  bypass    = "extern \"C\"";
1256  bypass    = "__BEGIN_DECLS";
1257  c_fix     = wrap;
1258  c_fix_arg = "#ifdef __cplusplus\n"
1259              "extern \"C\" {\n"
1260              "#endif\n";
1261  c_fix_arg = "#ifdef __cplusplus\n"
1262              "}\n"
1263              "#endif\n";
1264  test_text = "extern void swap_fat_header();\n";
1265};
1266
1267/*
1268 * AvailabilityMacros.h on Darwin breaks with GCC 4.0, because of
1269 * bad __GNUC__ tests.
1270 */
1271fix = {
1272  hackname  = darwin_gcc4_breakage;
1273  mach      = "*-*-darwin*";
1274  files     = AvailabilityMacros.h;
1275  select    = "\\(__GNUC__ >= 3\\) && \\(__GNUC_MINOR__ >= 1\\)";
1276  c_fix     = format;
1277  c_fix_arg = "((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))";
1278  test_text = "#if defined(__GNUC__) && (__GNUC__ >= 3) && "
1279  	      "(__GNUC_MINOR__ >= 1)\n";
1280};
1281
1282/*
1283 *  __private_extern__ doesn't exist in FSF GCC.  Even if it did,
1284 *  why would you ever put it in a system header file?
1285 */
1286fix = {
1287  hackname  = darwin_private_extern;
1288  mach      = "*-*-darwin*";
1289  files     = mach-o/dyld.h;
1290  select    = "__private_extern__ [a-z_]+ _dyld_";
1291  c_fix     = format;
1292  c_fix_arg = "extern";
1293  c_fix_arg = "__private_extern__";
1294  test_text = "__private_extern__ int _dyld_func_lookup(\n"
1295	      "const char *dyld_func_name,\n"
1296	      "unsigned long *address);\n";
1297};
1298
1299/*
1300 * Darwin headers have a stdint.h that defines UINT8_C and UINT16_C to
1301 * unsigned constants.
1302 */
1303fix = {
1304    hackname  = darwin_stdint_1;
1305    mach      = "*-*-darwin*";
1306    files     = stdint-darwin.h, stdint.h;
1307    c_fix     = format;
1308    c_fix_arg = "#define UINT8_C(v)\tv\n#define UINT16_C(v)\tv";
1309    select    = "#define UINT8_C\\(v\\)[ \t]+\\(v ## U\\)\n"
1310		"#define UINT16_C\\(v\\)[ \t]+\\(v ## U\\)";
1311    test_text = "#define UINT8_C(v)   (v ## U)\n"
1312		"#define UINT16_C(v)  (v ## U)";
1313};
1314
1315/*
1316 * Darwin headers have a stdint.h that defines INTPTR_MIN and INTPTR_MAX
1317 * with wrong types.
1318 */
1319fix = {
1320    hackname  = darwin_stdint_2;
1321    mach      = "*-*-darwin*";
1322    files     = stdint-darwin.h, stdint.h;
1323    c_fix     = format;
1324    c_fix_arg = "#if __WORDSIZE == 64\n"
1325		"#define INTPTR_MAX 9223372036854775807L\n"
1326		"#define INTPTR_MIN (-INTPTR_MAX-1)\n"
1327		"#else\n"
1328		"#define INTPTR_MAX 2147483647L\n"
1329		"#define INTPTR_MIN (-INTPTR_MAX-1)\n"
1330		"#endif";
1331    select    = "#if __WORDSIZE == 64\n"
1332		"#define INTPTR_MIN[ \t]+INT64_MIN\n"
1333		"#define INTPTR_MAX[ \t]+INT64_MAX\n"
1334		"#else\n"
1335		"#define INTPTR_MIN[ \t]+INT32_MIN\n"
1336		"#define INTPTR_MAX[ \t]+INT32_MAX\n"
1337		"#endif";
1338    test_text = "#if __WORDSIZE == 64\n"
1339		"#define INTPTR_MIN        INT64_MIN\n"
1340		"#define INTPTR_MAX        INT64_MAX\n"
1341		"#else\n"
1342		"#define INTPTR_MIN        INT32_MIN\n"
1343		"#define INTPTR_MAX        INT32_MAX\n"
1344		"#endif";
1345};
1346
1347/*
1348 * Darwin headers have a stdint.h that defines UINTPTR_MAX with a wrong type.
1349 */
1350fix = {
1351    hackname  = darwin_stdint_3;
1352    mach      = "*-*-darwin*";
1353    files     = stdint-darwin.h, stdint.h;
1354    c_fix     = format;
1355    c_fix_arg = "#if __WORDSIZE == 64\n"
1356		"#define UINTPTR_MAX 18446744073709551615UL\n"
1357		"#else\n"
1358		"#define UINTPTR_MAX 4294967295UL\n"
1359		"#endif";
1360    select    = "#if __WORDSIZE == 64\n"
1361		"#define UINTPTR_MAX[ \t]+UINT64_MAX\n"
1362		"#else\n"
1363		"#define UINTPTR_MAX[ \t]+UINT32_MAX\n"
1364		"#endif";
1365    test_text = "#if __WORDSIZE == 64\n"
1366		"#define UINTPTR_MAX       UINT64_MAX\n"
1367		"#else\n"
1368		"#define UINTPTR_MAX       UINT32_MAX\n"
1369		"#endif";
1370};
1371
1372/*
1373 * Darwin headers have a stdint.h that defines SIZE_MAX with a wrong type.
1374 */
1375fix = {
1376    hackname  = darwin_stdint_4;
1377    mach      = "*-*-darwin*";
1378    files     = stdint-darwin.h, stdint.h;
1379    c_fix     = format;
1380    c_fix_arg = "#if __WORDSIZE == 64\n"
1381		"#define SIZE_MAX 18446744073709551615UL\n"
1382		"#else\n"
1383		"#define SIZE_MAX 4294967295UL\n"
1384		"#endif";
1385    select    = "#if __WORDSIZE == 64\n"
1386		"#define SIZE_MAX[ \t]+UINT64_MAX\n"
1387		"#else\n"
1388		"#define SIZE_MAX[ \t]+UINT32_MAX\n"
1389		"#endif";
1390    test_text = "#if __WORDSIZE == 64\n"
1391		"#define SIZE_MAX          UINT64_MAX\n"
1392		"#else\n"
1393		"#define SIZE_MAX          UINT32_MAX\n"
1394		"#endif";
1395};
1396
1397/*
1398 * Darwin headers have a stdint.h that defines {U,}INTMAX_{MIN,MAX}
1399 * with a wrong type.
1400 */
1401fix = {
1402    hackname  = darwin_stdint_5;
1403    mach      = "*-*-darwin*";
1404    files     = stdint-darwin.h, stdint.h;
1405    c_fix     = format;
1406    c_fix_arg = "#if __WORDSIZE == 64\n"
1407		"#define INTMAX_MIN   (-9223372036854775807L - 1)\n"
1408		"#define INTMAX_MAX   9223372036854775807L\n"
1409		"#define UINTMAX_MAX  18446744073709551615UL\n"
1410		"#else\n"
1411		"#define INTMAX_MIN   (-9223372036854775807LL - 1)\n"
1412		"#define INTMAX_MAX   9223372036854775807LL\n"
1413		"#define UINTMAX_MAX  18446744073709551615ULL\n"
1414		"#endif";
1415    select    = "#define INTMAX_MIN[ \t]+INT64_MIN\n"
1416		"#define INTMAX_MAX[ \t]+INT64_MAX\n"
1417		"\n"
1418		"#define UINTMAX_MAX[ \t]+UINT64_MAX";
1419    test_text = "#define INTMAX_MIN        INT64_MIN\n"
1420		"#define INTMAX_MAX        INT64_MAX\n"
1421		"\n"
1422		"#define UINTMAX_MAX       UINT64_MAX";
1423};
1424
1425/*
1426 * Darwin headers have a stdint.h that defines {U,}INTMAX_C
1427 * with a wrong type.
1428 */
1429fix = {
1430    hackname  = darwin_stdint_6;
1431    mach      = "*-*-darwin*";
1432    files     = stdint-darwin.h, stdint.h;
1433    c_fix     = format;
1434    c_fix_arg = "#if __WORDSIZE == 64\n"
1435		"#define PTRDIFF_MIN (-9223372036854775807L - 1)\n"
1436		"#define PTRDIFF_MAX 9223372036854775807L\n"
1437		"#else\n"
1438		"#define PTRDIFF_MIN (-2147483647 - 1)\n"
1439		"#define PTRDIFF_MAX 2147483647\n"
1440		"#endif";
1441    select    = "#if __WORDSIZE == 64\n"
1442		"#define PTRDIFF_MIN[ \t]+INT64_MIN\n"
1443		"#define PTRDIFF_MAX[ \t]+INT64_MAX\n"
1444		"#else\n"
1445		"#define PTRDIFF_MIN[ \t]+INT32_MIN\n"
1446		"#define PTRDIFF_MAX[ \t]+INT32_MAX\n"
1447		"#endif";
1448    test_text = "#if __WORDSIZE == 64\n"
1449		"#define PTRDIFF_MIN       INT64_MIN\n"
1450		"#define PTRDIFF_MAX       INT64_MAX\n"
1451		"#else\n"
1452		"#define PTRDIFF_MIN       INT32_MIN\n"
1453		"#define PTRDIFF_MAX       INT32_MAX\n"
1454		"#endif";
1455};
1456
1457/*
1458 * Darwin headers have a stdint.h that defines {U,}INTMAX_C
1459 * with a wrong type.
1460 */
1461fix = {
1462    hackname  = darwin_stdint_7;
1463    mach      = "*-*-darwin*";
1464    files     = stdint-darwin.h, stdint.h;
1465    c_fix     = format;
1466    c_fix_arg = "#if __WORDSIZE == 64\n"
1467		"#define INTMAX_C(v)  (v ## L)\n"
1468		"#define UINTMAX_C(v) (v ## UL)\n"
1469		"#else\n"
1470		"#define INTMAX_C(v)  (v ## LL)\n"
1471		"#define UINTMAX_C(v) (v ## ULL)\n"
1472		"#endif";
1473    select    = "#define INTMAX_C\\(v\\)[ \t]+\\(v ## LL\\)\n"
1474		"#define UINTMAX_C\\(v\\)[ \t]+\\(v ## ULL\\)";
1475    test_text = "#define INTMAX_C(v)  (v ## LL)\n"
1476		"#define UINTMAX_C(v) (v ## ULL)";
1477};
1478
1479/*
1480 *  Fix <c_asm.h> on Digital UNIX V4.0:
1481 *  It contains a prototype for a DEC C internal asm() function,
1482 *  clashing with gcc's asm keyword.  So protect this with __DECC.
1483 */
1484fix = {
1485    hackname = dec_intern_asm;
1486    files    = c_asm.h;
1487    sed = "/^[ \t]*float[ \t]*fasm/i\\\n#ifdef __DECC\n";
1488    sed = "/^[ \t]*#[ \t]*pragma[ \t]*intrinsic([ \t]*dasm/a\\\n"
1489          "#endif\n";
1490    test_text =
1491    "float fasm {\n"
1492    "    ... asm stuff ...\n"
1493    "};\n#pragma intrinsic( dasm )\n/* END ASM TEST*/";
1494};
1495
1496/*
1497 * Fix typo in <wchar.h> on DJGPP 2.03.
1498 */
1499fix = {
1500    hackname  = djgpp_wchar_h;
1501    file      = wchar.h;
1502    select    = "__DJ_wint_t";
1503    bypass    = "sys/djtypes.h";
1504    c_fix     = format;
1505    c_fix_arg = "%0\n#include <sys/djtypes.h>";
1506    c_fix_arg = "#include <stddef.h>";
1507    test_text = "#include <stddef.h>\n"
1508                "extern __DJ_wint_t x;\n";
1509};
1510
1511/*
1512 * Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
1513 */
1514fix = {
1515    hackname  = ecd_cursor;
1516    files     = "sunwindow/win_lock.h";
1517    files     = "sunwindow/win_cursor.h";
1518    select    = 'ecd\.cursor';
1519    c_fix     = format;
1520    c_fix_arg = 'ecd_cursor';
1521
1522    test_text = "#ifdef ecd.cursor\n#error bogus\n#endif /* ecd+cursor */";
1523};
1524
1525/*
1526 *  Incorrect feraiseexcept extern inline in bits/fenv.h on x86_64
1527 *  that fails when compiling for SSE-less 32-bit x86.
1528 */
1529fix = {
1530    hackname  = feraiseexcept_nosse_divbyzero;
1531    mach      = 'i[34567]86-*-linux*', 'x86*-linux*', 'amd64-*-linux*';
1532    files     = bits/fenv.h, '*/bits/fenv.h';
1533    select    = "^([\t ]*)__asm__ __volatile__ \\(\"divss %1, %0 *\" : "
1534		": \"x\" \\(__f\\), \"x\" \\(__g\\)\\);$";
1535    bypass    = "\"fdivp .*; fwait\"";
1536
1537    c_fix     = format;
1538    c_fix_arg = <<- _EOText_
1539	# ifdef __SSE_MATH__
1540	%0
1541	# else
1542	%1__asm__ __volatile__ ("fdivp %%%%st, %%%%st(1); fwait"
1543	%1			: "=t" (__f) : "0" (__f), "u" (__g) : "st(1)");
1544	# endif
1545	_EOText_;
1546
1547    test_text = <<- _EOText_
1548	  __asm__ __volatile__ ("divss %1, %0" : : "x" (__f), "x" (__g));
1549	_EOText_;
1550};
1551
1552/*
1553 *  Incorrect feraiseexcept extern inline in bits/fenv.h on x86_64
1554 *  that fails when compiling for SSE-less 32-bit x86.
1555 */
1556fix = {
1557    hackname  = feraiseexcept_nosse_invalid;
1558    mach      = 'i[34567]86-*-linux*', 'x86*-linux*', 'amd64-*-linux*';
1559    files     = bits/fenv.h, '*/bits/fenv.h';
1560    select    = "^([\t ]*)__asm__ __volatile__ \\(\"divss %0, %0 *\" : "
1561		": \"x\" \\(__f\\)\\);$";
1562    bypass    = "\"fdiv .*; fwait\"";
1563
1564    c_fix     = format;
1565    c_fix_arg = <<- _EOText_
1566	# ifdef __SSE_MATH__
1567	%0
1568	# else
1569	%1__asm__ __volatile__ ("fdiv %%%%st, %%%%st(0); fwait"
1570	%1			: "=t" (__f) : "0" (__f));
1571	# endif
1572	_EOText_;
1573
1574    test_text = <<- _EOText_
1575	  __asm__ __volatile__ ("divss %0, %0" : : "x" (__f));
1576	_EOText_;
1577};
1578
1579/*
1580 *  Between 8/24/1998 and 2/17/2001, FreeBSD system headers presume
1581 *  neither the existence of GCC 3 nor its exact feature set yet break
1582 *  (by design?) when __GNUC__ is set beyond 2.
1583 */
1584fix = {
1585    hackname  = freebsd_gcc3_breakage;
1586    mach      = "*-*-freebsd*";
1587    files     = sys/cdefs.h;
1588    select    = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7$';
1589    bypass    = '__GNUC__[ \t]*([>=]=[ \t]*[3-9]|>[ \t]*2)';
1590    c_fix     = format;
1591    c_fix_arg = '%0 || __GNUC__ >= 3';
1592    test_text = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7';
1593};
1594
1595/*
1596 *  Some releases of FreeBSD 4 and FreeBSD 5.0 and 5.1 system headers presume
1597 *  neither the existence of GCC 4 nor its exact feature set yet break
1598 *  (by design?) when __GNUC__ is set beyond 3.
1599 */
1600fix = {
1601    hackname  = freebsd_gcc4_breakage;
1602    mach      = "*-*-freebsd*";
1603    files     = sys/cdefs.h;
1604    select    = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 \|\| __GNUC__ == 3$';
1605    c_fix     = format;
1606    c_fix_arg = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3';
1607    test_text = '#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3';
1608};
1609
1610/*
1611 *  Some versions of glibc don't expect the C99 inline semantics.
1612 */
1613fix = {
1614    hackname  = glibc_c99_inline_1;
1615    files     = features.h, '*/features.h';
1616    select    = "^ *&& !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__$";
1617    c_fix     = format;
1618    c_fix_arg = "%0 && (defined __extern_inline || defined __GNUC_GNU_INLINE__)";
1619    test_text = <<-EOT
1620	#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
1621	    && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__
1622	# define __USE_EXTERN_INLINES	1
1623	#endif
1624	EOT;
1625};
1626
1627/*
1628 *  Similar, but a version that didn't have __NO_INLINE__
1629 */
1630fix = {
1631    hackname  = glibc_c99_inline_1a;
1632    files     = features.h, '*/features.h';
1633    select    = "(\\) && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__)\n"
1634		"(#[ \t]*define[ \t]*__USE_EXTERN_INLINES[ \t]*1)";
1635    c_fix     = format;
1636    c_fix_arg = "%1 && (defined __extern_inline || defined __GNUC_GNU_INLINE__)\n%2";
1637    test_text = <<-EOT
1638	#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__
1639	# define __USE_EXTERN_INLINES	1
1640	#endif
1641	EOT;
1642};
1643
1644/*
1645 * The glibc_c99_inline_1 fix should have fixed everything.  Unfortunately
1646 * there are many glibc headers which do not respect __USE_EXTERN_INLINES.
1647 * The remaining glibc_c99_inline_* fixes deal with some of those headers.
1648 */
1649fix = {
1650    hackname  = glibc_c99_inline_2;
1651    files     = sys/stat.h, '*/sys/stat.h';
1652    select    = "extern __inline__ int";
1653    sed     = "s/extern int \\(stat\\)/"
1654              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1655              "__inline__ int \\1/";
1656    sed     = "s/extern int \\([lf]stat\\)/"
1657              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1658              "__inline__ int \\1/";
1659    sed     = "s/extern int \\(mknod\\)/"
1660              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1661              "__inline__ int \\1/";
1662    sed     = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\(stat\\)/"
1663              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1664              "__inline__ int __REDIRECT\\1 (\\2/";
1665    sed     = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\([lf]stat\\)/"
1666              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1667              "__inline__ int __REDIRECT\\1 (\\2/";
1668    sed     = "s/^extern __inline__ int/"
1669              "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
1670              "__inline__ int/";
1671    test_text = <<-EOT
1672	extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
1673	extern __inline__ int
1674	__NTH (fstat64 (int __fd, struct stat64 *__statbuf))
1675	{}
1676	EOT;
1677};
1678
1679/*
1680 * glibc_c99_inline_3
1681 */
1682fix = {
1683    hackname  = glibc_c99_inline_3;
1684    files     = bits/string2.h, '*/bits/string2.h';
1685    select    = "extern __inline";
1686    bypass    = "__extern_inline|__GNU_STDC_INLINE__";
1687    c_fix     = format;
1688    c_fix_arg = "# if defined(__cplusplus) || defined(__GNUC_STDC_INLINE__)";
1689    c_fix_arg = "^# ifdef __cplusplus$";
1690    test_text = <<-EOT
1691	# ifdef __cplusplus
1692	#  define __STRING_INLINE inline
1693	# else
1694	#  define __STRING_INLINE extern __inline
1695	# endif
1696	EOT;
1697};
1698
1699/*
1700 * glibc_c99_inline_4
1701 */
1702fix = {
1703    hackname  = glibc_c99_inline_4;
1704    files     = sys/sysmacros.h, '*/sys/sysmacros.h', wchar.h, '*/wchar.h';
1705    bypass    = "__extern_inline|__gnu_inline__";
1706    select    = "(^| )extern __inline";
1707    c_fix     = format;
1708    c_fix_arg = "%0 __attribute__ ((__gnu_inline__))";
1709    test_text = <<-EOT
1710	__extension__ extern __inline unsigned int
1711	extern __inline unsigned int
1712	EOT;
1713};
1714
1715/*  glibc-2.3.5 defines pthread mutex initializers incorrectly,
1716 *  so we replace them with versions that correspond to the
1717 *  definition.
1718 */
1719fix = {
1720    hackname = glibc_mutex_init;
1721    files    = pthread.h;
1722    select   = '\{ *\{ *0, *\} *\}';
1723    sed      = "/define[ \t]\\{1,\\}PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/{\n"
1724               "N\ns/{ { 0, } }/{ { 0, 0, 0, 0, 0, 0 } }/\n}";
1725    sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1726               "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0 }/";
1727    sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1728               "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0 }/";
1729    sed      = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
1730               "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0 }/";
1731    sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1732               "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
1733    sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1734               "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0, 0 }/";
1735    sed      = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
1736               "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
1737    sed      = "/define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/"
1738               "N;s/^[ \t]*#[ \t]*"
1739               "\\(define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\\\)\\n"
1740               "[ \t]*{ { 0, } }/# if __WORDSIZE == 64\\\n"
1741               "#  \\1\\\n"
1742               "  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
1743               "# else\\\n"
1744               "#  \\1\\\n"
1745               "  { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
1746               "# endif/";
1747    sed      = "s/{ \\(0, 0, 0, 0, 0, 0, "
1748               "PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP\\) }/{ \\1, 0 }/";
1749    sed      = "/define[ \t]\\{1,\\}PTHREAD_COND_INITIALIZER/"
1750               "s/{ { 0, } }/{ { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }/";
1751
1752    test_text = <<- _EOText_
1753	#define PTHREAD_MUTEX_INITIALIZER \\
1754	  { { 0, } }
1755	#ifdef __USE_GNU
1756	# if __WORDSIZE == 64
1757	#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \\
1758	  { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
1759	#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \\
1760	  { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
1761	#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \\
1762	  { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
1763	# else
1764	#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \\
1765	  { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
1766	#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \\
1767	  { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
1768	#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \\
1769	  { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
1770	# endif
1771	#endif
1772	# define PTHREAD_RWLOCK_INITIALIZER \\
1773	  { { 0, } }
1774	# ifdef __USE_GNU
1775	#  if __WORDSIZE == 64
1776	#   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \\
1777	  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,			      \\
1778	      PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
1779	#  else
1780	#   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \\
1781	  { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
1782	#  endif
1783	# endif
1784	#define PTHREAD_COND_INITIALIZER { { 0, } }
1785	_EOText_;
1786};
1787
1788/* glibc versions before 2.5 have a version of stdint.h that defines
1789   UINT8_C and UINT16_C to produce unsigned constants, as do uClibc
1790   versions with stdint.h based on those glibc versions.  */
1791fix = {
1792    hackname  = glibc_stdint;
1793    files     = stdint.h;
1794    select    = "GNU C Library";
1795    c_fix     = format;
1796    c_fix_arg = "# define UINT8_C(c)\tc\n# define UINT16_C(c)\tc";
1797    c_fix_arg = "# define UINT8_C\\(c\\)\tc ## U\n# define UINT16_C\\(c\\)\tc ## U";
1798    test_text = "/* This file is part of the GNU C Library.  */\n"
1799        "# define UINT8_C(c)\tc ## U\n"
1800        "# define UINT16_C(c)\tc ## U";
1801};
1802
1803/* Some versions of glibc have a version of bits/string2.h that
1804   produces "value computed is not used" warnings from strncpy; fix
1805   this definition by using __builtin_strncpy instead as in newer
1806   versions.  */
1807fix = {
1808    hackname  = glibc_strncpy;
1809    files     = bits/string2.h, '*/bits/string2.h';
1810    bypass    = "__builtin_strncpy";
1811    c_fix     = format;
1812    c_fix_arg = "#  define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)";
1813    c_fix_arg = "#  define strncpy([^\n]*\\\\\n)*[^\n]*";
1814    test_text = <<-EOT
1815	#  define strncpy(dest, src, n) \
1816	  (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n)      \\
1817			  ? (strlen (src) + 1 >= ((size_t) (n))			      \\
1818			     ? (char *) memcpy (dest, src, n)			      \\
1819			     : strncpy (dest, src, n))				      \\
1820			  : strncpy (dest, src, n)))
1821	EOT;
1822
1823};
1824
1825/* glibc's tgmath.h relies on an expression that is not an integer
1826   constant expression being treated as it was by GCC 4.4 and
1827   earlier.  */
1828fix = {
1829    hackname  = glibc_tgmath;
1830    files     = tgmath.h;
1831    select    = '\(\(\(type\) 0.25\) && \(\(type\) 0.25 - 1\)\)';
1832    bypass    = "__floating_type\\(type\\) \\\\\n.*__builtin_classify_type";
1833    c_fix     = format;
1834    c_fix_arg = "(__builtin_classify_type ((type) 0) == 8 || "
1835        "(__builtin_classify_type ((type) 0) == 9 && "
1836            "__builtin_classify_type (__real__ ((type) 0)) == 8))";
1837    test_text = "# define __floating_type(type) (((type) 0.25) && ((type) 0.25 - 1))";
1838};
1839
1840/*
1841 * Fix these files to use the types we think they should for
1842 * ptrdiff_t, size_t, and wchar_t.
1843 *
1844 * This defines the types in terms of macros predefined by our 'cpp'.
1845 * This is supposedly necessary for glibc's handling of these types.
1846 * It's probably not necessary for anyone else, but it doesn't hurt.
1847 */
1848fix = {
1849    hackname  = gnu_types;
1850    files  = "sys/types.h";
1851    files  = "stdlib.h";
1852    files  = "sys/stdtypes.h";
1853    files  = "stddef.h";
1854    files  = "memory.h";
1855    files  = "unistd.h";
1856    bypass    = '_GCC_(PTRDIFF|SIZE|WCHAR)_T';
1857    select    = "^[ \t]*typedef[ \t]+.*[ \t](ptrdiff|size|wchar)_t;";
1858    c_fix     = gnu_type;
1859    /* The Solaris 10 headers already define these types correctly.  */
1860    mach   = '*-*-solaris2.1[0-9]*';
1861    not_machine = true;
1862
1863    test_text = "typedef long int ptrdiff_t; /* long int */\n"
1864                "typedef uint_t size_t; /* uint_t */\n"
1865                "typedef ushort_t wchar_t; /* ushort_t */";
1866};
1867
1868/*
1869 *  Fix HP & Sony's use of "../machine/xxx.h"
1870 *  to refer to:  <machine/xxx.h>
1871 */
1872fix = {
1873    hackname  = hp_inline;
1874    files     = sys/spinlock.h;
1875    files     = machine/machparam.h;
1876    select    = "[ \t]*#[ \t]*include[ \t]+"  '"\.\./machine/';
1877
1878    c_fix     = format;
1879    c_fix_arg = "%1<machine/%2.h>";
1880
1881    c_fix_arg = "([ \t]*#[ \t]*include[ \t]+)"  '"\.\./machine/'
1882                '([a-z]+)\.h"';
1883
1884    test_text = ' # include "../machine/mumble.h"';
1885};
1886
1887/*
1888 *  Check for (...) in C++ code in HP/UX sys/file.h.
1889 */
1890fix = {
1891    hackname  = hp_sysfile;
1892    files     = sys/file.h;
1893    select    = "HPUX_SOURCE";
1894
1895    c_fix     = format;
1896    c_fix_arg = "(struct file *, ...)";
1897    c_fix_arg = '\(\.\.\.\)';
1898
1899    test_text = "extern void foo(...); /* HPUX_SOURCE - bad varargs */";
1900};
1901
1902/*
1903 *  Un-Hide a series of five FP defines from post-1999 compliance GCC:
1904 *  FP_NORMAL, FP_ZERO, FP_INFINITE, FP_SUBNORMAL and FP_NAN
1905 */
1906fix = {
1907     hackname  = hppa_hpux_fp_macros;
1908     mach      = "hppa*-hp-hpux11*";
1909     files     = math.h;
1910     select    = "#[ \t]*define[ \t]*FP_NORMAL.*\n"
1911		 "#[ \t]*define[ \t]*FP_ZERO.*\n"
1912		 "#[ \t]*define[ \t]*FP_INFINITE.*\n"
1913		 "#[ \t]*define[ \t]*FP_SUBNORMAL.*\n"
1914		 "#[ \t]*define[ \t]*FP_NAN.*\n";
1915     c_fix     = format;
1916     c_fix_arg = <<- _EOFix_
1917	#endif /* _INCLUDE_HPUX_SOURCE */
1918
1919	#if defined(_INCLUDE_HPUX_SOURCE) || \
1920	   (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
1921	%0#endif
1922
1923	#ifdef _INCLUDE_HPUX_SOURCE
1924
1925	_EOFix_;
1926
1927     test_text =
1928            "#  define FP_NORMAL     0\n"
1929            "#  define FP_ZERO       1\n"
1930            "#  define FP_INFINITE   2\n"
1931            "#  define FP_SUBNORMAL  3\n"
1932            "#  define FP_NAN        4\n";
1933};
1934
1935/*
1936 * Delete C++ double pow (double, int) inline function from HP-UX 10 & 11
1937 * math.h to prevent clash with define in c_std/bits/std_cmath.h.
1938 */
1939fix = {
1940    hackname  = hpux10_cpp_pow_inline;
1941    files     = fixinc-test-limits.h, math.h;
1942    select    = <<-	END_POW_INLINE
1943	^# +ifdef +__cplusplus
1944	 +\}
1945	 +inline +double +pow\(double +__d,int +__expon\) +\{
1946	[ 	]+return +pow\(__d,\(double\)__expon\);
1947	 +\}
1948	 +extern +"C" +\{
1949	#else
1950	# +endif
1951	END_POW_INLINE;
1952
1953    c_fix     = format;
1954    c_fix_arg = "";
1955
1956    test_text =
1957	"#    ifdef __cplusplus\n"
1958	"     }\n"
1959	"     inline double pow(double __d,int __expon) {\n"
1960	"\t return pow(__d,(double)__expon);\n"
1961	"     }\n"
1962	'     extern "C"' " {\n"
1963	"#else\n"
1964	"#    endif";
1965};
1966
1967fix = {
1968     hackname  = hpux11_cpp_pow_inline;
1969     files     = math.h;
1970     select    = " +inline double pow\\(double d,int expon\\) \\{\n"
1971                 " +return pow\\(d, \\(double\\)expon\\);\n"
1972                 " +\\}\n";
1973     c_fix     = format;
1974     c_fix_arg = "";
1975
1976     test_text =
1977            "   inline double pow(double d,int expon) {\n"
1978            "     return pow(d, (double)expon);\n"
1979            "   }\n";
1980};
1981
1982/*
1983 *  Fix hpux 10.X missing ctype declarations 1
1984 */
1985fix = {
1986    hackname = hpux10_ctype_declarations1;
1987    files    = ctype.h;
1988    select   = "^#[ \t]*define _toupper\\(__c\\)[ \t]*__toupper\\(__c\\)";
1989    bypass   = "^[ \t]*extern[ \t]*int[ \t]*__tolower[ \t]*\\(";
1990    c_fix     = format;
1991    c_fix_arg = "#ifdef _PROTOTYPES\n"
1992		"extern int __tolower(int);\n"
1993		"extern int __toupper(int);\n"
1994		"#else /* NOT _PROTOTYPES */\n"
1995		"extern int __tolower();\n"
1996		"extern int __toupper();\n"
1997		"#endif /* _PROTOTYPES */\n\n"
1998		"%0\n";
1999
2000    test_text = "#  define _toupper(__c)         __toupper(__c)\n";
2001};
2002
2003/*
2004 *  Fix hpux 10.X missing ctype declarations 2
2005 */
2006fix = {
2007    hackname = hpux10_ctype_declarations2;
2008    files    = ctype.h;
2009    select   = "^#  if defined\\(_SB_CTYPE_MACROS\\) && \\!defined\\(__lint\\)";
2010    bypass   = "^[ \t]*extern[ \t]*int[ \t]*_isalnum[ \t]*\\(";
2011    c_fix     = format;
2012    c_fix_arg = "%0\n\n"
2013		"#ifdef _PROTOTYPES\n"
2014		"     extern int _isalnum(int);\n"
2015		"     extern int _isalpha(int);\n"
2016		"     extern int _iscntrl(int);\n"
2017		"     extern int _isdigit(int);\n"
2018		"     extern int _isgraph(int);\n"
2019		"     extern int _islower(int);\n"
2020		"     extern int _isprint(int);\n"
2021		"     extern int _ispunct(int);\n"
2022		"     extern int _isspace(int);\n"
2023		"     extern int _isupper(int);\n"
2024		"     extern int _isxdigit(int);\n"
2025		"#  else /* not _PROTOTYPES */\n"
2026		"     extern int _isalnum();\n"
2027		"     extern int _isalpha();\n"
2028		"     extern int _iscntrl();\n"
2029		"     extern int _isdigit();\n"
2030		"     extern int _isgraph();\n"
2031		"     extern int _islower();\n"
2032		"     extern int _isprint();\n"
2033		"     extern int _ispunct();\n"
2034		"     extern int _isspace();\n"
2035		"     extern int _isupper();\n"
2036		"     extern int _isxdigit();\n"
2037		"#endif /* _PROTOTYPES */\n";
2038
2039    test_text = "#  if defined(_SB_CTYPE_MACROS) && !defined(__lint)\n"
2040		"     extern unsigned int *__SB_masks;\n";
2041};
2042
2043/*
2044 *  Fix hpux 10.X missing stdio declarations
2045 */
2046fix = {
2047    hackname = hpux10_stdio_declarations;
2048    files    = stdio.h;
2049    select   = "^#[ \t]*define _iob[ \t]*__iob";
2050    bypass   = "^[ \t]*extern[ \t]*int[ \t]*vsnprintf[ \t]*\\(";
2051    c_fix     = format;
2052    c_fix_arg = "%0\n\n"
2053	"#  if defined(__STDC__) || defined(__cplusplus)\n"
2054	"     extern int snprintf(char *, size_t, const char *, ...);\n"
2055	"     extern int vsnprintf(char *, size_t, const char *, __va_list);\n"
2056	"#  else /* not __STDC__) || __cplusplus */\n"
2057	"     extern int snprintf();\n"
2058	"     extern int vsnprintf();\n"
2059	"#  endif /* __STDC__) || __cplusplus */\n";
2060
2061    test_text = "#  define _iob __iob\n";
2062};
2063
2064/*
2065 *  Make sure hpux defines abs in header.
2066 */
2067fix = {
2068    hackname  = hpux11_abs;
2069    mach      = "*-hp-hpux11*";
2070    files     = stdlib.h;
2071    select    = "ifndef _MATH_INCLUDED";
2072    c_fix     = format;
2073    c_fix_arg = "if !defined(_MATH_INCLUDED) || defined(__GNUG__)";
2074    test_text = "#ifndef _MATH_INCLUDED";
2075};
2076
2077/*
2078 * hpux sendfile()
2079 */
2080fix = {
2081    hackname  = hpux11_extern_sendfile;
2082    mach      = "*-hp-hpux11.[12]*";
2083    files     = sys/socket.h;
2084    select    = "^[ \t]*extern sbsize_t sendfile.*\n.*, int\\)\\);\n";
2085    c_fix     = format;
2086    c_fix_arg = "#ifndef _APP32_64BIT_OFF_T\n%0#endif\n";
2087    test_text = "   extern sbsize_t sendfile __((int, int, off_t, bsize_t,\n"
2088        "                               const struct iovec *, int));\n";
2089};
2090
2091/*
2092 * hpux sendpath()
2093 */
2094fix = {
2095    hackname  = hpux11_extern_sendpath;
2096    mach      = "*-hp-hpux11.[12]*";
2097    files     = sys/socket.h;
2098    select    = "^[ \t]*extern sbsize_t sendpath.*\n.*, int\\)\\);\n";
2099    c_fix     = format;
2100    c_fix_arg = "#ifndef _APP32_64BIT_OFF_T\n%0#endif\n";
2101    test_text = "   extern sbsize_t sendpath __((int, int, off_t, bsize_t,\n"
2102        "                               const struct iovec *, int));\n";
2103};
2104
2105/*
2106 *  Keep HP-UX 11 from stomping on C++ math namespace
2107 *  with defines for fabsf.
2108 */
2109fix = {
2110    hackname  = hpux11_fabsf;
2111    files     = math.h;
2112    select    = "^[ \t]*#[ \t]*define[ \t]+fabsf\\(.*";
2113    bypass    = "__cplusplus";
2114
2115    c_fix     = format;
2116    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
2117
2118    test_text =
2119    "#ifdef _PA_RISC\n"
2120    "#  define fabsf(x) ((float)fabs((double)(float)(x)))\n"
2121    "#endif";
2122};
2123
2124/*
2125 *  Fix C99 constant in __POINTER_SET define.
2126 */
2127fix = {
2128    hackname  = hpux11_pthread_const;
2129    mach      = "*-hp-hpux11.[0-3]*";
2130    files     = sys/pthread.h;
2131    select    = "^#define[ \t]*__POINTER_SET[ \t]*\\(\\(void \\*\\) 1LL\\)";
2132
2133    c_fix     = format;
2134    c_fix_arg = "#define __POINTER_SET\t\t((void *) 1L)";
2135    test_text = "#define __POINTER_SET\t\t((void *) 1LL)";
2136};
2137
2138/*
2139 * Prevent HP-UX 11 from defining __size_t and preventing size_t from
2140 * being defined by having it define _hpux_size_t instead.
2141 */
2142fix = {
2143    hackname  = hpux11_size_t;
2144    mach      = "*-hp-hpux11*";
2145    select    = "__size_t";
2146
2147    c_fix     = format;
2148    c_fix_arg = "_hpux_size_t";
2149
2150    test_text =
2151    "#define __size_t size_t\n"
2152    "       extern int getpwuid_r( char *, __size_t, struct passwd **);\n";
2153};
2154
2155/*
2156 *  Fix hpux 11.00 broken snprintf declaration
2157 *  (third argument is char *, needs to be const char * to prevent
2158 *  spurious warnings with -Wwrite-strings or in C++).
2159 */
2160fix = {
2161    hackname = hpux11_snprintf;
2162    files    = stdio.h;
2163    select   = '(extern int snprintf *\(char *\*, *(|__|_hpux_)size_t,)'
2164                                    ' *(char *\*, *\.\.\.\);)';
2165    c_fix     = format;
2166    c_fix_arg = '%1 const %3';
2167
2168    test_text = "extern int snprintf(char *, size_t, char *, ...);\n"
2169                "extern int snprintf(char *, __size_t, char *, ...);\n"
2170                "extern int snprintf(char *, _hpux_size_t, char *, ...);";
2171};
2172
2173/*
2174 *  Fix hpux 11.00 broken vsnprintf declaration
2175 */
2176fix = {
2177    hackname = hpux11_vsnprintf;
2178    files    = stdio.h;
2179    select   = '(extern int vsnprintf\(char \*, _[hpux]*_size_t, '
2180                                     'const char \*,) __va__list\);';
2181    c_fix     = format;
2182    c_fix_arg = "%1 __va_list);";
2183
2184    test_text = 'extern int vsnprintf(char *, _hpux_size_t, const char *,'
2185                                     ' __va__list);';
2186};
2187
2188/*
2189 *  get rid of bogus inline definitions in HP-UX 8.0
2190 */
2191fix = {
2192    hackname = hpux8_bogus_inlines;
2193    files    = math.h;
2194    select   = inline;
2195    bypass   = "__GNUG__";
2196    sed = "s@inline int abs(int [a-z][a-z]*) {.*}"
2197           "@extern \"C\" int abs(int);@";
2198    sed = "s@inline double abs(double [a-z][a-z]*) {.*}@@";
2199    sed = "s@inline int sqr(int [a-z][a-z]*) {.*}@@";
2200    sed = "s@inline double sqr(double [a-z][a-z]*) {.*}@@";
2201    test_text = "inline int abs(int v) { return (v>=0)?v:-v; }\n"
2202                "inline double sqr(double v) { return v**0.5; }";
2203};
2204
2205/*
2206 * hpux intptr
2207 */
2208fix = {
2209    hackname  = hpux_c99_intptr;
2210    mach      = "*-hp-hpux11.3*";
2211    files     = stdint-hpux11.h, stdint.h;
2212    sed       = "s@^[ \t]*#[ \t]*define[ \t]*PTRDIFF_MAX[ \t]*"
2213        "INT32_MAX[ \t]*$@#define PTRDIFF_MAX (2147483647l)@";
2214    sed       = "s@^[ \t]*#[ \t]*define[ \t]*PTRDIFF_MIN[ \t]*"
2215        "INT32_MIN[ \t]*$@#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)@";
2216    sed       = "s@^[ \t]*#[ \t]*define[ \t]*INTPTR_MAX[ \t]*"
2217        "INT32_MAX[ \t]*$@#define INTPTR_MAX (2147483647l)@";
2218    sed       = "s@^[ \t]*#[ \t]*define[ \t]*INTPTR_MIN[ \t]*"
2219        "INT32_MIN[ \t]*$@#define INTPTR_MIN (-INTPTR_MAX - 1)@";
2220    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINTPTR_MAX[ \t]*"
2221        "UINT32_MAX[ \t]*$@#define UINTPTR_MAX (4294967295ul)@";
2222    sed       = "s@^[ \t]*#[ \t]*define[ \t]*SIZE_MAX[ \t]*"
2223        "UINT32_MAX[ \t]*$@#define SIZE_MAX (4294967295ul)@";
2224    test_text = "#define PTRDIFF_MAX	INT32_MAX\n"
2225		"#define PTRDIFF_MIN	INT32_MIN\n"
2226		"#define INTPTR_MAX	INT32_MAX\n"
2227		"#define INTPTR_MIN	INT32_MIN\n"
2228		"#define UINTPTR_MAX	UINT32_MAX\n"
2229		"#define SIZE_MAX	UINT32_MAX\n";
2230};
2231
2232/*
2233 * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2234 */
2235fix = {
2236    hackname  = hpux_c99_inttypes;
2237    mach      = "*-hp-hpux11.[23]*";
2238    files     = inttypes.h;
2239    files     = stdint-hpux11.h, stdint.h;
2240    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT8_C(__c)[ \t]*"
2241        "__CONCAT_U__(__c)[ \t]*$@#define UINT8_C(__c) (__c)@";
2242    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT16_C(__c)[ \t]*"
2243        "__CONCAT_U__(__c)[ \t]*$@#define UINT16_C(__c) (__c)@";
2244    sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT32_C(__c)[ \t]*"
2245        "__CONCAT__(__c,l)[ \t]*$@#define INT32_C(__c) (__c)@";
2246    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT32_C(__c)[ \t].*$@"
2247        "#define UINT32_C(__c) __CONCAT__(__c,u)@";
2248    test_text = "#define UINT8_C(__c)     __CONCAT_U__(__c)\n"
2249                "#define UINT16_C(__c)    __CONCAT_U__(__c)\n"
2250		"#define INT32_C(__c)     __CONCAT__(__c,l)\n"
2251		"#define UINT32_C(__c)     __CONCAT__(__c,ul)\n";
2252};
2253
2254/*
2255 * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2256 */
2257fix = {
2258    hackname  = hpux_c99_inttypes2;
2259    mach      = "*-hp-hpux11.2*";
2260    files     = stdint-hpux11.h, stdint.h;
2261    sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT8_C(__c)[ \t]*"
2262        "((signed char)(__c))[ \t]*$@#define INT8_C(__c) (__c)@";
2263    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT8_C(__c)[ \t]*"
2264        "((unsigned char)(__c))[ \t]*$@#define UINT8_C(__c) (__c)@";
2265    sed       = "s@^[ \t]*#[ \t]*define[ \t]*INT16_C(__c)[ \t]*"
2266        "((short)(__c))[ \t]*$@#define INT16_C(__c) (__c)@";
2267    sed       = "s@^[ \t]*#[ \t]*define[ \t]*UINT16_C(__c)[ \t]*"
2268        "((unsigned short)(__c))[ \t]*$@#define UINT16_C(__c) (__c)@";
2269    test_text = "#  define	INT8_C(__c)	((signed char)(__c))\n"
2270                "#  define      UINT8_C(__c)    ((unsigned char)(__c))\n"
2271		"#  define      INT16_C(__c)    ((short)(__c))\n"
2272		"#  define	UINT16_C(__c)	((unsigned short)(__c))\n";
2273};
2274
2275/*
2276 *  Fix hpux broken ctype macros
2277 */
2278fix = {
2279    hackname = hpux_ctype_macros;
2280    files    = ctype.h;
2281    select   = '((: |\()__SB_masks \? )'
2282	       '(__SB_masks\[__(alnum|c)\] & _IS)';
2283    c_fix     = format;
2284    c_fix_arg = "%1(int)%3";
2285
2286    test_text = ": __SB_masks ? __SB_masks[__alnum] & _ISCNTRL\n"
2287		"# define isalpha(__c) (__SB_masks ? __SB_masks[__c] & _IS\n";
2288};
2289
2290/*
2291 * hpux errno()
2292 */
2293fix = {
2294    hackname  = hpux_extern_errno;
2295    mach      = "*-hp-hpux10.*";
2296    mach      = "*-hp-hpux11.[0-2]*";
2297    files     = errno.h;
2298    select    = "^[ \t]*extern int errno;$";
2299    c_fix     = format;
2300    c_fix_arg = "#ifdef __cplusplus\n"
2301        "extern \"C\" {\n"
2302        "#endif\n"
2303        "%0\n"
2304        "#ifdef __cplusplus\n"
2305        "}\n"
2306        "#endif";
2307    test_text = "   extern int errno;\n";
2308};
2309
2310/*
2311 *  Fix hpux broken #ifndef _XOPEN_SOURCE_EXTENDED conditional on htonl etc.
2312 */
2313fix = {
2314    hackname = hpux_htonl;
2315    files    = netinet/in.h;
2316    select   = "#ifndef _XOPEN_SOURCE_EXTENDED[ \t]*\n"
2317               "(/\\*\n"
2318               " \\* Macros for number representation conversion\\.\n"
2319               " \\*/\n"
2320               "#ifndef ntohl)";
2321    c_fix     = format;
2322    c_fix_arg = "#if 1\n%1";
2323
2324    test_text = "#ifndef _XOPEN_SOURCE_EXTENDED\n"
2325                "/*\n"
2326                " * Macros for number representation conversion.\n"
2327                " */\n"
2328                "#ifndef ntohl\n"
2329                "#define ntohl(x)        (x)\n"
2330                "#define ntohs(x)        (x)\n"
2331                "#define htonl(x)        (x)\n"
2332                "#define htons(x)        (x)\n"
2333                "#endif\n"
2334                "#endif  /* ! _XOPEN_SOURCE_EXTENDED */";
2335};
2336
2337/*
2338 * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2339 */
2340fix = {
2341    hackname  = hpux_imaginary_i;
2342    mach      = "ia64-hp-hpux11.*";
2343    files     = complex.h;
2344    select    = "^[ \t]*#[ \t]*define[ \t]*_Complex_I.*";
2345    c_fix     = format;
2346    c_fix_arg = "#define _Complex_I (__extension__ 1.0iF)";
2347    test_text = "#define _Complex_I (0.f+_Imaginary_I)\n";
2348};
2349
2350/*
2351 * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2352 */
2353fix = {
2354    hackname  = hpux_inttype_int8_t;
2355    mach      = "*-hp-hpux1[01].*";
2356    files     = sys/_inttypes.h;
2357    select    = "^[ \t]*typedef[ \t]*char[ \t]*int(_least){0,1}8_t.*";
2358    c_fix     = format;
2359    c_fix_arg = "typedef signed char int%18_t;";
2360    test_text = "typedef char int_least8_t;\n"
2361                "typedef char int8_t;\n";
2362};
2363
2364/*
2365 * HP-UX long_double
2366 */
2367fix = {
2368    hackname  = hpux_long_double;
2369    mach      = "*-*-hpux10*";
2370    mach      = "*-*-hpux11.[012]*";
2371    files     = stdlib.h;
2372    select    = "extern[ \t]long_double[ \t]strtold";
2373    bypass    = "long_double_t";
2374    sed       = "/^#[ \t]*ifndef _LONG_DOUBLE/,/\\/\\* _LONG_DOUBLE \\*\\//D";
2375    sed       = "s/long_double/long double/g";
2376
2377    test_text = "#  ifndef _LONG_DOUBLE\n"
2378		"#    define _LONG_DOUBLE\n"
2379		"     typedef struct {\n"
2380		"       unsigned int word1, word2, word3, word4;\n"
2381		"     } long_double;\n"
2382		"#  endif /* _LONG_DOUBLE */\n"
2383		"extern long_double strtold(const char *, char **);\n";
2384};
2385
2386/*
2387 * We cannot use the above rule on 11.31 because it removes the strtold
2388 * definition.  ia64 is OK with no hack, PA needs some help.
2389 */
2390fix = {
2391    hackname  = hpux_long_double_2;
2392    mach      = "hppa*-*-hpux11.3*";
2393    files     = stdlib.h;
2394    select    = "#[ \t]*if[ \t]*!defined\\(__ia64\\) \\|\\| "
2395        "defined\\(_PROTOTYPES\\) \\|\\| "
2396        "defined\\(_LONG_DOUBLE_STRUCT\\)";
2397    c_fix     = format;
2398    c_fix_arg = "#  if !defined(_PROTOTYPES) || defined(_LONG_DOUBLE_STRUCT)";
2399
2400    test_text = "#  if !defined(__ia64) || "
2401        "!defined(_PROTOTYPES) || "
2402        "defined(_LONG_DOUBLE_STRUCT)\n";
2403};
2404
2405/*
2406 *  Add missing braces to pthread initializer defines.
2407 */
2408fix = {
2409    hackname  = hpux_pthread_initializers;
2410    mach      = "*-hp-hpux11.[0-3]*";
2411    files     = sys/pthread.h;
2412    sed       = "s@^[ \t]*1, 1, 1, 1,[ \t]*\\\\"
2413		 "@\t{ 1, 1, 1, 1 },\t\t\t\t\t\t\t\\\\@";
2414    sed       = "s@^[ \t]*1,[ \t]*\\\\"
2415		 "@\t{ 1, 0 }@";
2416    sed       = "/^[ \t]*0$/d";
2417    sed       = "s@__PTHREAD_MUTEX_VALID, 0"
2418		 "@{ __PTHREAD_MUTEX_VALID, 0 }@";
2419    sed       = "s@^[ \t]*0, 0, -1, 0,[ \t]*\\\\"
2420		 "@\t{ 0, 0, -1, 0 },\t\t\t\t\t\t\\\\@";
2421    sed       = "s@0, __LWP_MTX_VALID, 0, 1, 1, 1, 1,[ \t]*\\\\"
2422		 "@{ 0, __LWP_MTX_VALID }, { 0, 1, 1, 1, 1 },\t\t\t\\\\@";
2423    sed       = "s@^[ \t]*__LWP_MTX_VALID, 0, 1, 1, 1, 1,[ \t]*\\\\"
2424		 "@\t{ 0, __LWP_MTX_VALID }, { 0, 1, 1, 1, 1 },\t\t\t\\\\@";
2425    sed       = "s@^[ \t]*0, 0[ \t]*\\\\"
2426		 "@\t{ 0, 0 }\t\t\t\t\t\t\t\\\\@";
2427    sed       = "s@__PTHREAD_COND_VALID, 0"
2428		 "@{ __PTHREAD_COND_VALID, 0 }@";
2429    sed       = "s@__LWP_COND_VALID, 0,[ \t]*\\\\"
2430		 "@{ __LWP_COND_VALID, 0 },\t\t\t\t\t\\\\@";
2431    sed       = "s@__PTHREAD_RWLOCK_VALID, 0"
2432		 "@{ __PTHREAD_RWLOCK_VALID, 0 }@";
2433    sed       = "s@__LWP_RWLOCK_VALID, 0,[ \t]*\\\\"
2434		 "@{ __LWP_RWLOCK_VALID, 0 },\t\t\t\t\t\\\\@";
2435    sed       = "s@^[ \t]*0, 0, 0, 0, 0, 0, 0[ \t]*\\\\"
2436		 "@\t{ 0, 0, 0, 0, 0 }, { 0, 0}\t\t\t\t\t\\\\@";
2437    test_text = "#define PTHREAD_MUTEX_INITIALIZER  {\t\t\t\t\t\\\\\n"
2438		"\t__PTHREAD_MUTEX_VALID, 0,\t\t\t\t\t\\\\\n"
2439		"\t(PTHREAD_MUTEX_DEFAULT | PTHREAD_PROCESS_PRIVATE),\t\t\\\\\n"
2440		"\t__SPNLCK_INITIALIZER,\t\t\t\t\t\t\\\\\n"
2441		"\t0, 0, -1, 0,\t\t\t\t\t\t\t\\\\\n"
2442		"\t0, __LWP_MTX_VALID, 0, 1, 1, 1, 1,\t\t\t\t\\\\\n"
2443		"\t0, 0\t\t\t\t\t\t\t\t\\\\\n"
2444		"}\n";
2445};
2446
2447/*
2448 *  Wrap spu_info in ifdef _KERNEL.  GCC cannot handle an array of unknown
2449 *  type and mpinfou is only defined when _KERNEL is set.
2450 */
2451fix = {
2452    hackname = hpux_spu_info;
2453    mach     = "*-hp-hpux*";
2454    /*
2455     *  It is tempting to omit the first "files" entry.  Do not.
2456     *  The testing machinery will take the first "files" entry as the name
2457     *  of a test file to play with.  It would be a nuisance to have a directory
2458     *  with the name "*".
2459     */
2460    files    = "ia64/sys/getppdp.h";
2461    files    = "*/sys/getppdp.h";
2462    select   = "^.*extern.*spu_info.*";
2463
2464    c_fix     = format;
2465    c_fix_arg = "#ifdef _KERNEL\n%0\n#endif";
2466
2467    test_text = "extern union mpinfou spu_info[];";
2468};
2469
2470/*
2471 * These hacks are need in inttypes.h on 11.23 and in stdint.h on 11.31.
2472 */
2473fix = {
2474    hackname  = hpux_stdint_least_fast;
2475    mach      = "*-hp-hpux11.2*";
2476    files     = stdint-hpux11.h, stdint.h;
2477    select    =
2478        "^[ \t]*#[ \t]*define[ \t]+UINT_(LEAST|FAST)64_MAX[ \t]+ULLONG_MAX";
2479    c_fix     = format;
2480    c-fix-arg = "#  define	UINT_%164_MAX	__UINT64_MAX__";
2481    test-text = "#  define       UINT_FAST64_MAX        ULLONG_MAX\n"
2482		"#  define       UINT_LEAST64_MAX        ULLONG_MAX\n";
2483	_EOFix_;
2484};
2485
2486/*
2487 *  Fix hpux10.20 <sys/time.h> to avoid invalid forward decl
2488 */
2489fix = {
2490    hackname = hpux_systime;
2491    files    = sys/time.h;
2492    select   = "^extern struct sigevent;";
2493
2494    c_fix     = format;
2495    c_fix_arg = "struct sigevent;";
2496
2497    test_text = 'extern struct sigevent;';
2498};
2499
2500/*
2501 *  Fix glibc definition of HUGE_VAL in terms of hex floating point constant
2502 */
2503fix = {
2504    hackname  = huge_val_hex;
2505    files     = bits/huge_val.h, '*/bits/huge_val.h';
2506    select    = "^#[ \t]*define[ \t]*HUGE_VAL[ \t].*0x1\\.0p.*";
2507    bypass    = "__builtin_huge_val";
2508
2509    c_fix     = format;
2510    c_fix_arg = "#define HUGE_VAL (__builtin_huge_val())\n";
2511
2512    test_text = "# define HUGE_VAL\t(__extension__ 0x1.0p2047)";
2513};
2514
2515/*
2516 *  Fix glibc definition of HUGE_VALF in terms of hex floating point constant
2517 */
2518fix = {
2519    hackname  = huge_valf_hex;
2520    files     = bits/huge_val.h, '*/bits/huge_val.h';
2521    select    = "^#[ \t]*define[ \t]*HUGE_VALF[ \t].*0x1\\.0p.*";
2522    bypass    = "__builtin_huge_valf";
2523
2524    c_fix     = format;
2525    c_fix_arg = "#define HUGE_VALF (__builtin_huge_valf())\n";
2526
2527    test_text = "#  define HUGE_VALF (__extension__ 0x1.0p255f)";
2528};
2529
2530/*
2531 *  Fix glibc definition of HUGE_VALL in terms of hex floating point constant
2532 */
2533fix = {
2534    hackname  = huge_vall_hex;
2535    files     = bits/huge_val.h, '*/bits/huge_val.h';
2536    select    = "^#[ \t]*define[ \t]*HUGE_VALL[ \t].*0x1\\.0p.*";
2537    bypass    = "__builtin_huge_vall";
2538
2539    c_fix     = format;
2540    c_fix_arg = "#define HUGE_VALL (__builtin_huge_vall())\n";
2541
2542    test_text = "#  define HUGE_VALL (__extension__ 0x1.0p32767L)";
2543};
2544
2545/*
2546 *  Fix return type of abort and free
2547 */
2548fix = {
2549    hackname  = int_abort_free_and_exit;
2550    files     = stdlib.h;
2551    select    = "int[ \t]+(abort|free|exit)[ \t]*\\(";
2552    bypass    = "_CLASSIC_ANSI_TYPES";
2553
2554    c_fix     = format;
2555    c_fix_arg = "void\t%1(";
2556
2557    test_text = "extern int abort(int);\n"
2558                "extern int free(void*);\n"
2559                "extern int exit(void*);";
2560};
2561
2562/*
2563 *  Fix various macros used to define ioctl numbers.
2564 *  The traditional syntax was:
2565 *
2566 *    #define _IO(n, x) (('n'<<8)+x)
2567 *    #define TIOCFOO _IO(T, 1)
2568 *
2569 *  but this does not work with the C standard, which disallows macro
2570 *  expansion inside strings.  We have to rewrite it thus:
2571 *
2572 *    #define _IO(n, x) ((n<<8)+x)
2573 *    #define TIOCFOO  _IO('T', 1)
2574 *
2575 *  The select expressions match too much, but the c_fix code is cautious.
2576 *
2577 *  _IO might be: _IO DESIO BSD43__IO with W, R, WR, C, ... suffixes.
2578 */
2579fix = {
2580    hackname  = io_quotes_def;
2581    select    = "define[ \t]+[A-Z0-9_]+IO[A-Z]*\\([a-zA-Z][,)]";
2582    c_fix     = char_macro_def;
2583    c_fix_arg = "IO";
2584    test_text =
2585    "#define BSD43__IOWR(n, x) (('n'<<8)+x)\n"
2586    "#define _IOWN(x,y,t)  (_IOC_IN|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)\n"
2587    "#define _IO(x,y)      ('x'<<8|y)";
2588    test_text =
2589    "#define XX_IO(x)        ('x'<<8|256)";
2590};
2591
2592/*
2593 *  Fix the usage of the ioctl macro numbers.
2594 */
2595fix = {
2596    hackname  = io_quotes_use;
2597    select    = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+IO[A-Z]*[ \t]*"
2598                "\\( *[^,']";
2599    c_fix     = char_macro_use;
2600    c_fix_arg = "IO";
2601    test_text = "#define TIOCFOO BSD43__IOWR(T, 1)\n"
2602                "#define TIOCFOO \\\\\n"
2603                "BSD43__IOWR(T, 1) /* Some are multi-line */";
2604};
2605
2606/*
2607 *  Check for missing ';' in struct
2608 */
2609fix = {
2610    hackname = ip_missing_semi;
2611    files    = netinet/ip.h;
2612    select   = "}$";
2613    sed      = "/^struct/,/^};/s/}$/};/";
2614    test_text=
2615    "struct mumble {\n"
2616    "  union {\n"
2617    "    int x;\n"
2618    "  }\n"
2619    "}; /* mumbled struct */\n";
2620};
2621
2622/*
2623 *  Non-traditional "const" declaration in Irix's limits.h.
2624 */
2625fix = {
2626    hackname    = irix_limits_const;
2627    files       = fixinc-test-limits.h, limits.h;
2628    select      = "^extern const ";
2629    c_fix       = format;
2630    c_fix_arg   = "extern __const ";
2631    test_text   = "extern const char limit; /* test limits */";
2632};
2633
2634/*
2635 *  IRIX 5.x's stdio.h declares some functions that take a va_list as
2636 *  taking char *.  However, GCC uses void * for va_list, so
2637 *  calling vfprintf with a va_list fails in C++.  */
2638fix = {
2639    hackname  = irix_stdio_va_list;
2640    files     = stdio.h;
2641
2642    select = '/\* va_list \*/ char \*';
2643    c_fix  = format;
2644    c_fix_arg = "__gnuc_va_list";
2645    test_text =
2646    "extern int printf( const char *, /* va_list */ char * );";
2647};
2648
2649/*
2650 * These files in Sun OS 4.x and ARM/RISCiX and BSD4.3
2651 * use / * * / to concatenate tokens.
2652 */
2653fix = {
2654    hackname = kandr_concat;
2655    files  = "sparc/asm_linkage.h";
2656    files  = "sun*/asm_linkage.h";
2657    files  = "arm/as_support.h";
2658    files  = "arm/mc_type.h";
2659    files  = "arm/xcb.h";
2660    files  = "dev/chardefmac.h";
2661    files  = "dev/ps_irq.h";
2662    files  = "dev/screen.h";
2663    files  = "dev/scsi.h";
2664    files  = "sys/tty.h";
2665    files  = "Xm.acorn/XmP.h";
2666    files  = bsd43/bsd43_.h;
2667    select = '/\*\*/';
2668    c_fix     = format;
2669    c_fix_arg = '##';
2670    test_text = "#define __CONCAT__(a,b) a/**/b";
2671};
2672
2673/*
2674 * The /usr/include/sys/ucontext.h on ia64-*linux-gnu systems defines
2675 * an _SC_GR0_OFFSET macro using an idiom that isn't a compile time
2676 * constant on recent versions of g++.
2677 */
2678fix = {
2679    hackname = linux_ia64_ucontext;
2680    files = "sys/ucontext.h";
2681    mach = "ia64-*-linux*";
2682    select = '\(\(\(char \*\) &\(\(struct sigcontext \*\) 0\)'
2683             '->sc_gr\[0\]\) - \(char \*\) 0\)';
2684    c_fix = format;
2685    c_fix_arg = "__builtin_offsetof \(struct sigcontext, sc_gr[0]\)";
2686    test_text = "# define _SC_GR0_OFFSET\t\\\\\n"
2687	"\t(((char *) &((struct sigcontext *) 0)->sc_gr[0]) - (char *) 0)\n";
2688};
2689
2690/*
2691 *  Remove header file warning from sys/time.h.  Autoconf's
2692 *  AC_HEADER_TIME recommends to include both sys/time.h and time.h
2693 *  which causes warning on LynxOS.  Remove the warning.
2694 */
2695fix = {
2696    hackname  = lynxos_no_warning_in_sys_time_h;
2697    files     = sys/time.h;
2698    select    = "#warning[ \t]+Using <time.h> instead of <sys/time.h>";
2699    c_fix     = format;
2700    c_fix_arg = "";
2701    test_text = "#warning Using <time.h> instead of <sys/time.h>";
2702};
2703
2704/*
2705 *  Add missing declaration for putenv.
2706 */
2707fix = {
2708    hackname  = lynxos_missing_putenv;
2709    mach      = '*-*-lynxos*';
2710    files     = stdlib.h;
2711    bypass    = 'putenv[ \t]*\\(';
2712    select    = "extern char \\*getenv[ \t]*_AP\\(\\(const char \\*\\)\\);";
2713    c_fix     = format;
2714    c_fix_arg = "%0\n"
2715        "extern int putenv				_AP((char *));";
2716    c_fix_arg = "extern char \\*getenv[ \t]*_AP\\(\\(const char \\*\\)\\);";
2717    test_text = "extern char *getenv	_AP((const char *));";
2718};
2719
2720/*
2721 * Fix BSD machine/ansi.h to use __builtin_va_list to define _BSD_VA_LIST_.
2722 *
2723 * On NetBSD, machine is a symbolic link to an architecture specific
2724 * directory name, so we can't match a specific file name here.
2725 */
2726fix = {
2727    hackname = machine_ansi_h_va_list;
2728    select   = "define[ \t]+_BSD_VA_LIST_[ \t]";
2729    bypass   = '__builtin_va_list';
2730
2731    c_fix     = format;
2732    c_fix_arg = "%1__builtin_va_list";
2733    c_fix_arg = "(define[ \t]+_BSD_VA_LIST_[ \t]+).*";
2734
2735    test_text = " # define _BSD_VA_LIST_\tchar**";
2736};
2737
2738/*
2739 *  Fix non-ansi machine name defines
2740 */
2741fix = {
2742    hackname  = machine_name;
2743    c_test    = machine_name;
2744    c_fix     = machine_name;
2745
2746    test_text = "/* MACH_DIFF: */\n"
2747    "#if defined( i386 ) || defined( sparc ) || defined( vax )"
2748    "\n/* no uniform test, so be careful  :-) */";
2749};
2750
2751/*
2752 *  Some math.h files define struct exception (it's in the System V
2753 *  Interface Definition), which conflicts with the class exception defined
2754 *  in the C++ file std/stdexcept.h.  We redefine it to __math_exception.
2755 *  This is not a great fix, but I haven't been able to think of anything
2756 *  better.
2757 */
2758fix = {
2759    hackname  = math_exception;
2760    files     = math.h;
2761    select    = "struct exception";
2762    /*
2763     * This should be bypassed on __cplusplus, but some supposedly C++
2764     * aware headers, such as Solaris 8 and 9, don't wrap their struct
2765     * exception either.  So currently we bypass only for glibc, based on a
2766     * comment in the fixed glibc header.  Ick.
2767     */
2768    bypass    = 'We have a problem when using C\+\+|for C\+\+, '
2769		'_[a-z0-9A-Z_]+_exception; for C, exception';
2770    c_fix     = wrap;
2771
2772    c_fix_arg = "#ifdef __cplusplus\n"
2773                "#define exception __math_exception\n"
2774                "#endif\n";
2775
2776    c_fix_arg = "#ifdef __cplusplus\n"
2777                "#undef exception\n"
2778                "#endif\n";
2779
2780    test_text = "typedef struct exception t_math_exception;";
2781};
2782
2783/*
2784 *  This looks pretty broken to me.  ``dbl_max_def'' will contain
2785 *  "define DBL_MAX " at the start, when what we really want is just
2786 *  the value portion.  Can't figure out how to write a test case
2787 *  for this either  :-(
2788 */
2789fix = {
2790    hackname = math_huge_val_from_dbl_max;
2791    files    = math.h;
2792
2793    /*
2794     * IF HUGE_VAL is defined to be DBL_MAX *and* DBL_MAX is _not_ defined
2795     * in math.h, this fix applies.
2796     */
2797    select   = "define[ \t]+HUGE_VAL[ \t]+DBL_MAX";
2798    bypass   = "define[ \t]+DBL_MAX";
2799
2800    shell    =
2801    /*
2802     *  See if we have a definition for DBL_MAX in float.h.
2803     *  If we do, we will replace the one in math.h with that one.
2804     */
2805
2806    "\tdbl_max_def=`egrep 'define[ \t]+DBL_MAX[ \t]+.*' float.h "
2807                   "| sed 's/.*DBL_MAX[ \t]*//' 2>/dev/null`\n\n"
2808
2809    "\tif ( test -n \"${dbl_max_def}\" ) > /dev/null 2>&1\n"
2810    "\tthen sed -e '/define[ \t]*HUGE_VAL[ \t]*DBL_MAX/"
2811			"s@DBL_MAX@'\"$dbl_max_def@\"\n"
2812    "\telse cat\n"
2813    "\tfi";
2814
2815    test_text =
2816    "`echo '#define DBL_MAX\t3.1415e+9 /* really big */' >> float.h`\n"
2817    "#define HUGE_VAL DBL_MAX";
2818};
2819
2820/*
2821 *  nested comment
2822 */
2823fix = {
2824    hackname  = nested_auth_des;
2825    files     = rpc/rpc.h;
2826    select    = '(/\*.*rpc/auth_des\.h>.*)/\*';
2827    c_fix     = format;
2828    c_fix_arg = "%1*/ /*";
2829    test_text = "/*#include <rpc/auth_des.h> /* skip this */";
2830};
2831
2832/*
2833 *  Some versions of NetBSD don't expect the C99 inline semantics.
2834 */
2835fix = {
2836    hackname  = netbsd_c99_inline_1;
2837    mach      = "*-*-netbsd*";
2838    files     = signal.h;
2839    select    = "extern __inline int";
2840
2841    c_fix     = format;
2842    c_fix_arg = "extern\n"
2843		"#ifdef __GNUC_STDC_INLINE__\n"
2844		"__attribute__((__gnu_inline__))\n"
2845		"#endif\n"
2846		"__inline int";
2847
2848    test_text = "extern __inline int\nsigaddset(sigset_t *set, int signo)\n{}";
2849};
2850
2851/*
2852 * netbsd_c99_inline_2
2853 */
2854fix = {
2855    hackname  = netbsd_c99_inline_2;
2856    mach      = "*-*-netbsd*";
2857    files     = signal.h;
2858    select    = "#define _SIGINLINE extern __inline";
2859
2860    c_fix     = format;
2861    c_fix_arg = <<- _EOArg_
2862	#ifdef __GNUC_STDC_INLINE__
2863	#define _SIGINLINE extern __attribute__((__gnu_inline__)) __inline
2864	#else
2865	%0
2866	#endif
2867	_EOArg_;
2868
2869    test_text = "#define _SIGINLINE extern __inline";
2870};
2871
2872/*
2873 * NetBSD has a semicolon after the ending '}' for some extern "C".
2874 */
2875fix = {
2876    hackname  = netbsd_extra_semicolon;
2877    mach      = "*-*-netbsd*";
2878    files     = sys/cdefs.h;
2879    select    = "#define[ \t]*__END_DECLS[ \t]*};";
2880
2881    c_fix     = format;
2882    c_fix_arg = "#define __END_DECLS }";
2883
2884    test_text = "#define __END_DECLS };";
2885};
2886
2887/*
2888 * newlib's stdint.h has several failures to conform to C99.  The fix
2889 *  for these removed a comment that can be matched to identify unfixed
2890 *  versions.
2891 */
2892fix = {
2893    hackname  = newlib_stdint_1;
2894    files     = stdint-newlib.h, stdint.h;
2895    select    = "@todo - Add support for wint_t types";
2896    sed       = "s@#define INT32_MIN.*@#define INT32_MIN (-INT32_MAX - 1)@";
2897    sed       = "s@#define INT32_MAX.*@#define INT32_MAX __INT32_MAX__@";
2898    sed       = "s@#define UINT32_MAX.*@#define UINT32_MAX __UINT32_MAX__@";
2899    sed       = "s@#define INT_LEAST32_MIN.*@"
2900                  "#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)@";
2901    sed       = "s@#define INT_LEAST32_MAX.*@"
2902                  "#define INT_LEAST32_MAX __INT_LEAST32_MAX__@";
2903    sed       = "s@#define UINT_LEAST32_MAX.*@"
2904                  "#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__@";
2905    sed       = 's@#define INT_FAST\([0-9]*\)_MIN.*@'
2906                  '#define INT_FAST\1_MIN (-INT_FAST\1_MAX - 1)@';
2907    sed       = 's@#define INT_FAST\([0-9]*\)_MAX.*@'
2908                  '#define INT_FAST\1_MAX __INT_FAST\1_MAX__@';
2909    sed       = 's@#define UINT_FAST\([0-9]*\)_MAX.*@'
2910                  '#define UINT_FAST\1_MAX __UINT_FAST\1_MAX__@';
2911    sed       = "s@#define SIZE_MAX.*@#define SIZE_MAX __SIZE_MAX__@";
2912    sed       = "s@#define PTRDIFF_MIN.*@#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)@";
2913    sed       = "s@#define PTRDIFF_MAX.*@#define PTRDIFF_MAX __PTRDIFF_MAX__@";
2914    sed       = "s@#define UINT8_C.*@#define UINT8_C(c) __UINT8_C(c)@";
2915    sed       = "s@#define UINT16_C.*@#define UINT16_C(c) __UINT16_C(c)@";
2916    test_text = "/* @todo - Add support for wint_t types. */\n"
2917                "#define INT32_MIN (-2147483647-1)\n"
2918                "#define INT32_MAX 2147483647\n"
2919                "#define UINT32_MAX 4294967295U\n"
2920                "#define INT_LEAST32_MIN (-2147483647-1)\n"
2921                "#define INT_LEAST32_MAX 2147483647\n"
2922                "#define UINT_LEAST32_MAX 4294967295U\n"
2923                "#define INT_FAST8_MIN INT8_MIN\n"
2924                "#define INT_FAST8_MAX INT8_MAX\n"
2925                "#define UINT_FAST8_MAX UINT8_MAX\n"
2926                "#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)\n"
2927                "#define PTRDIFF_MIN (-__STDINT_EXP(LONG_MAX) - 1L)\n"
2928                "#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)\n"
2929                "#define UINT8_C(x) x##U\n"
2930                "#define UINT16_C(x) x##U";
2931};
2932
2933/*
2934 * newlib_stdint_2
2935 */
2936fix = {
2937    hackname  = newlib_stdint_2;
2938    files     = stdint-newlib.h, stdint.h;
2939    select    = "@todo - Add support for wint_t types";
2940    c_fix     = format;
2941    c_fix_arg = "#define INTMAX_MAX __INTMAX_MAX__\n"
2942                "#define INTMAX_MIN (-INTMAX_MAX - 1)\n"
2943                "#define UINTMAX_MAX __UINTMAX_MAX__\n"
2944                "#define WCHAR_MAX __WCHAR_MAX__\n"
2945                "#define WCHAR_MIN __WCHAR_MIN__\n"
2946                "#define WINT_MAX __WINT_MAX__\n"
2947                "#define WINT_MIN __WINT_MIN__\n\n"
2948                "%0";
2949    c_fix_arg = '/\*\* Macros for minimum-width integer constant expressions \*/';
2950    test_text = "/* @todo - Add support for wint_t types. */\n"
2951                "/** Macros for minimum-width integer constant expressions */";
2952};
2953
2954/*
2955 *  NeXT 3.2 adds const prefix to some math functions.
2956 *  These conflict with the built-in functions.
2957 */
2958fix = {
2959    hackname  = next_math_prefix;
2960    files     = ansi/math.h;
2961    select    = "^extern[ \t]+double[ \t]+__const__[ \t]";
2962
2963    c_fix     = format;
2964    c_fix_arg = "extern double %1(";
2965    c_fix_arg = "^extern[ \t]+double[ \t]+__const__[ \t]+([a-z]+)\\(";
2966
2967    test_text = "extern\tdouble\t__const__\tmumble();";
2968};
2969
2970/*
2971 *  NeXT 3.2 uses the word "template" as a parameter for some
2972 *  functions. GCC reports an invalid use of a reserved key word
2973 *  with the built-in functions.
2974 */
2975fix = {
2976    hackname = next_template;
2977    files    = bsd/libc.h;
2978    select   = "[ \t]template\\)";
2979
2980    c_fix     = format;
2981    c_fix_arg = "(%1)";
2982    c_fix_arg = "\\(([^)]*)[ \t]template\\)";
2983    test_text = "extern mumble( char * template); /* fix */";
2984};
2985
2986/*
2987 *  NeXT 3.2 includes the keyword volatile in the abort() and  exit()
2988 *  function prototypes. That conflicts with the  built-in functions.
2989 */
2990fix = {
2991    hackname = next_volitile;
2992    files    = ansi/stdlib.h;
2993    select   = "^extern[ \t]+volatile[ \t]+void[ \t]";
2994
2995    c_fix     = format;
2996    c_fix_arg = "extern void %1(";
2997    c_fix_arg = "^extern[ \t]+volatile[ \t]+void[ \t]+(exit|abort)\\(";
2998
2999    test_text = "extern\tvolatile\tvoid\tabort();";
3000};
3001
3002/*
3003 *  NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
3004 *  Note that version 3 of the NeXT system has wait.h in a different directory,
3005 *  so that this code won't do anything.  But wait.h in version 3 has a
3006 *  conditional, so it doesn't need this fix.  So everything is okay.
3007 */
3008fix = {
3009    hackname  = next_wait_union;
3010    files     = sys/wait.h;
3011
3012    select    = 'wait\(union wait';
3013    c_fix     = format;
3014    c_fix_arg = "wait(void";
3015    test_text = "extern pid_d wait(union wait*);";
3016};
3017
3018/*
3019 *  a missing semi-colon at the end of the nodeent structure definition.
3020 */
3021fix = {
3022    hackname  = nodeent_syntax;
3023    files     = netdnet/dnetdb.h;
3024    select    = "char[ \t]*\\*na_addr[ \t]*$";
3025    c_fix     = format;
3026    c_fix_arg = "%0;";
3027    test_text = "char *na_addr\t";
3028};
3029
3030/*
3031 * Fix OpenBSD's NULL definition.
3032 */
3033fix = {
3034  hackname  = openbsd_null_definition;
3035  mach      = "*-*-openbsd*";
3036  files     = locale.h, stddef.h, stdio.h, string.h,
3037  time.h, unistd.h, wchar.h, sys/param.h;
3038  select    = "__GNUG__";
3039  c_fix = format;
3040  c_fix_arg = "#ifndef NULL\n"
3041	      "#ifdef __cplusplus\n"
3042	      "#ifdef __GNUG__\n"
3043	      "#define NULL\t__null\n"
3044	      "#else\t /* ! __GNUG__  */\n"
3045	      "#define NULL\t0L\n"
3046              "#endif\t /* __GNUG__  */\n"
3047	      "#else\t /* ! __cplusplus  */\n"
3048	      "#define NULL\t((void *)0)\n"
3049              "#endif\t /* __cplusplus  */\n"
3050              "#endif\t /* !NULL  */";
3051
3052  c_fix_arg = "^#ifndef[ \t]*NULL\n"
3053	      "^#ifdef[ \t]*__GNUG__\n"
3054  	      "^#define[ \t]*NULL[ \t]*__null\n"
3055  	      "^#else\n"
3056              "^#define[ \t]*NULL[ \t]*0L\n"
3057              "^#endif\n"
3058              "^#endif";
3059  test_text =
3060	"#ifndef NULL\n"
3061	"#ifdef  __GNUG__\n"
3062	"#define NULL    __null\n"
3063	"#else\n"
3064	"#define NULL    0L\n"
3065	"#endif\n"
3066	"#endif\n";
3067};
3068
3069/*
3070 *  obstack.h used casts as lvalues.
3071 *
3072 *  We need to change postincrements of casted pointers (which are
3073 *  then dereferenced and assigned into) of the form
3074 *
3075 *    *((TYPE*)PTRVAR)++ = (VALUE)
3076 *
3077 *  into expressions like
3078 *
3079 *    ((*((TYPE*)PTRVAR) = (VALUE)), (PTRVAR += sizeof (TYPE)))
3080 *
3081 *  which is correct for the cases used in obstack.h since PTRVAR is
3082 *  of type char * and the value of the expression is not used.
3083 */
3084fix = {
3085    hackname  = obstack_lvalue_cast;
3086    files     = obstack.h;
3087    select    = '\*\(\(([^()]*)\*\)(.*)\)\+\+ = \(([^()]*)\)';
3088    c_fix     = format;
3089    c_fix_arg = "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))";
3090    test_text = "*((void **) (h)->next_free)++ = (aptr)";
3091};
3092
3093/*
3094 * Fix OpenBSD's va_start define.
3095 */
3096fix = {
3097  hackname  = openbsd_va_start;
3098  mach      = "*-*-openbsd*";
3099  files     = stdarg.h;
3100  select    = '__builtin_stdarg_start';
3101  c_fix     = format;
3102  c_fix_arg = __builtin_va_start;
3103
3104  test_text = "#define va_start(v,l)   __builtin_stdarg_start((v),l)";
3105};
3106
3107/*
3108 *  sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
3109 *  defining regex.h related types.  This causes libg++ build and usage
3110 *  failures.  Fixing this correctly requires checking and modifying 3 files.
3111 */
3112fix = {
3113    hackname = osf_namespace_a;
3114    files    = reg_types.h;
3115    files    = sys/lc_core.h;
3116    test     = " -r reg_types.h";
3117    test     = " -r sys/lc_core.h";
3118    test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
3119    test     = " -z \"`grep __regex_t regex.h`\"";
3120
3121    c_fix     = format;
3122    c_fix_arg = "__%0";
3123    c_fix_arg = "reg(ex|off|match)_t";
3124
3125    test_text = "`touch sys/lc_core.h`"
3126    "typedef struct {\n  int stuff, mo_suff;\n} regex_t;\n"
3127    "extern regex_t    re;\n"
3128    "extern regoff_t   ro;\n"
3129    "extern regmatch_t rm;\n";
3130};
3131
3132fix = {
3133    hackname = osf_namespace_c;
3134    files    = regex.h;
3135    test     = " -r reg_types.h";
3136    test     = " -r sys/lc_core.h";
3137    test     = " -n \"`grep '} regex_t;' reg_types.h`\"";
3138    test     = " -z \"`grep __regex_t regex.h`\"";
3139
3140    select    = "#include <reg_types\.h>.*";
3141    c_fix     = format;
3142    c_fix_arg = "%0\n"
3143                "typedef __regex_t\tregex_t;\n"
3144                "typedef __regoff_t\tregoff_t;\n"
3145                "typedef __regmatch_t\tregmatch_t;";
3146
3147    test_text = "#include <reg_types.h>";
3148};
3149
3150/*
3151 * On broken glibc-2.3.3 systems an array of incomplete structures is
3152 * passed to __sigsetjmp.  Fix that to take a pointer instead.
3153 */
3154fix = {
3155    hackname  = pthread_incomplete_struct_argument;
3156    files     = pthread.h;
3157    select    = "struct __jmp_buf_tag";
3158    c_fix     = format;
3159    c_fix_arg = "%1 *%2%3";
3160    c_fix_arg = "^(extern int __sigsetjmp \\(struct __jmp_buf_tag) "
3161        "(__env)\\[1\\](.*)$";
3162    test_text = "extern int __sigsetjmp (struct __jmp_buf_tag __env[1], "
3163        "int __savemask);";
3164};
3165
3166/*
3167 *  Fix return type of fread and fwrite on sysV68
3168 */
3169fix = {
3170    hackname = read_ret_type;
3171    files    = stdio.h;
3172    select   = "extern int\t.*, fread\\(\\), fwrite\\(\\)";
3173    c_fix     = format;
3174    c_fix_arg = "extern unsigned int fread(), fwrite();\n%1%2";
3175    c_fix_arg = "(extern int\t.*), fread\\(\\), fwrite\\(\\)(.*)";
3176
3177    test_text = "extern int\tfclose(), fflush(), fread(), fwrite(), foo();";
3178};
3179
3180/*
3181 *  Fix casts as lvalues in glibc's <rpc/xdr.h>.
3182 */
3183fix = {
3184    hackname  = rpc_xdr_lvalue_cast_a;
3185    files     = rpc/xdr.h;
3186    select    = "#define[ \t]*IXDR_GET_LONG.*\\\\\n.*__extension__.*";
3187    c_fix     = format;
3188    c_fix_arg = "#define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf))";
3189    test_text = "#define IXDR_GET_LONG(buf) \\\\\n"
3190                "\t((long)ntohl((u_long)*__extension__((u_int32_t*)(buf))++))";
3191};
3192
3193/*
3194 * rpc_xdr_lvalue_cast_b
3195 */
3196fix = {
3197    hackname  = rpc_xdr_lvalue_cast_b;
3198    files     = rpc/xdr.h;
3199    select    = "#define[ \t]*IXDR_PUT_LONG.*\\\\\n.*__extension__.*";
3200    c_fix     = format;
3201    c_fix_arg = "#define IXDR_PUT_LONG(buf, v) ((long)IXDR_PUT_INT32(buf, (long)(v)))";
3202    test_text = "#define IXDR_PUT_LONG(buf, v) \\\\\n"
3203                "\t(*__extension__((u_int32_t*)(buf))++ = (long)htonl((u_long)(v)))";
3204};
3205
3206/*
3207 *  function class(double x) conflicts with C++ keyword on rs/6000
3208 */
3209fix = {
3210    hackname  = rs6000_double;
3211    files     = math.h;
3212    select    = '[^a-zA-Z_]class\(';
3213
3214    c_fix     = format;
3215    c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
3216    c_fix_arg = '^.*[^a-zA-Z_]class\(.*';
3217
3218    test_text = "extern int class();";
3219};
3220
3221/*
3222 *  Wrong fchmod prototype on RS/6000.
3223 */
3224fix = {
3225    hackname  = rs6000_fchmod;
3226    files     = sys/stat.h;
3227    select    = 'fchmod\(char \*';
3228    c_fix     = format;
3229    c_fix_arg = "fchmod(int";
3230    test_text = "extern int fchmod(char *, mode_t);";
3231};
3232
3233/*
3234 *  parameters conflict with C++ new on rs/6000
3235 */
3236fix = {
3237    hackname  = rs6000_param;
3238    files     = "stdio.h";
3239    files     = "unistd.h";
3240
3241    select    = 'rename\(const char \*old, const char \*new\)';
3242    c_fix     = format;
3243    c_fix_arg = 'rename(const char *_old, const char *_new)';
3244
3245    test_text = 'extern int rename(const char *old, const char *new);';
3246};
3247
3248/*
3249 *  Solaris 10+ <sys/feature_tests.h> defines _RESTRICT_KYWD as restrict
3250 *  for C99.  This is wrong for C++, which needs many C99 features, but
3251 *  only supports __restrict.
3252 */
3253fix = {
3254    hackname  = solaris___restrict;
3255    files     = sys/feature_tests.h;
3256    select    = "#define[ \t]*_RESTRICT_KYWD[ \t]*restrict";
3257    mach      = "*-*-solaris2*";
3258    c_fix     = format;
3259    c_fix_arg = "#ifdef __cplusplus\n#define\t_RESTRICT_KYWD\t__restrict\n"
3260    	        "#else\n%0\n#endif";
3261    test_text = "#define	_RESTRICT_KYWD	restrict";
3262};
3263
3264/*
3265 * Solaris 10+ complex.h defines _Complex_I and _Imaginary_I in terms of
3266 * themselves, which are Sun Studio compiler intrinsics.  Remove _Imaginary_I
3267 * and imaginary definitions which are not supported by GCC.
3268 */
3269fix = {
3270    hackname  = solaris_complex;
3271    mach      = "*-*-solaris2.*";
3272    files     = complex.h;
3273    select    = "#define[ \t]_Complex_I[ \t]_Complex_I";
3274    sed	      = "s/#define[ \t]_Complex_I[ \t]_Complex_I/"
3275		"#define\t_Complex_I\t(__extension__ 1.0iF)/";
3276    sed	      = "/#define[ \t]_Imaginary_I[ \t]_Imaginary_I/d";
3277    sed	      = "/#define[ \t]imaginary[ \t]_Imaginary/d";
3278    sed       = "s/#define[ \t]I[ \t]\\{1,\\}_Imaginary_I/#define\tI\t\t_Complex_I/";
3279    test_text = "#define	_Complex_I	_Complex_I\n"
3280    		"#define	complex		_Complex\n"
3281		"#define	_Imaginary_I	_Imaginary_I\n"
3282		"#define	imaginary	_Imaginary\n"
3283		"#undef	I\n"
3284		"#define	I		_Imaginary_I";
3285};
3286
3287/*
3288 * Solaris 10+ <complex.h> is wrapped in #ifndef __cplusplus.  Wrap in
3289 * extern "C" instead so libstdc++ can use it.
3290 */
3291fix = {
3292    hackname  = solaris_complex_cxx;
3293    mach      = "*-*-solaris2.*";
3294    files     = complex.h;
3295    sed	      = "/#if[ \t]*!defined(__cplusplus)/c\\\n"
3296    		"#ifdef\t__cplusplus\\\nextern \"C\" {\\\n#endif";
3297    sed	      = "/#endif[ \t]*\\/\\* !defined(__cplusplus) \\*\\//c\\\n"
3298		"#ifdef\t__cplusplus\\\n}\\\n#endif";
3299    test_text = "#if !defined(__cplusplus)\n"
3300		"#endif	/* !defined(__cplusplus) */";
3301};
3302
3303/*
3304 *  g++ rejects functions declared with both C and C++ linkage.
3305 */
3306fix = {
3307    hackname  = solaris_cxx_linkage;
3308    mach      = '*-*-solaris2*';
3309    files     = "iso/stdlib_iso.h";
3310    select    = "(#if __cplusplus >= 199711L)\n"
3311	        "(extern \"C\\+\\+\" \\{\n)"
3312	        "(.*(bsearch|qsort).*)";
3313    c_fix     = format;
3314    c_fix_arg = "%1 && !__GNUG__\n%2%3";
3315
3316    test_text =
3317    "#if __cplusplus >= 199711L\n"
3318    "extern \"C++\" {\n"
3319    "	void *bsearch(const void *, const void *, size_t, size_t,";
3320};
3321
3322/*
3323 *  Solaris <iso/stdio_iso.h> doesn't declare getc for C++ with
3324 *  _STRICT_STDC, but uses it.
3325 */
3326fix = {
3327    hackname  = solaris_getc_strict_stdc;
3328    mach      = "*-*-solaris2*";
3329    files     = "iso/stdio_iso.h";
3330    select    = "(.*&& )!defined\\(_STRICT_STDC\\)(.*)";
3331    c_fix     = format;
3332    c_fix_arg = "%1(!defined(_STRICT_STDC) || (__cplusplus >= 199711L))%2";
3333
3334    test_text =
3335    "#if	!defined(_REENTRANT) && !defined(_LP64) && !defined(_STRICT_STDC)";
3336};
3337
3338/*
3339 * Sun Solaris 2 has a version of sys/int_const.h that defines
3340 * UINT8_C and UINT16_C to unsigned constants.
3341 */
3342fix = {
3343    hackname  = solaris_int_const;
3344    files     = sys/int_const.h;
3345    mach      = '*-*-solaris2*';
3346    c_fix     = format;
3347    c_fix_arg = "#define\tUINT8_C(c)\t(c)\n"
3348                "%1\n"
3349                "#define\tUINT16_C(c)\t(c)";
3350    select    = "^#define[ \t]+UINT8_C\\(c\\)[ \t]+__CONCAT__.*\n"
3351                "(/\*.*\*/)\n"
3352                "#define[ \t]+UINT16_C\\(c\\)[ \t]+__CONCAT__.*";
3353    test_text =
3354    "#define	UINT8_C(c)	__CONCAT__(c,u)\n"
3355    "/* CSTYLED */\n"
3356    "#define	UINT16_C(c)	__CONCAT__(c,u)";
3357};
3358
3359/*
3360 * Sun Solaris 2 has a version of sys/int_limits.h that defines
3361 * UINT8_MAX and UINT16_MAX to unsigned constants.
3362 */
3363fix = {
3364    hackname  = solaris_int_limits_1;
3365    files     = sys/int_limits.h;
3366    mach      = '*-*-solaris2*';
3367    c_fix     = format;
3368    c_fix_arg = "#define\tUINT8_MAX\t(255)\n"
3369                "#define\tUINT16_MAX\t(65535)";
3370    select    = "^#define[ \t]+UINT8_MAX[ \t]+\\(255U\\)\n"
3371                "#define[ \t]+UINT16_MAX[ \t]+\\(65535U\\)";
3372    test_text =
3373    "#define	UINT8_MAX	(255U)\n"
3374    "#define	UINT16_MAX	(65535U)";
3375};
3376
3377/*
3378 * Sun Solaris 2 has a version of sys/int_limits.h that defines
3379 * INT_FAST16 limits to wrong values for sys/int_types.h.
3380 */
3381fix = {
3382    hackname  = solaris_int_limits_2;
3383    files     = sys/int_limits.h;
3384    mach      = '*-*-solaris2*';
3385    c_fix     = format;
3386    c_fix_arg = "#define\t%1_FAST16_%2 %132_%2";
3387    select    = "^#define[ \t]+(INT|UINT)_FAST16_(MAX|MIN)[ \t](INT|UINT)16.*";
3388    test_text =
3389    "#define	INT_FAST16_MAX INT16_MAX\n"
3390    "#define	UINT_FAST16_MAX UINT16_MAX\n"
3391    "#define	INT_FAST16_MIN	INT16_MIN";
3392};
3393
3394/*
3395 * Sun Solaris 2 has a version of sys/int_limits.h that defines
3396 * SIZE_MAX as unsigned long.
3397 */
3398fix = {
3399    hackname  = solaris_int_limits_3;
3400    files     = sys/int_limits.h;
3401    mach      = '*-*-solaris2*';
3402    c_fix     = format;
3403    c_fix_arg = "#define\tSIZE_MAX\t4294967295U";
3404    select    = "^#define[ \t]+SIZE_MAX[ \t]+4294967295UL";
3405    test_text =
3406    "#define	SIZE_MAX	4294967295UL";
3407};
3408
3409/*
3410 * Sun Solaris up to 9 has a version of sys/int_types.h that forbids use
3411 * of Standard C99 64-bit types in 32-bit mode.
3412 */
3413fix = {
3414    hackname  = solaris_int_types;
3415    select    = "__STDC__ - 0 == 0";
3416    bypass    = "_LONGLONG_TYPE";
3417    files     = sys/int_types.h;
3418    c_fix     = format;
3419    c_fix_arg =
3420    "(defined(_STDC_C99) || !defined(_STRICT_STDC) || defined(__GNUC__))";
3421    test_text =
3422    "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3423    "typedef	long long		int64_t;\n"
3424    "#endif\n\n"
3425    "#if defined(_LP64) || (__STDC__ - 0 == 0 && !defined(_NO_LONGLONG))\n"
3426    "typedef int64_t			intmax_t;\n"
3427    "#endif";
3428};
3429
3430/*
3431 *  Before Solaris 10, <iso/setjmp_iso.h> doesn't mark longjump noreturn.
3432 */
3433fix = {
3434    hackname  = solaris_longjmp_noreturn;
3435    mach      = "*-*-solaris2*";
3436    files     = "iso/setjmp_iso.h";
3437    bypass    = "__NORETURN";
3438    select    = "(.*longjmp\\(jmp_buf.*[^)]+\\));";
3439    c_fix     = format;
3440    c_fix_arg = "%1 __attribute__ ((__noreturn__));";
3441
3442    test_text = "extern void longjmp(jmp_buf, int);";
3443};
3444
3445/*
3446 * Sun Solaris 10 defines several C99 math macros in terms of
3447 * builtins specific to the Studio compiler, in particular not
3448 * compatible with the GNU compiler.
3449 */
3450fix = {
3451    hackname = solaris_math_1;
3452    select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3453    bypass = "__GNUC__";
3454    files = iso/math_c99.h;
3455    c_fix = format;
3456    c_fix_arg = "#define\tHUGE_VA%1\t(__builtin_huge_va%2())";
3457    c_fix_arg = "^#define[ \t]+HUGE_VA([LF]+)[ \t]+__builtin_huge_va([lf]+)";
3458    test_text =
3459    '#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"'"\n"
3460    "#undef	HUGE_VAL\n"
3461    "#define	HUGE_VAL	__builtin_huge_val\n"
3462    "#undef	HUGE_VALF\n"
3463    "#define	HUGE_VALF	__builtin_huge_valf\n"
3464    "#undef	HUGE_VALL\n"
3465    "#define	HUGE_VALL	__builtin_huge_vall";
3466};
3467
3468/*
3469 * On Solaris 11, if you do isinf(NaN) you'll get a floating point
3470 * exception.  Provide an alternative using GCC's builtin.
3471 */
3472fix = {
3473    hackname  = solaris_math_10;
3474    select    = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3475    files     = iso/math_c99.h;
3476    c_fix     = format;
3477    c_fix_arg = "#define\tisinf(x) __builtin_isinf(x)";
3478    c_fix_arg = "^#define[ \t]+isinf\\(x\\)[ \t]+__extension__\\([ \t]*\\\\\n"
3479                "[ \t]*\\{[ \t]*__typeof\\(x\\)[ \t]*__x_i[ \t]*=[ \t]*\\(x\\);"
3480                    "[ \t]*\\\\\n"
3481                "[ \t]*__x_i[ \t]*==[ \t]*\\(__typeof\\(__x_i\\)\\)[ \t]*"
3482                    "INFINITY[ \t]*\\|\\|[ \t]*\\\\\n"
3483                "[ \t]*__x_i[ \t]*==[ \t]*\\(__typeof\\(__x_i\\)\\)[ \t]*"
3484                    "\\(-INFINITY\\);[ \t]*\\}\\)";
3485    test_text =
3486    '#pragma ident	"@(#)math_c99.h	1.12	07/01/21 SMI"'"\n"
3487    "#undef	isinf\n"
3488    "#define	isinf(x)	__extension__( \\\\\n"
3489    "			{ __typeof(x) __x_i = (x); \\\\\n"
3490    "			__x_i == (__typeof(__x_i)) INFINITY || \\\\\n"
3491    "			__x_i == (__typeof(__x_i)) (-INFINITY); })";
3492};
3493
3494/*
3495 * Solaris math INFINITY
3496 */
3497fix = {
3498    hackname = solaris_math_2;
3499    select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3500    bypass = "__GNUC__";
3501    files = iso/math_c99.h;
3502    c_fix = format;
3503    c_fix_arg = "#define\tINFINITY\t(__builtin_inff())";
3504    c_fix_arg = "^#define[ \t]+INFINITY[ \t]+__builtin_infinity";
3505    test_text =
3506    '#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"'"\n"
3507    "#undef	INFINITY\n"
3508    "#define	INFINITY	__builtin_infinity";
3509};
3510
3511/*
3512 * Solaris math NAN
3513 */
3514fix = {
3515    hackname = solaris_math_3;
3516    select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3517    bypass = "__GNUC__";
3518    files = iso/math_c99.h;
3519    c_fix = format;
3520    c_fix_arg = "#define\tNAN\t\t(__builtin_nanf(\"\"))";
3521    c_fix_arg = "^#define[ \t]+NAN[ \t]+__builtin_nan";
3522    test_text =
3523    '#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"'"\n"
3524    "#undef	NAN\n"
3525    "#define	NAN	__builtin_nan";
3526};
3527
3528/*
3529 * Solaris math fpclassify
3530 */
3531fix = {
3532    hackname = solaris_math_4;
3533    select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3534    bypass = "__GNUC__";
3535    files = iso/math_c99.h;
3536    c_fix = format;
3537    c_fix_arg = "#define\tfpclassify(x) \\\n"
3538                "  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, "
3539                    "FP_SUBNORMAL, FP_ZERO, (x))";
3540    c_fix_arg = "^#define[ \t]+fpclassify\\(x\\)[ \t]+__builtin_fpclassify\\(x\\)";
3541    test_text =
3542    '#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"'"\n"
3543    "#undef	fpclassify\n"
3544    "#define	fpclassify(x)	__builtin_fpclassify(x)";
3545};
3546
3547/*
3548 * Solaris math signbit
3549 */
3550fix = {
3551    hackname = solaris_math_8;
3552    select = '@\(#\)math_c99\.h' "[ \t]+1\\.[0-9]+[ \t]+[0-9/]+ SMI";
3553    bypass = "__GNUC__";
3554    files = iso/math_c99.h;
3555    c_fix = format;
3556    c_fix_arg = "#define\tsignbit(x)\t(sizeof(x) == sizeof(float) \\\n"
3557                "\t\t\t   ? __builtin_signbitf(x) \\\n"
3558                "\t\t\t   : sizeof(x) == sizeof(long double) \\\n"
3559                "\t\t\t     ? __builtin_signbitl(x) \\\n"
3560                "\t\t\t     : __builtin_signbit(x))";
3561    c_fix_arg = "^#define[ \t]+signbit\\(x\\)[ \t]+__builtin_signbit\\(x\\)";
3562    test_text = <<- _EOText_
3563	#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"
3564	#undef	signbit
3565	#define	signbit(x)	__builtin_signbit(x)
3566	_EOText_;
3567};
3568
3569/*
3570 * Solaris math comparison macros
3571 */
3572fix = {
3573    hackname = solaris_math_9;
3574    select = '@\(#\)math_c99.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3575    bypass = "__GNUC__";
3576    files = iso/math_c99.h;
3577    c_fix = format;
3578    c_fix_arg = "#define\t%1(x, y)%2__builtin_%1(x, y)";
3579    c_fix_arg = "^#define[ \t]+([a-z]+)\\(x, y\\)([ \t]+)\\(\\(x\\) "
3580                    "__builtin_[a-z]+\\(y\\)\\)";
3581    test_text =
3582    '#ident	"@(#)math_c99.h	1.9	04/11/01 SMI"'"\n"
3583    "#undef	isgreater\n"
3584    "#define	isgreater(x, y)		((x) __builtin_isgreater(y))\n"
3585    "#undef	isgreaterequal\n"
3586    "#define	isgreaterequal(x, y)	((x) __builtin_isgreaterequal(y))\n"
3587    "#undef	isless\n"
3588    "#define	isless(x, y)		((x) __builtin_isless(y))\n"
3589    "#undef	islessequal\n"
3590    "#define	islessequal(x, y)	((x) __builtin_islessequal(y))\n"
3591    "#undef	islessgreater\n"
3592    "#define	islessgreater(x, y)	((x) __builtin_islessgreater(y))\n"
3593    "#undef	isunordered\n"
3594    "#define	isunordered(x, y)	((x) __builtin_isunordered(y))";
3595};
3596
3597/*
3598 * Sun Solaris defines PTHREAD_MUTEX_INITIALIZER with a trailing
3599 * "0" for the last field of the pthread_mutex_t structure, which is
3600 * of type upad64_t, which itself is typedef'd to int64_t, but with
3601 * __STDC__ defined (e.g. by -ansi) it is a union. So change the
3602 * initializer to "{0}" instead
3603 */
3604fix = {
3605    hackname = solaris_mutex_init_2;
3606    select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3607    files = pthread.h;
3608    /*
3609     * On Solaris 10, this fix is unnecessary because upad64_t is
3610     * always defined correctly regardless of the definition of the
3611     * __STDC__ macro.  The first "mach" pattern matches up to
3612     * solaris9.  The second "mach" pattern will not match any two (or
3613     * more) digit solaris version, but it will match e.g. 2.5.1.
3614     */
3615    mach = '*-*-solaris2.[0-9]', '*-*-solaris2.[0-9][!0-9]*';
3616    c_fix = format;
3617    c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3618                "%0\n"
3619                "#else\n"
3620                "%1, {0}}%4\n"
3621                "#endif";
3622    c_fix_arg = "(^#define[ \t]+PTHREAD_(MUTEX|COND)_INITIALIZER[ \t]+"
3623                "(|/\*.*\*/[ \t]*\\\\\n[ \t]*)\\{.*)"
3624                ",[ \t]*0\\}" "(|[ \t].*)$";
3625    test_text =
3626    '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3627    "#define PTHREAD_MUTEX_INITIALIZER\t{{{0},0}, {{{0}}}, 0}\n"
3628    "#define PTHREAD_COND_INITIALIZER\t{{{0}, 0}, 0}\t/* DEFAULTCV */\n"
3629    "#define	PTHREAD_MUTEX_INITIALIZER		/* = DEFAULTMUTEX */	\\\\\n"
3630    "	{{0, 0, 0, DEFAULT_TYPE, _MUTEX_MAGIC}, {{{0}}}, 0}\n"
3631    "#define	PTHREAD_COND_INITIALIZER		/* = DEFAULTCV */	\\\\\n"
3632    "	{{{0, 0, 0, 0}, DEFAULT_TYPE, _COND_MAGIC}, 0}";
3633};
3634
3635/*
3636 * Sun Solaris defines PTHREAD_ONCE_INIT as an array containing a
3637 * structure.  As such, it need two levels of brackets, but only
3638 * contains one.  Wrap the macro definition in an extra layer.
3639 */
3640fix = {
3641    hackname = solaris_once_init_1;
3642    select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3643    files = pthread.h;
3644    mach = '*-*-solaris*';
3645    c_fix = format;
3646    c_fix_arg = "%1{%2}%3";
3647    c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{)([^}]+)(\\})[ \t]*$";
3648    test_text =
3649    '#pragma ident	"@(#)pthread.h	1.37	04/09/28 SMI"'"\n"
3650    "#define PTHREAD_ONCE_INIT\t{0, 0, 0, PTHREAD_ONCE_NOTDONE}";
3651};
3652
3653/*
3654 * Sun Solaris defines PTHREAD_ONCE_INIT with a "0" for some
3655 *  fields of the pthread_once_t structure, which are of type
3656 *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
3657 *  defined (e.g. by -ansi) it is a union. So change the initializer
3658 *  to "{0}" instead.  This test relies on solaris_once_init_1.
3659 */
3660fix = {
3661    hackname = solaris_once_init_2;
3662    select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3663    files = pthread.h;
3664    /*
3665     * On Solaris 10, this fix is unnecessary because upad64_t is
3666     * always defined correctly regardless of the definition of the
3667     * __STDC__ macro.  The first "mach" pattern matches up to
3668     * solaris9.  The second "mach" pattern will not match any two (or
3669     * more) digit solaris version, but it will match e.g. 2.5.1.
3670     */
3671    mach = '*-*-solaris2.[0-9]', '*-*-solaris2.[0-9][!0-9]*';
3672    c_fix = format;
3673    c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3674                "%0\n"
3675                "#else\n"
3676                "%1{0}, {0}, {0}, {%3}%4\n"
3677                "#endif";
3678    c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{\\{)"
3679                "(0, 0, 0, )(PTHREAD_[A-Z_]+)(\\}\\})[ \t]*$";
3680    test_text =
3681    '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3682    "#define PTHREAD_ONCE_INIT\t{{0, 0, 0, PTHREAD_ONCE_NOTDONE}}\n";
3683};
3684
3685/*
3686 * Solaris 10+ <spawn.h> uses char *const argv[_RESTRICT_KYWD] in the
3687 * posix_spawn declarations, which doesn't work with C++.
3688 */
3689fix = {
3690    hackname  = solaris_posix_spawn_restrict;
3691    files     = spawn.h;
3692    mach      = '*-*-solaris2*';
3693    c_fix     = format;
3694    c_fix_arg = "%1*_RESTRICT_KYWD %2%3";
3695    select    = "(.*[ \t]+)([a-z]+)\\[_RESTRICT_KYWD\\](.*)";
3696    test_text =
3697    "char *const argv[_RESTRICT_KYWD],\n"
3698    "char *const envp[_RESTRICT_KYWD]);";
3699};
3700
3701/*
3702 *  The pow overloads with int were removed in C++ 2011 DR 550.
3703 */
3704fix = {
3705    hackname  = solaris_pow_int_overload;
3706    mach      = '*-*-solaris2*';
3707    files     = "iso/math_iso.h";
3708    select    = "^[ \t]*inline [a-z ]* pow\\([^()]*, int [^()]*\\)"
3709		" *\\{[^{}]*\n[^{}]*\\}";
3710    c_fix     = format;
3711    c_fix_arg = "#if __cplusplus < 201103L\n%0\n#endif";
3712
3713    test_text =
3714    "	inline long double pow(long double __X, int __Y) { return\n"
3715    "		__powl(__X, (long double) (__Y)); }";
3716};
3717
3718/*
3719 * Sun Solaris defines PTHREAD_RWLOCK_INITIALIZER with a "0" for some
3720 *  fields of the pthread_rwlock_t structure, which are of type
3721 *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
3722 *  defined (e.g. by -ansi) it is a union. So change the initializer
3723 *  to "{0}" instead.
3724 */
3725fix = {
3726    hackname = solaris_rwlock_init_1;
3727    select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
3728    files = pthread.h;
3729    mach = '*-*-solaris*';
3730    c_fix = format;
3731    c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
3732                "%0\n"
3733                "#else\n"
3734                "%1{0, 0, 0, {{0}, {0}, {0}}, {{0}, {0}}, {{0}, {0}}}\n"
3735                "#endif";
3736    c_fix_arg = "(^#define[ \t]+PTHREAD_RWLOCK_INITIALIZER[ \t]+)"
3737                "\\{0, 0, 0, \\{0, 0, 0\\}, \\{0, 0\\}, \\{0, 0\\}\\}[ \t]*$";
3738
3739    test_text =
3740    '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
3741    "#define PTHREAD_RWLOCK_INITIALIZER\t{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}";
3742};
3743
3744/*
3745 * Before Solaris 10, <stdio.h> lacks declarations of std::__filbuf and
3746 * std::__flsbuf, but <iso/stdio_iso.h> uses them.
3747 */
3748fix = {
3749    hackname  = solaris_std___filbuf;
3750    files     = stdio.h;
3751    mach      = '*-*-solaris2*';
3752    bypass    = "using std::__filbuf";
3753    select    = "(using std::perror;\n)(#endif)";
3754    c_fix     = format;
3755    c_fix_arg = "%1#ifndef _LP64\n"
3756		"using std::__filbuf;\n"
3757		"using std::__flsbuf;\n"
3758		"#endif\n%2";
3759
3760    test_text = "using std::perror;\n"
3761		"#endif";
3762};
3763
3764/*
3765 * Sun Solaris 8 has what appears to be some gross workaround for
3766 * some old version of their c++ compiler.  G++ doesn't want it
3767 * either, but doesn't want to be tied to SunPRO version numbers.
3768 */
3769fix = {
3770    hackname = solaris_stdio_tag;
3771    files    = stdio_tag.h;
3772
3773    select   = '__cplusplus < 54321L';
3774    /* In Solaris 10, the code in stdio_tag.h is conditionalized on
3775       "!defined(__GNUC__)" so we no longer need to fix it.  */
3776    bypass   = '__GNUC__';
3777    sed      = 's/defined(__cplusplus) && (__cplusplus < 54321L)/0/';
3778
3779    test_text = "#if\tdefined(__cplusplus) && (__cplusplus < 54321L)";
3780};
3781
3782/*
3783 * On Solaris 9, __va_list needs to become a typedef for
3784 * __builtin_va_list to make -Wmissing-format-attribute work.
3785 */
3786fix = {
3787    hackname = solaris_sys_va_list;
3788    files    = sys/va_list.h;
3789    mach     = '*-*-solaris2.9';
3790    select   = "#if.*__STDC__.*\n"
3791	       "typedef void \\*__va_list;\n"
3792	       "#else\n"
3793	       "typedef char \\*__va_list;\n"
3794	       "#endif";
3795
3796    c_fix    = format;
3797    c_fix_arg = "#ifdef __GNUC__\n"
3798		"typedef __builtin_va_list __va_list;\n"
3799		"#else\n"
3800		"%0\n"
3801		"#endif";
3802    test_text = "#if defined(__STDC__) && !defined(__ia64)\n"
3803    		"typedef void *__va_list;\n"
3804	        "#else\n"
3805	        "typedef char *__va_list;\n"
3806	        "#endif";
3807};
3808
3809/*
3810 *  a missing semi-colon at the end of the statsswtch structure definition.
3811 */
3812fix = {
3813    hackname  = statsswtch;
3814    files     = rpcsvc/rstat.h;
3815    select    = "boottime$";
3816    c_fix     = format;
3817    c_fix_arg = "boottime;";
3818    test_text = "struct statswtch {\n  int boottime\n};";
3819};
3820
3821/*
3822 *  Arrange for stdio.h to use stdarg.h to define __gnuc_va_list.
3823 *  On 4BSD-derived systems, stdio.h defers to machine/ansi.h; that's
3824 *  OK too.
3825 */
3826fix = {
3827    hackname = stdio_stdarg_h;
3828    files    = stdio.h;
3829    bypass   = "include.*(stdarg\.h|machine/ansi\.h)";
3830    /*
3831     * On Solaris 10, this fix is unncessary; <stdio.h> includes
3832     * <iso/stdio_iso.h>, which includes <sys/va_list.h>.
3833      */
3834    mach     = '*-*-solaris2.1[0-9]*';
3835    not_machine = true;
3836
3837    c_fix     = wrap;
3838
3839    c_fix_arg = "#define __need___va_list\n#include <stdarg.h>\n";
3840
3841    test_text = "";
3842};
3843
3844/*
3845 *  Don't use or define the name va_list in stdio.h.  This is for
3846 *  ANSI.  Note _BSD_VA_LIST_ is dealt with elsewhere.  The presence
3847 *  of __gnuc_va_list, __DJ_va_list, or _G_va_list is taken to
3848 *  indicate that the header knows what it's doing -- under SUSv2,
3849 *  stdio.h is required to define va_list, and we shouldn't break
3850 *  that.
3851 */
3852fix = {
3853    hackname = stdio_va_list;
3854    files    = stdio.h;
3855    bypass   = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
3856    /*
3857     * On Solaris 10, the definition in
3858     * <stdio.h> is guarded appropriately by the _XPG4 feature macro;
3859     * there is therefore no need for this fix there.
3860     */
3861    mach = '*-*-solaris2.1[0-9]*';
3862    not_machine = true;
3863
3864    /*
3865     * Use __gnuc_va_list in arg types in place of va_list.
3866     * On 386BSD use __gnuc_va_list instead of _VA_LIST_.  On Tru64 UNIX V5.1A
3867     * use __gnuc_va_list instead of __VA_LIST__.  We're hoping the
3868     * trailing parentheses and semicolon save all other systems from this.
3869     * Define __not_va_list__ (something harmless and unused)
3870     * instead of va_list.
3871     * Don't claim to have defined va_list.
3872     */
3873    sed = "s@[ \t]va_list\\([ \t)]\\)@ __gnuc_va_list\\1@\n"
3874	  "s@(va_list)&@(__gnuc_va_list)\\&@\n"
3875          "s@ _VA_LIST_));@ __gnuc_va_list));@\n"
3876          "s@ __VA_LIST__));@ __gnuc_va_list));@\n"
3877          "s@ va_list@ __not_va_list__@\n"
3878          "s@\\*va_list@*__not_va_list__@\n"
3879          "s@ __va_list)@ __gnuc_va_list)@\n"
3880          "s@typedef[ \t]\\(.*\\)[ \t]va_list[ \t]*;"
3881           "@typedef \\1 __not_va_list__;@\n"
3882	  "s@typedef[ \t]*__va_list__@typedef __gnuc_va_list@\n"
3883          "s@GNUC_VA_LIST@GNUC_Va_LIST@\n"
3884          "s@_VA_LIST_DEFINED@_Va_LIST_DEFINED@\n"
3885          "s@_NEED___VA_LIST@_NEED___Va_LIST@\n"
3886          "s@VA_LIST@DUMMY_VA_LIST@\n"
3887          "s@_Va_LIST@_VA_LIST@";
3888    test_text = "extern void mumble( va_list);";
3889};
3890
3891/*
3892 *  Fix headers that use va_list from stdio.h to use the updated
3893 *  va_list from the stdio_va_list change.  Note _BSD_VA_LIST_ is
3894 *  dealt with elsewhere.  The presence of __gnuc_va_list,
3895 *  __DJ_va_list, or _G_va_list is taken to indicate that the header
3896 *  knows what it's doing.
3897 */
3898fix = {
3899    hackname = stdio_va_list_clients;
3900    files    = com_err.h;
3901    files    = cps.h;
3902    files    = curses.h;
3903    files    = krb5.h;
3904    files    = lc_core.h;
3905    files    = pfmt.h;
3906    files    = wchar.h;
3907    files    = curses_colr/curses.h;
3908    bypass   = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
3909    /* Don't fix, if we use va_list from stdarg.h, or if the use is
3910       otherwise protected.  */
3911    bypass   = 'include <stdarg\.h>|#ifdef va_start';
3912
3913    /*
3914     * Use __gnuc_va_list in arg types in place of va_list.
3915     * On 386BSD use __gnuc_va_list instead of _VA_LIST_.  On Tru64 UNIX V5.1A
3916     * use __gnuc_va_list instead of __VA_LIST__.  We're hoping the
3917     * trailing parentheses and semicolon save all other systems from this.
3918     * Define __not_va_list__ (something harmless and unused)
3919     * instead of va_list.
3920     * Don't claim to have defined va_list.
3921     */
3922    sed = "s@[ \t]va_list\\([ \t)]\\)@ __gnuc_va_list\\1@\n"
3923	  "s@(va_list)&@(__gnuc_va_list)\\&@\n"
3924          "s@ _VA_LIST_));@ __gnuc_va_list));@\n"
3925          "s@ __VA_LIST__));@ __gnuc_va_list));@\n"
3926          "s@ va_list@ __not_va_list__@\n"
3927          "s@\\*va_list@*__not_va_list__@\n"
3928          "s@ __va_list)@ __gnuc_va_list)@\n"
3929          "s@typedef[ \t]\\(.*\\)[ \t]va_list[ \t]*;"
3930           "@typedef \\1 __not_va_list__;@\n"
3931	  "s@typedef[ \t]*__va_list__@typedef __gnuc_va_list@\n"
3932          "s@GNUC_VA_LIST@GNUC_Va_LIST@\n"
3933          "s@_VA_LIST_DEFINED@_Va_LIST_DEFINED@\n"
3934          "s@_NEED___VA_LIST@_NEED___Va_LIST@\n"
3935          "s@VA_LIST@DUMMY_VA_LIST@\n"
3936          "s@_Va_LIST@_VA_LIST@";
3937    test_text = "extern void mumble( va_list);";
3938};
3939
3940/*
3941 *  "!__STDC__" or "__STDC__==0" or "__STDC__!=1" or "__STDC__-0==0"
3942 *  is "!defined( __STRICT_ANSI__ )"
3943 */
3944fix = {
3945    hackname = strict_ansi_not;
3946    select   = "^([ \t]*#[ \t]*if.*)"
3947               "(!__STDC__"
3948               "|__STDC__[ \t]*==[ \t]*0"
3949               "|__STDC__[ \t]*!=[ \t]*1"
3950               "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*0)";
3951    /* Tru64 UNIX V4.0F/V5.1 <standards.h> supports GCC usage of __STDC__. */
3952    bypass = 'GNU and MIPS C compilers define __STDC__ differently';
3953    /* GNU gmp.h uses "__STDC__ != 1" only if __SCO_VERSION__, which
3954       is not defined by GCC, so it is safe.  */
3955    bypass = '__SCO_VERSION__.*__STDC__ != 1';
3956    c_test   = stdc_0_in_system_headers;
3957
3958    c_fix     = format;
3959    c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
3960
3961    test_text = "#if !__STDC__ \n"
3962                "#if __STDC__ == 0\n"
3963                "#if __STDC__ != 1\n"
3964                "#if __STDC__ - 0 == 0"
3965               "/* not std C */\nint foo;\n"
3966               "\n#end-end-end-end-if :-)";
3967};
3968
3969/*
3970 *  "__STDC__-0==0"
3971 *  is "!defined( __STRICT_ANSI__ )" on continued #if-s
3972 */
3973fix = {
3974    hackname = strict_ansi_not_ctd;
3975    files    = math.h, limits.h, stdio.h, signal.h,
3976               stdlib.h, sys/signal.h, time.h;
3977    /*
3978     * Starting at the beginning of a line, skip white space and
3979     * a leading "(" or "&&" or "||".  One of those must be found.
3980     * Then, zero, one or more copies of a "defined(_FOO_BAR_) &&"
3981     * expression.  If these are nested, then they must accumulate
3982     * because we won't match any closing parentheses.  Finally,
3983     * after skipping over all that, we must then match our suspect
3984     * phrase:  "__STDC__-0==0" with or without white space.
3985     */
3986    select   = "^([ \t]*" '(\(|&&|\|\|)'
3987               "([ \t(]*!*[ \t]*defined\\([a-zA-Z_0-9]+\\)[ \t]*[|&][|&])*"
3988               "[ \t(]*)"
3989               "(__STDC__[ \t]*(|-[ \t]*0[ \t]*)==[ \t]*0)";
3990    c_test   = stdc_0_in_system_headers;
3991
3992    c_fix     = format;
3993    c_fix_arg = "%1 !defined(__STRICT_ANSI__)";
3994
3995    test_text = "#if 1 && \\\\\n"
3996               "&& defined(mumbling) |& (__STDC__ - 0 == 0) \\\\\n"
3997               "( __STDC__ == 0 && !defined(_XOPEN_SOURCE) \\\\\n"
3998               "|| __STDC__ - 0 == 0 ) /* not std C */\n"
3999               "int foo;\n#endif";
4000};
4001
4002/*
4003 *  "__STDC__!=0" or "__STDC__==1" or "__STDC__-0==1"
4004 *  is "defined( __STRICT_ANSI__ )"
4005 */
4006fix = {
4007    hackname = strict_ansi_only;
4008    select   = "^([ \t]*#[ \t]*if.*)"
4009               "(__STDC__[ \t]*!=[ \t]*0"
4010               "|__STDC__[ \t]*==[ \t]*1"
4011               "|__STDC__[ \t]*-[ \t]*0[ \t]*==[ \t]*1"
4012               "|__STDC__[ \t]*-[ \t]*0[ \t]*!=[ \t]*0)";
4013    c_test   = stdc_0_in_system_headers;
4014
4015    c_fix     = format;
4016    c_fix_arg = "%1 defined(__STRICT_ANSI__)";
4017
4018    test_text = "#if __STDC__ == 1 /* is std C\n */\nint foo;\n#endif";
4019};
4020
4021/*
4022 *  IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s
4023 *  in prototype without previous definition.
4024 */
4025fix = {
4026    hackname  = struct_file;
4027    files     = rpc/xdr.h;
4028    select    = '^.*xdrstdio_create.*struct __file_s';
4029    c_fix     = format;
4030    c_fix_arg = "struct __file_s;\n%0";
4031    test_text = "extern void xdrstdio_create( struct __file_s* );";
4032};
4033
4034/*
4035 *  IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr
4036 *  in prototype without previous definition.
4037 *
4038 *  Don't fix OpenBSD, which uses struct sockaddr_in prototyping the same
4039 *  function, and does define it.
4040 */
4041fix = {
4042    hackname  = struct_sockaddr;
4043    files     = rpc/auth.h;
4044    select    = "^.*authdes_create.*struct sockaddr[^_]";
4045    bypass    = "<sys/socket\.h>";
4046    bypass    = "struct sockaddr;\n";
4047    c_fix     = format;
4048    c_fix_arg = "struct sockaddr;\n%0";
4049    test_text = "extern AUTH* authdes_create( struct sockaddr* );";
4050};
4051
4052/*
4053 *  Apply fix this to all OSs since this problem seems to effect
4054 *  more than just SunOS.
4055 */
4056fix = {
4057    hackname = sun_auth_proto;
4058    files    = rpc/auth.h;
4059    files    = rpc/clnt.h;
4060    files    = rpc/svc.h;
4061    files    = rpc/xdr.h;
4062    bypass   = "__cplusplus";
4063    /*
4064     *  Select those files containing '(*name)()'.
4065     */
4066    select    = '\(\*[a-z][a-z_]*\)\(\)';
4067
4068    c_fix     = format;
4069    c_fix_arg = "#ifdef __cplusplus\n%1(...);%2\n"
4070                "#else\n%1();%2\n#endif";
4071    c_fix_arg = '(.*\(\*[a-z][a-z_]*\))\(\);(.*)';
4072
4073    test_text =
4074    "struct auth_t {\n"
4075    "    int (*name)(); /* C++ bad */\n"
4076    "};";
4077};
4078
4079/*
4080 *  Fix bogus #ifdef on SunOS 4.1.
4081 */
4082fix = {
4083    hackname  = sun_bogus_ifdef;
4084    files     = "hsfs/hsfs_spec.h";
4085    files     = "hsfs/iso_spec.h";
4086    select    = '#ifdef(.*\|\|.*)';
4087    c_fix     = format;
4088    c_fix_arg = "#if%1";
4089
4090    test_text = "#ifdef  __i386__ || __vax__ || __sun4c__";
4091};
4092
4093/*
4094 *  Fix the CAT macro in SunOS memvar.h.
4095 */
4096fix = {
4097    hackname  = sun_catmacro;
4098    files     = pixrect/memvar.h;
4099    select    = "^#define[ \t]+CAT\\(a,b\\).*";
4100    c_fix     = format;
4101
4102    c_fix_arg =
4103    "#ifdef __STDC__\n"
4104    "#  define CAT(a,b) a##b\n"
4105    "#else\n%0\n#endif";
4106
4107    test_text =
4108    "#define CAT(a,b)\ta/**/b";
4109};
4110
4111/*
4112 *  Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
4113 *  Also fix return type of {m,re}alloc in <malloc.h> on sysV68
4114 */
4115fix = {
4116    hackname = sun_malloc;
4117    files    = malloc.h;
4118    bypass   = "_CLASSIC_ANSI_TYPES";
4119
4120    sed   = "s/typedef[ \t]char \\*\tmalloc_t/typedef void \\*\tmalloc_t/g";
4121    sed   = "s/int[ \t][ \t]*free/void\tfree/g";
4122    sed   = "s/char\\([ \t]*\\*[ \t]*malloc\\)/void\\1/g";
4123    sed   = "s/char\\([ \t]*\\*[ \t]*realloc\\)/void\\1/g";
4124    sed   = "s/char\\([ \t]*\\*[ \t]*calloc\\)/void\\1/g";
4125
4126    test_text =
4127    "typedef char *\tmalloc_t;\n"
4128    "int \tfree();\n"
4129    "char*\tmalloc();\n"
4130    "char*\tcalloc();\n"
4131    "char*\trealloc();";
4132};
4133
4134/*
4135 *  Check for yet more missing ';' in struct (in SunOS 4.0.x)
4136 */
4137fix = {
4138    hackname = sun_rusers_semi;
4139    files    = rpcsvc/rusers.h;
4140    select   = "_cnt$";
4141    sed      = "/^struct/,/^};/s/_cnt$/_cnt;/";
4142    test_text = "struct mumble\n  int _cnt\n};";
4143};
4144
4145/*
4146 *  signal.h on SunOS defines signal using (),
4147 *  which causes trouble when compiling with g++ -pedantic.
4148 */
4149fix = {
4150    hackname = sun_signal;
4151    files    = sys/signal.h;
4152    files    = signal.h;
4153    select   = "^void\t" '\(\*signal\(\)\)\(\);.*';
4154
4155    c_fix     = format;
4156    c_fix_arg =
4157          "#ifdef __cplusplus\n"
4158          "void\t(*signal(...))(...);\n"
4159          "#else\n%0\n#endif";
4160
4161    test_text = "void\t(*signal())();";
4162};
4163
4164/*
4165 *  Correct the return type for strlen in strings.h in SunOS 4.
4166 */
4167fix = {
4168    hackname = sunos_strlen;
4169    files    = strings.h;
4170    select   = "int[ \t]*strlen\\(\\);(.*)";
4171    c_fix     = format;
4172    c_fix_arg = "__SIZE_TYPE__ strlen();%1";
4173    test_text = " int\tstrlen(); /* string length */";
4174};
4175
4176/*
4177 *  Linux kernel's vt.h breaks C++
4178 */
4179fix = {
4180    hackname  = suse_linux_vt_cxx;
4181    files     = linux/vt.h;
4182
4183    select    = "^[ \t]*unsigned int new;";
4184    c_fix     = format;
4185    c_fix_arg = "unsigned int newev;";
4186
4187    test_text = "        unsigned int new;      /* New console (if changing) */";
4188};
4189
4190/*
4191 *  Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
4192 *  that is visible to any ANSI compiler using this include.  Simply
4193 *  delete the lines that #define some string functions to internal forms.
4194 */
4195fix = {
4196    hackname = svr4_disable_opt;
4197    files    = string.h;
4198    select   = '#define.*__std_hdr_';
4199    sed      = '/#define.*__std_hdr_/d';
4200    test_text = "#define strlen __std_hdr_strlen\n";
4201};
4202
4203/*
4204 *   Fix broken decl of getcwd present on some svr4 systems.
4205 */
4206fix = {
4207    hackname = svr4_getcwd;
4208    files    = stdlib.h;
4209    files    = unistd.h;
4210    files    = prototypes.h;
4211    select   = 'getcwd\(char \*, int\)';
4212
4213    c_fix     = format;
4214    c_fix_arg = "getcwd(char *, size_t)";
4215
4216    test_text = "extern char* getcwd(char *, int);";
4217};
4218
4219/*
4220 *   Fix broken decl of profil present on some svr4 systems.
4221 */
4222fix = {
4223    hackname = svr4_profil;
4224    files    = stdlib.h;
4225    files    = unistd.h;
4226
4227    select    =
4228    'profil\(unsigned short \*, unsigned int, unsigned int, unsigned int\)';
4229    c_fix     = format;
4230    c_fix_arg = 'profil(unsigned short *, size_t, int, unsigned int)';
4231
4232    test_text =
4233    'profil(unsigned short *, unsigned int, unsigned int, unsigned int);';
4234};
4235
4236/*
4237 * Correct types for signal handler constants like SIG_DFL; they might be
4238 * void (*) (), and should be void (*) (int).  C++ doesn't like the
4239 * old style.
4240 */
4241fix = {
4242    hackname = svr4_sighandler_type;
4243    files = sys/signal.h;
4244    select = 'void *\(\*\)\(\)';
4245    c_fix = format;
4246    c_fix_arg = "void (*)(int)";
4247    test_text = "#define SIG_DFL (void(*)())0\n"
4248                "#define SIG_IGN (void (*)())0\n";
4249};
4250
4251/*
4252 *  Some SysV r4 systems, including Sequent's DYNIX/ptx, use the local
4253 *  function 'getrnge' in <regexp.h> before they declare it.  For these
4254 *  systems add a 'static int' declaration of 'getrnge' into <regexp.h>
4255 *  early on.
4256 *
4257 *  'getrnge' traditionally manipulates a file-scope global called 'size',
4258 *  so put the declaration right after the declaration of 'size'.
4259 *
4260 *  Don't do this if there is already a `static void getrnge' declaration
4261 *  present, since this would cause a redeclaration error.  Solaris 2.x has
4262 *  such a declaration.
4263 */
4264fix = {
4265    hackname  = svr4_undeclared_getrnge;
4266    files     = regexp.h;
4267    select    = "getrnge";
4268    bypass    = "static void getrnge";
4269    c_fix     = format;
4270    c_fix_arg = "%0\n"
4271                "static int getrnge ();";
4272    c_fix_arg = "^static int[ \t]+size;";
4273    test_text = "static int size;\n"
4274                "/* stuff which calls getrnge() */\n"
4275                "static getrnge()\n"
4276                "{}";
4277};
4278
4279/*
4280 *  Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
4281 *  in string.h on sysV68
4282 *  Correct the return type for strlen in string.h on Lynx.
4283 *  Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
4284 *  Add missing const for strdup on OSF/1 V3.0.
4285 *  On sysV88 layout is slightly different.
4286 */
4287fix = {
4288    hackname = sysv68_string;
4289    files    = testing.h;
4290    files    = string.h;
4291    bypass   = "_CLASSIC_ANSI_TYPES";
4292
4293    sed = "s/extern[ \t]*int[ \t]*strlen();/extern unsigned int strlen();/";
4294    sed = "s/extern[ \t]*int[ \t]*ffs[ \t]*(long);/extern int ffs(int);/";
4295    sed = "s/strdup(char \\*s1);/strdup(const char *s1);/";
4296
4297    sed = "/^extern char$/N";
4298    sed = "s/^extern char\\(\\n\t\\*memccpy(),\\)$/extern void\\1/";
4299
4300    sed = "/^extern int$/N";
4301    sed = "s/^extern int\\(\\n\tstrlen(),\\)/extern size_t\\1/";
4302
4303    sed = "/^\tstrncmp(),$/N";
4304    sed = 's/^\(' "\t" 'strncmp()\),\n\(' "\t" 'strlen(),\)$/'
4305            '\1;' "\\\nextern unsigned int\\\n\\2/";
4306
4307    test_text =
4308    "extern int strlen();\n"
4309
4310    "extern int ffs(long);\n"
4311
4312    "extern char\n"
4313    "\t*memccpy(),\n"
4314    "\tmemcpy();\n"
4315
4316    "extern int\n"
4317    "\tstrcmp(),\n"
4318    "\tstrncmp(),\n"
4319    "\tstrlen(),\n"
4320    "\tstrspn();\n"
4321
4322    "extern int\n"
4323    "\tstrlen(), strspn();";
4324};
4325
4326/*
4327 *  Fix return type of calloc, malloc, realloc, bsearch and exit
4328 */
4329fix = {
4330    hackname = sysz_stdlib_for_sun;
4331    files    = stdlib.h;
4332    bypass   = "_CLASSIC_ANSI_TYPES";
4333
4334    select    = "char[ \t]*\\*[ \t]*(calloc|malloc|realloc|bsearch)[ \t]*\\(";
4335    c_fix     = format;
4336    c_fix_arg = "void *\t%1(";
4337
4338    test_text =
4339    "extern char*\tcalloc(size_t);\n"
4340    "extern char*\tmalloc(size_t);\n"
4341    "extern char*\trealloc(void*,size_t);\n"
4342    "extern char*\tbsearch(void*,size_t,size_t);\n";
4343};
4344
4345/*
4346 * __thread is now a keyword.
4347 */
4348fix = {
4349    hackname  = thread_keyword;
4350    files     = "pthread.h";
4351    files     = bits/sigthread.h, '*/bits/sigthread.h';
4352    select    = "([* ])__thread([,)])";
4353    c_fix     = format;
4354    c_fix_arg = "%1__thr%2";
4355
4356    test_text =
4357	"extern int pthread_create (pthread_t *__restrict __thread,\n"
4358	"extern int pthread_kill (pthread_t __thread, int __signo);\n"
4359	"extern int pthread_cancel (pthread_t __thread);";
4360};
4361
4362/*
4363 *  if the #if says _cplusplus, not the double underscore __cplusplus
4364 *  that it should be
4365 */
4366fix = {
4367    hackname = tinfo_cplusplus;
4368    files    = tinfo.h;
4369    select   = "[ \t]_cplusplus";
4370
4371    c_fix     = format;
4372    c_fix_arg = " __cplusplus";
4373    test_text = "#ifdef _cplusplus\nint bogus;\n#endif";
4374};
4375
4376/*
4377 *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
4378 */
4379fix = {
4380    hackname  = ultrix_const;
4381    files     = stdio.h;
4382    select    = 'perror\( char \*';
4383
4384    c_fix     = format;
4385    c_fix_arg = "%1 const %3 *__";
4386    c_fix_arg = "([ \t*](perror|fputs|fwrite|scanf|fscanf)\\(.*)"
4387                "[ \t]+(char|void) \\*__";
4388
4389    test_text =
4390    "extern void perror( char *__s );\n"
4391    "extern int fputs( char *__s, FILE *);\n"
4392    "extern size_t fwrite( void *__ptr, size_t, size_t, FILE *);\n"
4393    "extern int fscanf( FILE *__stream, char *__format, ...);\n"
4394    "extern int scanf( char *__format, ...);\n";
4395};
4396
4397/*
4398 *  parameters not const on DECstation Ultrix V4.0 and OSF/1.
4399 */
4400fix = {
4401    hackname  = ultrix_const2;
4402    files     = stdio.h;
4403
4404    select    = '\*fopen\( char \*';
4405    c_fix     = format;
4406    c_fix_arg = "%1( const char *%3, const char *";
4407    c_fix_arg = "([ \t*](fopen|sscanf|popen|tempnam))\\("
4408               "[ \t]*char[ \t]*\\*([^,]*),"
4409               "[ \t]*char[ \t]*\\*[ \t]*";
4410
4411    test_text =
4412    "extern FILE *fopen( char *__filename, char *__type );\n"
4413    "extern int sscanf( char *__s, char *__format, ...);\n"
4414    "extern FILE *popen(char *, char *);\n"
4415    "extern char *tempnam(char*,char*);\n";
4416};
4417
4418/*
4419 *  Fix definitions of macros used by va-i960.h in VxWorks header file.
4420 */
4421fix = {
4422    hackname  = va_i960_macro;
4423    files     = arch/i960/archI960.h;
4424    select    = "__(vsiz|vali|vpad|alignof__)";
4425
4426    c_fix     = format;
4427    c_fix_arg = "__vx%1";
4428
4429    test_text =
4430    "extern int __vsiz vsiz;\n"
4431    "extern int __vali vali;\n"
4432    "extern int __vpad vpad;\n"
4433    "#define __alignof__(x) ...";
4434};
4435
4436/*
4437 * On VMS, add missing braces around sigset_t constants.
4438 */
4439fix = {
4440    hackname  = vms_add_missing_braces;
4441    select    = "(_SIG_[A-Z]+_SET[ \t]+= \\{)(0x[0F]+, 0x[0F]+)";
4442    mach      = "*-*-*vms*";
4443    files     = "rtldef/signal.h";
4444    c_fix     = format;
4445
4446    c_fix_arg = '%1 {%2} ';
4447
4448    test_text = "static const __sigset_t _SIG_EMPTY_SET  = "
4449                "{0x00000000, 0x00000000},\n"
4450                " _SIG_FULL_SET   = {0xFFFFFFFF, 0xFFFFFFFF};\n";
4451};
4452
4453/*
4454 * On VMS, some DEC-C builtins are directly used.
4455 */
4456fix = {
4457    hackname  = vms_decc_builtin;
4458    select    = "(__MEMSET|__MEMMOVE|__MEMCPY|__STRLEN|__STRCPY)";
4459    mach      = "*-*-*vms*";
4460    files     = rtldef/string.h, rtldef/time.h, rtldef/strings.h,
4461                rtldef/socket.h;
4462    sed       = "s@__MEMSET@memset@";
4463    sed       = "s@__MEMMOVE@memmove@";
4464    sed       = "s@__MEMCPY@memcpy@";
4465    sed       = "s@__STRLEN@strlen@";
4466    sed       = "s@__STRCPY@strcpy@";
4467
4468    test_text = "define FD_ZERO(__p) __MEMSET((__p), 0, sizeof(*(__p)))\n";
4469};
4470
4471/*
4472 *  Define __CAN_USE_EXTERN_PREFIX on vms.
4473 */
4474fix = {
4475    hackname  = vms_define_can_use_extern_prefix;
4476    files     = "rtldef/decc$types.h";
4477    select    = "#[ \t]*else\n"
4478		"#[ \t]*if defined\\(__DECCXX\\)\n"
4479		"#[ \t]*define __CAN_USE_EXTERN_PREFIX 1\n";
4480    mach      = "*-*-*vms*";
4481    c_fix     = format;
4482
4483    c_fix_arg = "%0"
4484		"#    elif defined (__GNUC__)\n"
4485		"#\tdefine __CAN_USE_EXTERN_PREFIX 1\n";
4486
4487    test_text = "# else\n"
4488		"#    if defined(__DECCXX)\n"
4489		"#\tdefine __CAN_USE_EXTERN_PREFIX 1\n"
4490		"#    endif\n"
4491		"# endif\n";
4492};
4493
4494/*
4495 * On VMS, disable the use of dec-c string builtins
4496 */
4497fix = {
4498    hackname  = vms_disable_decc_string_builtins;
4499    select    = "#if !defined\\(__VAX\\)\n";
4500    mach      = "*-*-*vms*";
4501    files     = "rtldef/string.h";
4502    c_fix     = format;
4503
4504    c_fix_arg = "#if !defined(__VAX) && !defined(__GNUC__)\n";
4505
4506    test_text = "#if !defined(__VAX)\n";
4507};
4508
4509/*
4510 * On VMS, fix incompatible redeclaration of hostalias.
4511 */
4512fix = {
4513    hackname  = vms_do_not_redeclare_hostalias;
4514    select    = "(void[ \t]+fp_nquery \\(const u_char \\*, int, FILE \\*\\);)\n"
4515                "(__char_ptr32[ \t]+hostalias \\(const char \\*\\);)";
4516    mach      = "*-*-*vms*";
4517    files     = "rtldef/resolv.h";
4518    c_fix     = format;
4519
4520    c_fix_arg = "%1\n"
4521                "/* %2 */";
4522
4523    test_text = "void		fp_nquery (const u_char *, int, FILE *);\n"
4524                "__char_ptr32	hostalias (const char *);\n";
4525};
4526
4527/*
4528 * On VMS, forward declare structure before referencing them in prototypes.
4529 */
4530fix = {
4531    hackname  = vms_forward_declare_struct;
4532    select    = "(/\\* forward decls for C\\+\\+ \\*/\n)"
4533                "#ifdef __cplusplus\n";
4534    mach      = "*-*-*vms*";
4535    files     = rtldef/if.h;
4536    c_fix     = format;
4537
4538    c_fix_arg = "%1"
4539                "#if defined (__cplusplus) || defined (__GNUC__)\n";
4540
4541    test_text = "/* forward decls for C++ */\n"
4542                "#ifdef __cplusplus\n"
4543                "struct foo;\n"
4544                "#endif\n";
4545};
4546
4547/*
4548 * On VMS, do not declare getopt and al if pointers are 64 bit.
4549 */
4550fix = {
4551    hackname  = vms_no_64bit_getopt;
4552    select    = "^[ \t]*(extern[ \t]*)?(int[ \t]*(getopt|optind|opterr|optopt)"
4553                "|(char \\*optarg))([ \t]*\\(.*\\))?;\n";
4554    mach      = "*-*-*vms*";
4555    files     = rtldef/stdio.h, rtldef/unistd.h;
4556    c_fix     = format;
4557
4558    c_fix_arg = <<- _EOArg_
4559	#if __INITIAL_POINTER_SIZE != 64 /* getopt is short ptr only.  */
4560	%0#endif
4561
4562	_EOArg_;
4563
4564    test_text = "int getopt (int, char * const [], const char *);";
4565};
4566
4567/*
4568 * On VMS, force the use of fast setjmp, as the normal setjmp uses conditions
4569 * which is not yet fully supported by gcc.
4570 */
4571fix = {
4572    hackname  = vms_use_fast_setjmp;
4573    select    = "(#[ \t]*if[ \t]*defined\\(__FAST_SETJMP\\)[ \t]*\\|\\|)";
4574    mach      = "*-*-*vms*";
4575    files     = rtldef/setjmp.h;
4576    c_fix     = format;
4577
4578    c_fix_arg = "%0 defined (__GNUC__) ||";
4579
4580    test_text = "#   if defined(__FAST_SETJMP) || defined(__UNIX_SETJMP)";
4581};
4582
4583/*
4584 * On VMS, use pragma extern_model instead of VAX-C keywords.
4585 */
4586fix = {
4587    hackname  = vms_use_pragma_extern_model;
4588    select    = "#if defined\\(__DECC\\) \\|\\| defined\\(__DECCXX\\)\n"
4589		"# pragma extern_model __save\n";
4590    mach      = "*-*-*vms*";
4591    c_fix     = format;
4592
4593    c_fix_arg = "#if defined(__DECC) || defined(__DECCXX) || defined(__GNUC__)\n"
4594		"# pragma extern_model __save\n";
4595
4596    test_text = "#if defined(__DECC) || defined(__DECCXX)\n"
4597		"# pragma extern_model __save\n"
4598		"# pragma extern_model strict_refdef\n"
4599		"   extern struct x zz$yy;\n"
4600		"# pragma extern_model __restore\n"
4601		"#endif\n";
4602};
4603
4604/*
4605 * On VMS, change <resource.h> to <sys/resource.h> to avoid a
4606 * conflict while building gcc.  Likewise for <builtins.h>
4607 */
4608fix = {
4609    hackname  = vms_use_quoted_include;
4610    select    = "(#[ \t]*include[ \t]+)<(resource|builtins)\\.h>";
4611    mach      = "*-*-*vms*";
4612    files     = rtldef/wait.h, starlet_c/pthread.h;
4613    c_fix     = format;
4614
4615    c_fix_arg = '%1<sys/%2.h>';
4616
4617    test_text = "#   include <resource.h>";
4618};
4619
4620/*
4621 *  AIX and Interix headers define NULL to be cast to a void pointer,
4622 *  which is illegal in ANSI C++.
4623 */
4624fix = {
4625    hackname  = void_null;
4626    files     = curses.h, dbm.h, locale.h, stdio.h, stdlib.h, string.h,
4627    time.h, unistd.h, sys/dir.h, sys/param.h, sys/types.h;
4628    /* avoid changing C++ friendly NULL */
4629    bypass    = __cplusplus;
4630    bypass    = __null;
4631    select    = "^#[ \t]*define[ \t]+NULL[ \t]+\\(\\(void[ \t]*\\*\\)0\\)";
4632    c_fix     = format;
4633    c_fix_arg = <<- _EOFix_
4634	#ifndef NULL
4635	#ifdef __cplusplus
4636	#ifdef __GNUG__
4637	#define NULL __null
4638	#else /* ! __GNUG__  */
4639	#define NULL 0L
4640	#endif /* __GNUG__  */
4641	#else /* ! __cplusplus  */
4642	#define NULL ((void *)0)
4643	#endif /* __cplusplus  */
4644	#endif /* !NULL  */
4645	_EOFix_;
4646    test_text = "# define\tNULL \t((void *)0)  /* typed NULL */";
4647};
4648
4649/*
4650 *  Make VxWorks header which is almost gcc ready fully gcc ready.
4651 */
4652fix = {
4653    hackname = vxworks_gcc_problem;
4654    files    = types/vxTypesBase.h;
4655    select   = "__GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__";
4656
4657    sed = "s/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/"
4658          "#if 1/";
4659
4660    sed = "/[ \t]size_t/i\\\n"
4661        "#ifndef _GCC_SIZE_T\\\n"
4662        "#define _GCC_SIZE_T\n";
4663
4664    sed = "/[ \t]size_t/a\\\n"
4665        "#endif\n";
4666
4667    sed = "/[ \t]ptrdiff_t/i\\\n"
4668        "#ifndef _GCC_PTRDIFF_T\\\n"
4669        "#define _GCC_PTRDIFF_T\n";
4670
4671    sed = "/[ \t]ptrdiff_t/a\\\n"
4672        "#endif\n";
4673
4674    sed = "/[ \t]wchar_t/i\\\n"
4675        "#ifndef _GCC_WCHAR_T\\\n"
4676        "#define _GCC_WCHAR_T\n";
4677
4678    sed = "/[ \t]wchar_t/a\\\n"
4679        "#endif\n";
4680
4681    test_text =
4682    "#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__\n"
4683    "typedef unsigned int size_t;\n"
4684    "typedef long ptrdiff_t;\n"
4685    "typedef unsigned short wchar_t;\n"
4686    "#endif /* __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__ */\n";
4687};
4688
4689/*
4690 *  Wrap VxWorks ioctl to keep everything pretty
4691 */
4692fix = {
4693    hackname    = vxworks_ioctl_macro;
4694    files       = ioLib.h;
4695    mach        = "*-*-vxworks*";
4696
4697    c_fix       = format;
4698    c_fix_arg   = "%0\n"
4699        "#define ioctl(fd, func, arg) (ioctl)(fd, func, (int)(arg))\n";
4700    c_fix_arg   = "extern[\t ]+int[\t ]+ioctl[\t ]*\\([\t ,[:alnum:]]*\\);";
4701
4702    test_text   = "extern int ioctl ( int asdf1234, int jkl , int qwerty ) ;";
4703};
4704
4705/*
4706 *  Wrap VxWorks mkdir to be posix compliant
4707 */
4708fix = {
4709    hackname    = vxworks_mkdir_macro;
4710    files       = sys/stat.h;
4711    mach        = "*-*-vxworks*";
4712
4713    c_fix       = format;
4714    c_fix_arg   = "%0\n"
4715                "#define mkdir(dir, ...) ((void)0, ##__VA_ARGS__, (mkdir)(dir))\n";
4716    c_fix_arg   = "extern[\t ]+STATUS[\t ]+mkdir[\t ]*"
4717                "\\([\t ]*const[\t ]+char[\t ]*\\*[\t ]*" /* arg type */
4718                "(|[_[:alpha:]][_[:alnum:]]*)" /* arg name (optional) */
4719                "\\)[\t ]*;";
4720
4721    test_text   = "extern STATUS mkdir (const char * _qwerty) ;";
4722};
4723
4724/*
4725 *  Fix VxWorks <time.h> to not require including <vxTypes.h>.
4726 */
4727fix = {
4728    hackname  = vxworks_needs_vxtypes;
4729    files     = time.h;
4730    select    = "uint_t([ \t]+_clocks_per_sec)";
4731    c_fix     = format;
4732    c_fix_arg = "unsigned int%1";
4733    test_text = "uint_t\t_clocks_per_sec;";
4734};
4735
4736/*
4737 *  Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
4738 */
4739fix = {
4740    hackname = vxworks_needs_vxworks;
4741    files    = sys/stat.h;
4742    test     = " -r types/vxTypesOld.h";
4743    test     = " -n \"`egrep '#include' $file`\"";
4744    test     = " -n \"`egrep ULONG $file`\"";
4745    select   = "#[ \t]define[ \t]+__INCstath";
4746
4747    sed = "/#[ \t]define[ \t][ \t]*__INCstath/a\\\n"
4748          "#include <types/vxTypesOld.h>\n";
4749
4750    test_text = "`touch types/vxTypesOld.h`"
4751    "#include </dev/null> /* ULONG */\n"
4752    "# define\t__INCstath <sys/stat.h>";
4753};
4754
4755/*
4756 *  Make it so VxWorks does not include gcc/regs.h accidentally
4757 */
4758fix = {
4759    hackname    = vxworks_regs;
4760    mach        = "*-*-vxworks*";
4761
4762    select      = "#[\t ]*include[\t ]+[<\"]regs.h[>\"]";
4763    c_fix       = format;
4764    c_fix_arg   = "#include <arch/../regs.h>";
4765
4766    test_text   = "#include <regs.h>\n";
4767};
4768
4769/*
4770 *  Another bad dependency in VxWorks 5.2 <time.h>.
4771 */
4772fix = {
4773    hackname = vxworks_time;
4774    files    = time.h;
4775    test     = " -r vxWorks.h";
4776
4777    select    = "#[ \t]*define[ \t]+VOIDFUNCPTR[ \t].*";
4778    c_fix     = format;
4779
4780    c_fix_arg =
4781    "#ifndef __gcc_VOIDFUNCPTR_defined\n"
4782    "#ifdef __cplusplus\n"
4783    "typedef void (*__gcc_VOIDFUNCPTR) (...);\n"
4784    "#else\n"
4785    "typedef void (*__gcc_VOIDFUNCPTR) ();\n"
4786    "#endif\n"
4787    "#define __gcc_VOIDFUNCPTR_defined\n"
4788    "#endif\n"
4789    "#define VOIDFUNCPTR __gcc_VOIDFUNCPTR";
4790
4791    test_text = "`touch vxWorks.h`"
4792                "#define VOIDFUNCPTR (void(*)())";
4793};
4794
4795/*
4796 *  This hack makes write const-correct on VxWorks
4797 */
4798fix = {
4799    hackname    = vxworks_write_const;
4800    files       = ioLib.h;
4801    mach        = "*-*-vxworks*";
4802
4803    c_fix       = format;
4804    c_fix_arg   = "extern int  write (int, const char*, size_t);";
4805    c_fix_arg   = "extern[\t ]+int[\t ]+write[\t ]*\\("
4806                "[\t ]*int[\t ]*,"
4807                "[\t ]*char[\t ]*\\*[\t ]*,"
4808                "[\t ]*size_t[\t ]*\\)[\t ]*;";
4809
4810    test_text       = "extern int write ( int , char * , size_t ) ;";
4811};
4812
4813/*
4814 *  There are several name conflicts with C++ reserved words in X11 header
4815 *  files.  These are fixed in some versions, so don't do the fixes if
4816 *  we find __cplusplus in the file.  These were found on the RS/6000.
4817 */
4818fix = {
4819    hackname  = x11_class;
4820    files     = X11/ShellP.h;
4821    bypass    = __cplusplus;
4822    select    = "^([ \t]*char \\*)class;(.*)";
4823    c_fix     = format;
4824    c_fix_arg = "#ifdef __cplusplus\n%1c_class;%2\n"
4825                "#else\n%1class;%2\n#endif";
4826    test_text =
4827    "struct {\n"
4828    "   char *class;\n"
4829    "} mumble;\n";
4830};
4831
4832/*
4833 *  class in Xm/BaseClassI.h
4834 */
4835fix = {
4836    hackname = x11_class_usage;
4837    files    = Xm/BaseClassI.h;
4838    bypass   = "__cplusplus";
4839
4840    select    = " class\\)";
4841    c_fix     = format;
4842    c_fix_arg = " c_class)";
4843
4844    test_text = "extern mumble (int  class);\n";
4845};
4846
4847/*
4848 *  new in Xm/Traversal.h
4849 */
4850fix = {
4851    hackname = x11_new;
4852    files    = Xm/Traversal.h;
4853    bypass   = __cplusplus;
4854
4855    sed      = "/Widget\told, new;/i\\\n"
4856                   "#ifdef __cplusplus\\\n"
4857                   "\\\tWidget\told, c_new;\\\n"
4858                   "#else\n";
4859
4860    sed      = "/Widget\told, new;/a\\\n"
4861                   "#endif\n";
4862
4863    sed      = "s/Widget new,/Widget c_new,/g";
4864    test_text =
4865    "struct wedge {\n"
4866    "   Widget\told, new;\n"
4867    "};\nextern Wedged( Widget new, Widget old );";
4868};
4869
4870/*
4871 *  Incorrect sprintf declaration in X11/Xmu.h
4872 */
4873fix = {
4874    hackname = x11_sprintf;
4875    files    = X11/Xmu.h;
4876    files    = X11/Xmu/Xmu.h;
4877    select   = "^extern char \\*\tsprintf\\(\\);$";
4878
4879    c_fix     = format;
4880    c_fix_arg = "#ifndef __STDC__\n%0\n#endif /* !defined __STDC__ */";
4881
4882    test_text = "extern char *\tsprintf();";
4883};
4884/*EOF*/
4885