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