2 # Install modified versions of certain ANSI-incompatible
3 # native System V Release 4 system include files.
4 # Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
5 # Contributed by Ron Guilmette (rfg@monkeys.com).
7 # This file is part of GNU CC.
9 # GNU CC is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # GNU CC is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU CC; see the file COPYING. If not, write to
21 # the Free Software Foundation, 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA.
24 # This script munges the native include files provided with System V
25 # Release 4 systems so as to remove things which are violations of the
26 # ANSI C standard. Once munged, the resulting new system include files
27 # are placed in a directory that GNU C will search *before* searching
28 # the /usr/include directory. This script should work properly for most
29 # System V Release 4 systems. For other types of systems, you should
30 # use the `fixincludes' script instead.
32 # See README-fixinc for more information.
34 # Directory containing the original header files.
35 INPUT
=${2-${INPUT-/usr/include}}
37 # Fail if no arg to specify a directory for the output.
39 then echo fixincludes
: no output directory specified
43 # Directory in which to store the results.
44 LIB
=${1?"fixincludes: output directory not specified"}
46 # Make sure it exists.
47 if [ ! -d $LIB ]; then
53 # Make LIB absolute if it is relative.
54 # Don't do this if not necessary, since may screw up automounters.
63 echo 'Building fixincludes in ' ${LIB}
65 # Determine whether this filesystem has symbolic links.
66 if ln -s X
$LIB/ShouldNotExist
2>/dev
/null
; then
67 rm -f $LIB/ShouldNotExist
73 echo 'Making directories:'
76 files
=`find . -follow -type d -print 2>/dev/null | sed '/^.$/d'`
78 files
=`find . -type d -print | sed '/^.$/d'`
80 for file in $files; do
82 if [ ! -d $LIB/$file ]
87 # treetops gets an alternating list
88 # of old directories to copy
89 # and the new directories to copy to.
90 treetops
="${INPUT} ${LIB}"
93 echo 'Making internal symbolic directory links'
94 for file in $files; do
95 dest
=`ls -ld $file | sed -n 's/.*-> //p'`
98 # In case $dest is relative, get to $file's dir first.
100 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
102 # Check that the target directory exists.
103 # Redirections changed to avoid bug in sh on Ultrix.
104 (cd $dest) > /dev
/null
2>&1
107 # X gets the dir that the link actually leads to.
109 # If link leads back into ${INPUT},
110 # make a similar link here.
111 if expr "$dest" : '[^/][^/]*' >/dev
/null
&& [ ! -h $dest ]; then
112 echo $file '->' $dest': Making link'
113 rm -fr ${LIB}/$file > /dev
/null
2>&1
114 ln -s $dest ${LIB}/$file > /dev
/null
2>&1
115 elif expr $x : "${INPUT}/.*" > /dev
/null
; then
116 # Y gets the actual target dir name, relative to ${INPUT}.
117 y
=`echo $x | sed -n "s&${INPUT}/&&p"`
118 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
120 sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
121 echo $file '->' $dots$y ': Making link'
122 rm -fr ${LIB}/$file > /dev
/null
2>&1
123 ln -s $dots$y ${LIB}/$file > /dev
/null
2>&1
124 elif expr $x : "${rwd}/.*" > /dev
/null
; then
125 # Y gets the actual target dir name, relative to the directory where the link is.
126 y
=`echo $x | sed -n "s&${rwd}/&&p"`
127 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
129 sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
130 echo $file '->' $dots$y ': Making link'
131 rm -fr ${LIB}/$file > /dev
/null
2>&1
132 ln -s $dots$y ${LIB}/$file > /dev
/null
2>&1
134 # If the link is to outside ${INPUT},
135 # treat this directory as if it actually contained the files.
136 # This line used to have $dest instead of $x.
137 # $dest seemed to be wrong for links found in subdirectories
138 # of ${INPUT}. Does this change break anything?
139 treetops
="$treetops $x ${LIB}/$file"
148 while [ $# != 0 ]; do
149 # $1 is an old directory to copy, and $2 is the new directory to copy to.
150 echo "Finding header files in $1:"
153 files
=`find . -name '*.h' -type f -print`
154 echo 'Checking header files:'
155 for file in $files; do
156 if [ -r $file ]; then
157 cp $file $2/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
161 # The following have been removed from the sed command below
162 # because it is more useful to leave these things in.
163 # The only reason to remove them was for -pedantic,
164 # which isn't much of a reason. -- rms.
167 # This code makes Solaris SCSI fail, because it changes the
168 # alignment within some critical structures. See <sys/scsi/impl/commands.h>.
169 # s/u_char\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
170 # Disable these also, since they probably aren't safe either.
171 # s/u_short\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
172 # s/ushort\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
173 # s/evcm_t\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
174 # s/Pbyte\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*SEQSIZ\)/unsigned int\1/
176 # The change of u_char, etc, to u_int
177 # applies to bit fields.
179 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
180 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
181 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
182 s%^\([ ]*#[ ]*endif\)[ ]*[^/ ].*%\1%
183 s/#lint(on)/defined(lint)/g
184 s/#lint(off)/!defined(lint)/g
185 s/#machine(\([^)]*\))/defined(__\1__)/g
186 s/#system(\([^)]*\))/defined(__\1__)/g
187 s/#cpu(\([^)]*\))/defined(__\1__)/g
188 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
189 /#[a-z]*if.*[ (]__i386\([^_]\)/ s/__i386/__i386__/g
190 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
191 /#[a-z]*if.*[ (!]__i860\([^_]\)/ s/__i860/__i860__/g
192 /#[a-z]*if.*[ (!]i860/ s/\([^_]\)i860/\1__i860__/g
193 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
194 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
195 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
196 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
197 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
198 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
199 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
200 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
201 s/__STDC__[ ][ ]*==[ ][ ]*0/!defined (__STRICT_ANSI__)/g
202 s/__STDC__[ ][ ]*==[ ][ ]*1/defined (__STRICT_ANSI__)/g
203 s/__STDC__[ ][ ]*!=[ ][ ]*0/defined (__STRICT_ANSI__)/g
204 s/__STDC__[ ][ ]*!=[ ][ ]*1/!defined (__STRICT_ANSI__)/g
205 s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
206 s/__STDC__ - 0 == 1/defined (__STRICT_ANSI__)/g
207 /^typedef[ ][ ]*[unsigned ]*long[ ][ ]*[u_]*longlong_t;/s/long/long long/
208 ' $2/$file > $2/$file.
sed
209 mv $2/$file.
sed $2/$file
210 if cmp $file $2/$file >/dev
/null
2>&1; then
220 # Install the proper definition of the three standard types in header files
221 # that they come from.
222 for file in sys
/types.h stdlib.h sys
/stdtypes.h stddef.h memory.h unistd.h
; do
223 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
224 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
225 chmod +w
${LIB}/$file 2>/dev
/null
226 chmod a
+r
${LIB}/$file 2>/dev
/null
229 if [ -r ${LIB}/$file ]; then
230 echo Fixing size_t
, ptrdiff_t and wchar_t
in $file
232 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]size_t/i\
233 #ifndef __SIZE_TYPE__\
234 #define __SIZE_TYPE__ long unsigned int\
237 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]size_t/typedef __SIZE_TYPE__ size_t/' \
238 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]ptrdiff_t/i\
239 #ifndef __PTRDIFF_TYPE__\
240 #define __PTRDIFF_TYPE__ long int\
243 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
244 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]wchar_t/i\
245 #ifndef __WCHAR_TYPE__\
246 #define __WCHAR_TYPE__ int\
249 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
250 ${LIB}/$file > ${LIB}/${file}.
sed
251 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
252 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
258 # Fix first broken decl of getcwd present on some svr4 systems.
261 base
=`basename $file`
262 if [ -r ${LIB}/$file ]; then
263 file_to_fix
=${LIB}/$file
265 if [ -r ${INPUT}/$file ]; then
266 file_to_fix
=${INPUT}/$file
271 if [ \
! -z "$file_to_fix" ]; then
272 echo Checking
$file_to_fix
273 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp
/$base
274 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
277 echo Fixed
$file_to_fix
279 cp /tmp
/$base ${LIB}/$file
280 chmod a
+r
${LIB}/$file
285 # Fix second broken decl of getcwd present on some svr4 systems. Also
286 # fix the incorrect decl of profil present on some svr4 systems.
289 base
=`basename $file`
290 if [ -r ${LIB}/$file ]; then
291 file_to_fix
=${LIB}/$file
293 if [ -r ${INPUT}/$file ]; then
294 file_to_fix
=${INPUT}/$file
299 if [ \
! -z "$file_to_fix" ]; then
300 echo Checking
$file_to_fix
301 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
302 |
sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp
/$base
303 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
306 echo Fixed
$file_to_fix
308 cp /tmp
/$base ${LIB}/$file
309 chmod a
+r
${LIB}/$file
314 # Fix the definition of NULL in <sys/param.h> so that it is conditional
315 # and so that it is correct for both C and C++.
318 base
=`basename $file`
319 if [ -r ${LIB}/$file ]; then
320 file_to_fix
=${LIB}/$file
322 if [ -r ${INPUT}/$file ]; then
323 file_to_fix
=${INPUT}/$file
328 if [ \
! -z "$file_to_fix" ]; then
329 echo Checking
$file_to_fix
330 cp $file_to_fix /tmp
/$base
333 sed -e '/^#define[ ]*NULL[ ]*0$/c\
337 #else /* !defined(__cplusplus) */\
338 #define __NULL_TYPE (void *)\
339 #endif /* !defined(__cplusplus) */\
340 #define NULL (__NULL_TYPE 0)\
341 #endif /* !defined(NULL) */' /tmp
/$base > /tmp
/$base.
sed
342 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
345 echo Fixed
$file_to_fix
347 cp /tmp
/$base.
sed ${LIB}/$file
348 chmod a
+r
${LIB}/$file
350 rm -f /tmp
/$base /tmp
/$base.
sed
353 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
354 # and so that it is correct for both C and C++.
357 base
=`basename $file`
358 if [ -r ${LIB}/$file ]; then
359 file_to_fix
=${LIB}/$file
361 if [ -r ${INPUT}/$file ]; then
362 file_to_fix
=${INPUT}/$file
367 if [ \
! -z "$file_to_fix" ]; then
368 echo Checking
$file_to_fix
369 cp $file_to_fix /tmp
/$base
371 sed -e '/^#define[ ]*NULL[ ]*0$/c\
374 #else /* !defined(__cplusplus) */\
375 #define __NULL_TYPE (void *)\
376 #endif /* !defined(__cplusplus) */\
377 #define NULL (__NULL_TYPE 0)' /tmp
/$base > /tmp
/$base.
sed
378 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
381 echo Fixed
$file_to_fix
383 cp /tmp
/$base.
sed ${LIB}/$file
384 chmod a
+r
${LIB}/$file
386 rm -f /tmp
/$base /tmp
/$base.
sed
389 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
390 # and so that it is correct for both C and C++.
393 base
=`basename $file`
394 if [ -r ${LIB}/$file ]; then
395 file_to_fix
=${LIB}/$file
397 if [ -r ${INPUT}/$file ]; then
398 file_to_fix
=${INPUT}/$file
403 if [ \
! -z "$file_to_fix" ]; then
404 echo Checking
$file_to_fix
405 cp $file_to_fix /tmp
/$base
407 sed -e '/^#define[ ]*NULL[ ]*((char \*) 0)$/c\
411 #else /* !defined(__cplusplus) */\
412 #define __NULL_TYPE (void *)\
413 #endif /* !defined(__cplusplus) */\
414 #define NULL (__NULL_TYPE 0)\
415 #endif /* !defined(NULL) */' /tmp
/$base > /tmp
/$base.
sed
416 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
419 echo Fixed
$file_to_fix
421 cp /tmp
/$base.
sed ${LIB}/$file
422 chmod a
+r
${LIB}/$file
424 rm -f /tmp
/$base /tmp
/$base.
sed
427 # Add a prototyped declaration of mmap to <sys/mman.h>.
430 base
=`basename $file`
431 if [ -r ${LIB}/$file ]; then
432 file_to_fix
=${LIB}/$file
434 if [ -r ${INPUT}/$file ]; then
435 file_to_fix
=${INPUT}/$file
440 if [ \
! -z "$file_to_fix" ]; then
441 echo Checking
$file_to_fix
442 cp $file_to_fix /tmp
/$base
444 sed -e '/^extern caddr_t mmap();$/c\
446 extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
447 #else /* !defined(__STDC__) */\
448 extern caddr_t mmap ();\
449 #endif /* !defined(__STDC__) */' /tmp
/$base > /tmp
/$base.
sed
450 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
453 echo Fixed
$file_to_fix
455 cp /tmp
/$base.
sed ${LIB}/$file
456 chmod a
+r
${LIB}/$file
458 rm -f /tmp
/$base /tmp
/$base.
sed
461 # Fix declarations of `ftw' and `nftw' in <ftw.h>. On some/most SVR4 systems
462 # the file <ftw.h> contains extern declarations of these functions followed
463 # by explicitly `static' definitions of these functions... and that's not
464 # allowed according to ANSI C. (Note however that on Solaris, this header
465 # file glitch has been pre-fixed by Sun. In the Solaris version of <ftw.h>
466 # there are no static definitions of any function so we don't need to do
467 # any of this stuff when on Solaris.
470 base
=`basename $file`
471 if [ -r ${LIB}/$file ]; then
472 file_to_fix
=${LIB}/$file
474 if [ -r ${INPUT}/$file ]; then
475 file_to_fix
=${INPUT}/$file
480 if test -z "$file_to_fix" ||
grep 'define ftw' $file_to_fix > /dev
/null
; then
481 # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
482 # one. Either way, we don't have to do anything.
485 echo Checking
$file_to_fix
486 cp $file_to_fix /tmp
/$base
488 sed -e '/^extern int ftw(const/i\
489 #if !defined(_STYPES)\
495 -e 's/extern \(int ftw(const.*\)$/\1/' \
496 -e '/^extern int nftw/i\
497 #if defined(_STYPES)\
503 -e 's/extern \(int nftw.*\)$/\1/' \
504 -e '/^extern int ftw(),/c\
505 #if !defined(_STYPES)\
511 #if defined(_STYPES)\
516 int nftw();' /tmp
/$base > /tmp
/$base.
sed
517 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
520 echo Fixed
$file_to_fix
522 cp /tmp
/$base.
sed ${LIB}/$file
523 chmod a
+r
${LIB}/$file
525 rm -f /tmp
/$base /tmp
/$base.
sed
528 # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
529 # g++, since it's now an official type in the C++ language.
531 base
=`basename $file`
532 if [ -r ${LIB}/$file ]; then
533 file_to_fix
=${LIB}/$file
535 if [ -r ${INPUT}/$file ]; then
536 file_to_fix
=${INPUT}/$file
542 if [ \
! -z "$file_to_fix" ]; then
543 echo Checking
$file_to_fix
544 cp $file_to_fix /tmp
/$base
546 sed -e 's,^typedef[ ]char[ ]bool;$,#ifndef __cplusplus\
548 #endif /* !defined __cplusplus */,' /tmp
/$base > /tmp
/$base.
sed
549 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
552 echo Fixed
$file_to_fix
554 cp /tmp
/$base.
sed ${LIB}/$file
555 chmod a
+r
${LIB}/$file
557 rm -f /tmp
/$base /tmp
/$base.
sed
560 # Add a `static' declaration of `getrnge' into <regexp.h>.
562 # Don't do this if there is already a `static void getrnge' declaration
563 # present, since this would cause a redeclaration error. Solaris 2.x has
564 # such a declaration.
567 base
=`basename $file`
568 if [ -r ${LIB}/$file ]; then
569 file_to_fix
=${LIB}/$file
571 if [ -r ${INPUT}/$file ]; then
572 file_to_fix
=${INPUT}/$file
577 if [ \
! -z "$file_to_fix" ]; then
578 echo Checking
$file_to_fix
579 if grep "static void getrnge" $file_to_fix > /dev
/null
; then
582 cp $file_to_fix /tmp
/$base
584 sed -e '/^static int[ ]*size;/c\
587 static int getrnge ();' /tmp
/$base > /tmp
/$base.
sed
588 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
591 echo Fixed
$file_to_fix
593 cp /tmp
/$base.
sed ${LIB}/$file
594 chmod a
+r
${LIB}/$file
597 rm -f /tmp
/$base /tmp
/$base.
sed
600 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
601 # that is visible to any ANSI compiler using this include. Simply
602 # delete the lines that #define some string functions to internal forms.
605 base
=`basename $file`
606 if [ -r ${LIB}/$file ]; then
607 file_to_fix
=${LIB}/$file
609 if [ -r ${INPUT}/$file ]; then
610 file_to_fix
=${INPUT}/$file
615 if [ \
! -z "$file_to_fix" ]; then
616 echo Checking
$file_to_fix
617 cp $file_to_fix /tmp
/$base
619 sed -e '/#define.*__std_hdr_/d' /tmp
/$base > /tmp
/$base.
sed
620 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
623 echo Fixed
$file_to_fix
625 cp /tmp
/$base.
sed ${LIB}/$file
626 chmod a
+r
${LIB}/$file
628 rm -f /tmp
/$base /tmp
/$base.
sed
631 # Delete any #defines of `__i386' which may be present in <ieeefp.h>. They
632 # tend to conflict with the compiler's own definition of this symbol. (We
633 # will use the compiler's definition.)
634 # Likewise __sparc, for Solaris, and __i860, and a few others
635 # (guessing it is necessary for all of them).
638 base
=`basename $file`
639 if [ -r ${LIB}/$file ]; then
640 file_to_fix
=${LIB}/$file
642 if [ -r ${INPUT}/$file ]; then
643 file_to_fix
=${INPUT}/$file
648 if [ \
! -z "$file_to_fix" ]; then
649 echo Checking
$file_to_fix
650 cp $file_to_fix /tmp
/$base
652 sed -e '/#define[ ]*__i386 /d' -e '/#define[ ]*__sparc /d' \
653 -e '/#define[ ]*__i860 /d' -e '/#define[ ]*__m88k /d' \
654 -e '/#define[ ]*__mips /d' -e '/#define[ ]*__m68k /d' \
655 /tmp
/$base > /tmp
/$base.
sed
656 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
659 echo Fixed
$file_to_fix
661 cp /tmp
/$base.
sed ${LIB}/$file
662 chmod a
+r
${LIB}/$file
664 rm -f /tmp
/$base /tmp
/$base.
sed
667 # Add a #define of _SIGACTION_ into <sys/signal.h>.
668 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
671 base
=`basename $file`
672 if [ -r ${LIB}/$file ]; then
673 file_to_fix
=${LIB}/$file
675 if [ -r ${INPUT}/$file ]; then
676 file_to_fix
=${INPUT}/$file
681 if [ \
! -z "$file_to_fix" ]; then
682 echo Checking
$file_to_fix
683 cp $file_to_fix /tmp
/$base
685 sed -e '/^struct sigaction {/c\
687 struct sigaction {' \
688 -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp
/$base > /tmp
/$base.
sed
689 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
692 echo Fixed
$file_to_fix
694 cp /tmp
/$base.
sed ${LIB}/$file
695 chmod a
+r
${LIB}/$file
697 rm -f /tmp
/$base /tmp
/$base.
sed
700 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
703 base
=`basename $file`
704 if [ -r ${LIB}/$file ]; then
705 file_to_fix
=${LIB}/$file
707 if [ -r ${INPUT}/$file ]; then
708 file_to_fix
=${INPUT}/$file
713 if [ \
! -z "$file_to_fix" ]; then
714 echo Checking
$file_to_fix
715 cp $file_to_fix /tmp
/$base
717 sed -e '/^dev_t makedev(const/c\
718 static dev_t makedev(const major_t, const minor_t);' \
719 -e '/^dev_t makedev()/c\
720 static dev_t makedev();' \
721 -e '/^major_t major(const/c\
722 static major_t major(const dev_t);' \
723 -e '/^major_t major()/c\
724 static major_t major();' \
725 -e '/^minor_t minor(const/c\
726 static minor_t minor(const dev_t);' \
727 -e '/^minor_t minor()/c\
728 static minor_t minor();' /tmp
/$base > /tmp
/$base.
sed
729 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
732 echo Fixed
$file_to_fix
734 cp /tmp
/$base.
sed ${LIB}/$file
735 chmod a
+r
${LIB}/$file
737 rm -f /tmp
/$base /tmp
/$base.
sed
740 # Fix reference to NMSZ in <sys/adv.h>.
743 base
=`basename $file`
744 if [ -r ${LIB}/$file ]; then
745 file_to_fix
=${LIB}/$file
747 if [ -r ${INPUT}/$file ]; then
748 file_to_fix
=${INPUT}/$file
753 if [ \
! -z "$file_to_fix" ]; then
754 echo Checking
$file_to_fix
755 sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp
/$base
756 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
759 echo Fixed
$file_to_fix
761 cp /tmp
/$base ${LIB}/$file
762 chmod a
+r
${LIB}/$file
767 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>. Also fix types of
768 # array initializers.
771 base
=`basename $file`
772 if [ -r ${LIB}/$file ]; then
773 file_to_fix
=${LIB}/$file
775 if [ -r ${INPUT}/$file ]; then
776 file_to_fix
=${INPUT}/$file
781 if [ \
! -z "$file_to_fix" ]; then
782 echo Checking
$file_to_fix
783 sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
784 |
sed 's/NC_/(unsigned long) NC_/' > /tmp
/$base
785 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
788 echo Fixed
$file_to_fix
790 cp /tmp
/$base ${LIB}/$file
791 chmod a
+r
${LIB}/$file
796 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
798 file=fs
/rfs
/rf_cache.h
799 base
=`basename $file`
800 if [ -r ${LIB}/$file ]; then
801 file_to_fix
=${LIB}/$file
803 if [ -r ${INPUT}/$file ]; then
804 file_to_fix
=${INPUT}/$file
809 if [ \
! -z "$file_to_fix" ]; then
810 echo Checking
$file_to_fix
811 if grep _KERNEL
$file_to_fix > /dev
/null
; then
814 echo '#ifdef _KERNEL' > /tmp
/$base
815 cat $file_to_fix >> /tmp
/$base
816 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
817 echo Fixed
$file_to_fix
819 cp /tmp
/$base ${LIB}/$file
820 chmod a
+r
${LIB}/$file
825 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
828 base
=`basename $file`
829 if [ -r ${LIB}/$file ]; then
830 file_to_fix
=${LIB}/$file
832 if [ -r ${INPUT}/$file ]; then
833 file_to_fix
=${INPUT}/$file
838 if [ \
! -z "$file_to_fix" ]; then
839 echo Checking
$file_to_fix
840 if grep _KERNEL
$file_to_fix > /dev
/null
; then
843 echo '#ifdef _KERNEL' > /tmp
/$base
844 cat $file_to_fix >> /tmp
/$base
845 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
846 echo Fixed
$file_to_fix
848 cp /tmp
/$base ${LIB}/$file
849 chmod a
+r
${LIB}/$file
854 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
857 base
=`basename $file`
858 if [ -r ${LIB}/$file ]; then
859 file_to_fix
=${LIB}/$file
861 if [ -r ${INPUT}/$file ]; then
862 file_to_fix
=${INPUT}/$file
867 if [ \
! -z "$file_to_fix" ]; then
868 echo Checking
$file_to_fix
869 if grep _KERNEL
$file_to_fix > /dev
/null
; then
872 echo '#ifdef _KERNEL' > /tmp
/$base
873 cat $file_to_fix >> /tmp
/$base
874 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
875 echo Fixed
$file_to_fix
877 cp /tmp
/$base ${LIB}/$file
878 chmod a
+r
${LIB}/$file
883 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
886 base
=`basename $file`
887 if [ -r ${LIB}/$file ]; then
888 file_to_fix
=${LIB}/$file
890 if [ -r ${INPUT}/$file ]; then
891 file_to_fix
=${INPUT}/$file
896 if [ \
! -z "$file_to_fix" ]; then
897 echo Checking
$file_to_fix
898 if grep _KERNEL
$file_to_fix > /dev
/null
; then
901 echo '#ifdef _KERNEL' > /tmp
/$base
902 cat $file_to_fix >> /tmp
/$base
903 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
904 echo Fixed
$file_to_fix
906 cp /tmp
/$base ${LIB}/$file
907 chmod a
+r
${LIB}/$file
912 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
915 base
=`basename $file`
916 if [ -r ${LIB}/$file ]; then
917 file_to_fix
=${LIB}/$file
919 if [ -r ${INPUT}/$file ]; then
920 file_to_fix
=${INPUT}/$file
925 if [ \
! -z "$file_to_fix" ]; then
926 echo Checking
$file_to_fix
927 if grep _KERNEL
$file_to_fix > /dev
/null
; then
930 echo '#ifdef _KERNEL' > /tmp
/$base
931 cat $file_to_fix >> /tmp
/$base
932 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
933 echo Fixed
$file_to_fix
935 cp /tmp
/$base ${LIB}/$file
936 chmod a
+r
${LIB}/$file
941 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
944 base
=`basename $file`
945 if [ -r ${LIB}/$file ]; then
946 file_to_fix
=${LIB}/$file
948 if [ -r ${INPUT}/$file ]; then
949 file_to_fix
=${INPUT}/$file
954 if [ \
! -z "$file_to_fix" ]; then
955 echo Checking
$file_to_fix
956 if grep _KERNEL
$file_to_fix > /dev
/null
; then
959 echo '#ifdef _KERNEL' > /tmp
/$base
960 cat $file_to_fix >> /tmp
/$base
961 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
962 echo Fixed
$file_to_fix
964 cp /tmp
/$base ${LIB}/$file
965 chmod a
+r
${LIB}/$file
970 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
973 base
=`basename $file`
974 if [ -r ${LIB}/$file ]; then
975 file_to_fix
=${LIB}/$file
977 if [ -r ${INPUT}/$file ]; then
978 file_to_fix
=${INPUT}/$file
983 if [ \
! -z "$file_to_fix" ]; then
984 echo Checking
$file_to_fix
985 if grep _KERNEL
$file_to_fix > /dev
/null
; then
988 echo '#ifdef _KERNEL' > /tmp
/$base
989 cat $file_to_fix >> /tmp
/$base
990 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
991 echo Fixed
$file_to_fix
993 cp /tmp
/$base ${LIB}/$file
994 chmod a
+r
${LIB}/$file
999 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
1001 file=sys
/kdebugger.h
1002 base
=`basename $file`
1003 if [ -r ${LIB}/$file ]; then
1004 file_to_fix
=${LIB}/$file
1006 if [ -r ${INPUT}/$file ]; then
1007 file_to_fix
=${INPUT}/$file
1012 if [ \
! -z "$file_to_fix" ]; then
1013 echo Checking
$file_to_fix
1014 if grep _KERNEL
$file_to_fix > /dev
/null
; then
1017 echo '#ifdef _KERNEL' > /tmp
/$base
1018 cat $file_to_fix >> /tmp
/$base
1019 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
1020 echo Fixed
$file_to_fix
1022 cp /tmp
/$base ${LIB}/$file
1023 chmod a
+r
${LIB}/$file
1028 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
1029 # This has been taken out because it breaks on some versions of
1030 # DYNIX/ptx, and it does not seem to do much good on any system.
1032 # base=`basename $file`
1033 # if [ -r ${LIB}/$file ]; then
1034 # file_to_fix=${LIB}/$file
1036 # if [ -r ${INPUT}/$file ]; then
1037 # file_to_fix=${INPUT}/$file
1042 # if [ \! -z "$file_to_fix" ]; then
1043 # echo Checking $file_to_fix
1044 # if grep _KERNEL $file_to_fix > /dev/null; then
1047 # sed -e '/#ifdef INKERNEL/i\
1050 # -e '/#endif[ ]*\/\* INKERNEL \*\//a\
1051 # #endif /* _KERNEL */
1053 # $file_to_fix > ${LIB}/${file}.sed
1054 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1055 # echo Fixed $file_to_fix
1059 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
1062 base
=`basename $file`
1063 if [ -r ${LIB}/$file ]; then
1064 file_to_fix
=${LIB}/$file
1066 if [ -r ${INPUT}/$file ]; then
1067 file_to_fix
=${INPUT}/$file
1072 if [ \
! -z "$file_to_fix" ]; then
1073 echo Checking
$file_to_fix
1074 if grep __GNUC__
$file_to_fix > /dev
/null
; then
1077 sed -e '/# ifdef __STDC__/i\
1078 # if !defined (__GNUC__) && !defined (__GNUG__)
1080 -e '/# include <sys\/byteorder.h>/s/ / /'\
1081 -e '/# include <sys\/byteorder.h>/i\
1082 # endif /* !defined (__GNUC__) && !defined (__GNUG__) */
1084 $file_to_fix > ${LIB}/${file}.
sed
1085 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1086 echo Fixed
$file_to_fix
1090 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
1091 # and the text in types.h is not erroneous.
1092 ## In sys/types.h, don't name the enum for booleans.
1095 #base=`basename $file`
1096 #if [ -r ${LIB}/$file ]; then
1097 # file_to_fix=${LIB}/$file
1099 # if [ -r ${INPUT}/$file ]; then
1100 # file_to_fix=${INPUT}/$file
1105 #if [ \! -z "$file_to_fix" ]; then
1106 # echo Checking $file_to_fix
1107 # if grep "enum boolean" $file_to_fix > /dev/null; then
1108 # sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1109 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1110 # echo Fixed $file_to_fix
1116 # Remove useless extern keyword from struct forward declarations in
1117 # <sys/stream.h> and <sys/strsubr.h>
1120 base
=`basename $file`
1121 if [ -r ${LIB}/$file ]; then
1122 file_to_fix
=${LIB}/$file
1124 if [ -r ${INPUT}/$file ]; then
1125 file_to_fix
=${INPUT}/$file
1130 if [ \
! -z "$file_to_fix" ]; then
1131 echo Checking
$file_to_fix
1133 s/extern struct stdata;/struct stdata;/g
1134 s/extern struct strevent;/struct strevent;/g
1135 ' $file_to_fix > /tmp
/$base
1136 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1139 echo Fixed
$file_to_fix
1141 cp /tmp
/$base ${LIB}/$file
1142 chmod a
+r
${LIB}/$file
1148 base
=`basename $file`
1149 if [ -r ${LIB}/$file ]; then
1150 file_to_fix
=${LIB}/$file
1152 if [ -r ${INPUT}/$file ]; then
1153 file_to_fix
=${INPUT}/$file
1158 if [ \
! -z "$file_to_fix" ]; then
1159 echo Checking
$file_to_fix
1161 s/extern struct strbuf;/struct strbuf;/g
1162 s/extern struct uio;/struct uio;/g
1163 s/extern struct thread;/struct thread;/g
1164 s/extern struct proc;/struct proc;/g
1165 ' $file_to_fix > /tmp
/$base
1166 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1169 echo Fixed
$file_to_fix
1171 cp /tmp
/$base ${LIB}/$file
1172 chmod a
+r
${LIB}/$file
1177 # Put storage class at start of decl, to avoid warning.
1179 base
=`basename $file`
1180 if [ -r ${LIB}/$file ]; then
1181 file_to_fix
=${LIB}/$file
1183 if [ -r ${INPUT}/$file ]; then
1184 file_to_fix
=${INPUT}/$file
1189 if [ \
! -z "$file_to_fix" ]; then
1190 echo Checking
$file_to_fix
1192 s/const extern/extern const/g
1193 ' $file_to_fix > /tmp
/$base
1194 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1197 echo Fixed
$file_to_fix
1199 cp /tmp
/$base ${LIB}/$file
1200 chmod a
+r
${LIB}/$file
1205 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1208 base
=`basename $file`
1209 if [ -r ${LIB}/$file ]; then
1210 file_to_fix
=${LIB}/$file
1212 if [ -r ${INPUT}/$file ]; then
1213 file_to_fix
=${INPUT}/$file
1218 if [ \
! -z "$file_to_fix" ]; then
1219 echo Checking
$file_to_fix
1220 cp $file_to_fix /tmp
/$base
1222 sed -e '/^stat([ ]*[^c]/{
1229 -e '/^lstat([ ]*[^c]/{
1236 -e '/^fstat([ ]*[^i]/{
1243 -e '/^mknod([ ]*[^c]/{
1251 -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1252 -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1253 -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1254 -e '1,$s/ret\([^u]\)/__ret\1/g' \
1255 -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1256 -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp
/$base > /tmp
/$base.
sed
1257 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
1260 echo Fixed
$file_to_fix
1262 cp /tmp
/$base.
sed ${LIB}/$file
1263 chmod a
+r
${LIB}/$file
1265 rm -f /tmp
/$base /tmp
/$base.
sed
1268 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1270 if [ -x /bin
/sony
]; then
1273 # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1276 base
=`basename $file`
1277 if [ -r ${LIB}/$file ]; then
1278 file_to_fix
=${LIB}/$file
1280 if [ -r ${INPUT}/$file ]; then
1281 file_to_fix
=${INPUT}/$file
1286 if [ \
! -z "$file_to_fix" ]; then
1287 echo Checking
$file_to_fix
1288 cp $file_to_fix /tmp
/$base
1291 s/__filbuf/_filbuf/g
1292 s/__flsbuf/_flsbuf/g
1294 ' /tmp
/$base > /tmp
/$base.
sed
1295 mv /tmp
/$base.
sed /tmp
/$base
1296 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then
1299 echo Fixed
$file_to_fix
1301 cp /tmp
/$base ${LIB}/$file
1302 chmod a
+r
${LIB}/$file
1307 # Change <ctype.h> to not define __ctype
1310 base
=`basename $file`
1311 if [ -r ${LIB}/$file ]; then
1312 file_to_fix
=${LIB}/$file
1314 if [ -r ${INPUT}/$file ]; then
1315 file_to_fix
=${INPUT}/$file
1320 if [ \
! -z "$file_to_fix" ]; then
1321 echo Checking
$file_to_fix
1322 cp $file_to_fix /tmp
/$base
1326 ' /tmp
/$base > /tmp
/$base.
sed
1327 mv /tmp
/$base.
sed /tmp
/$base
1328 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then
1331 echo Fixed
$file_to_fix
1333 cp /tmp
/$base ${LIB}/$file
1334 chmod a
+r
${LIB}/$file
1341 # In limits.h, put #ifndefs around things that are supposed to be defined
1342 # in float.h to avoid redefinition errors if float.h is included first.
1343 # Solaris 2.1 has this problem.
1346 base
=`basename $file`
1347 if [ -r ${LIB}/$file ]; then
1348 file_to_fix
=${LIB}/$file
1350 if [ -r ${INPUT}/$file ]; then
1351 file_to_fix
=${INPUT}/$file
1356 if [ \
! -z "$file_to_fix" ]; then
1357 echo Checking
$file_to_fix
1358 sed -e '/[ ]FLT_MIN[ ]/i\
1361 -e '/[ ]FLT_MIN[ ]/a\
1364 -e '/[ ]FLT_MAX[ ]/i\
1367 -e '/[ ]FLT_MAX[ ]/a\
1370 -e '/[ ]FLT_DIG[ ]/i\
1373 -e '/[ ]FLT_DIG[ ]/a\
1376 -e '/[ ]DBL_MIN[ ]/i\
1379 -e '/[ ]DBL_MIN[ ]/a\
1382 -e '/[ ]DBL_MAX[ ]/i\
1385 -e '/[ ]DBL_MAX[ ]/a\
1388 -e '/[ ]DBL_DIG[ ]/i\
1391 -e '/[ ]DBL_DIG[ ]/a\
1393 ' $file_to_fix > /tmp
/$base
1394 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1397 echo Fixed
$file_to_fix
1399 cp /tmp
/$base ${LIB}/$file
1400 chmod a
+r
${LIB}/$file
1405 # Completely replace <sys/varargs.h> with a file that includes gcc's
1406 # stdarg.h or varargs.h files as appropriate.
1409 if [ -r ${INPUT}/$file ]; then
1410 echo Replacing
$file
1411 cat > ${LIB}/$file << EOF
1412 /* This file was generated by fixincludes. */
1413 #ifndef _SYS_VARARGS_H
1414 #define _SYS_VARARGS_H
1419 #include <varargs.h>
1422 #endif /* _SYS_VARARGS_H */
1424 chmod a
+r
${LIB}/$file
1427 # In math.h, put #ifndefs around things that might be defined in a gcc
1428 # specific math-*.h file.
1431 base
=`basename $file`
1432 if [ -r ${LIB}/$file ]; then
1433 file_to_fix
=${LIB}/$file
1435 if [ -r ${INPUT}/$file ]; then
1436 file_to_fix
=${INPUT}/$file
1441 if [ \
! -z "$file_to_fix" ]; then
1442 echo Checking
$file_to_fix
1443 sed -e '/define[ ]HUGE_VAL[ ]/i\
1446 -e '/define[ ]HUGE_VAL[ ]/a\
1448 ' $file_to_fix > /tmp
/$base
1449 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1452 echo Fixed
$file_to_fix
1454 cp /tmp
/$base ${LIB}/$file
1455 chmod a
+r
${LIB}/$file
1460 # Solaris math.h and floatingpoint.h define __P without protection,
1461 # which conflicts with the fixproto definition. The fixproto
1462 # definition and the Solaris definition are used the same way.
1463 for file in math.h floatingpoint.h
; do
1464 base
=`basename $file`
1465 if [ -r ${LIB}/$file ]; then
1466 file_to_fix
=${LIB}/$file
1468 if [ -r ${INPUT}/$file ]; then
1469 file_to_fix
=${INPUT}/$file
1474 if [ \
! -z "$file_to_fix" ]; then
1475 echo Checking
$file_to_fix
1476 sed -e '/^#define[ ]*__P/i\
1479 -e '/^#define[ ]*__P/a\
1481 ' $file_to_fix > /tmp
/$base
1482 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1485 echo Fixed
$file_to_fix
1487 cp /tmp
/$base ${LIB}/$file
1488 chmod a
+r
${LIB}/$file
1494 # The Solaris math.h defines struct exception, which conflicts with
1495 # the class exception defined in the C++ file std/stdexcept.h. We
1496 # redefine it to __math_exception. This is not a great fix, but I
1497 # haven't been able to think of anything better.
1499 base
=`basename $file`
1500 if [ -r ${LIB}/$file ]; then
1501 file_to_fix
=${LIB}/$file
1503 if [ -r ${INPUT}/$file ]; then
1504 file_to_fix
=${INPUT}/$file
1509 if [ \
! -z "$file_to_fix" ]; then
1510 echo Checking
$file_to_fix
1511 sed -e '/struct exception/i\
1513 #define exception __math_exception\
1515 -e '/struct exception/a\
1518 #endif' $file_to_fix > /tmp
/$base
1519 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1522 echo Fixed
$file_to_fix
1524 cp /tmp
/$base ${LIB}/$file
1525 chmod a
+r
${LIB}/$file
1530 echo 'Removing unneeded directories:'
1532 files
=`find . -type d -print | sort -r`
1533 for file in $files; do
1534 rmdir $LIB/$file > /dev
/null
2>&1
1538 echo 'Making internal symbolic non-directory links'
1540 files
=`find . -type l -print`
1541 for file in $files; do
1542 dest
=`ls -ld $file | sed -n 's/.*-> //p'`
1543 if expr "$dest" : '[^/].*' > /dev
/null
; then
1544 target
=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
1545 if [ -f $target ]; then
1546 ln -s $dest ${LIB}/$file >/dev
/null
2>&1
1554 echo 'Replacing <sys/byteorder.h>'
1555 if [ \
! -d $LIB/sys
]; then
1558 rm -f ${LIB}/sys
/byteorder.h
1559 cat <<'__EOF__' >${LIB}/sys/byteorder.h
1560 #ifndef _SYS_BYTEORDER_H
1561 #define _SYS_BYTEORDER_H
1563 /* Functions to convert `short' and `long' quantities from host byte order
1564 to (internet) network byte order (i.e. big-endian).
1566 Written by Ron Guilmette (rfg@ncd.com).
1568 This isn't actually used by GCC. It is installed by fixinc.svr4.
1570 For big-endian machines these functions are essentially no-ops.
1572 For little-endian machines, we define the functions using specialized
1573 asm sequences in cases where doing so yields better code (e.g. i386). */
1575 #if !defined (__GNUC__) && !defined (__GNUG__)
1576 #error You lose! This file is only useful with GNU compilers.
1579 #ifndef __BYTE_ORDER__
1580 /* Byte order defines. These are as defined on UnixWare 1.1, but with
1581 double underscores added at the front and back. */
1582 #define __LITTLE_ENDIAN__ 1234
1583 #define __BIG_ENDIAN__ 4321
1584 #define __PDP_ENDIAN__ 3412
1588 static __inline__ unsigned long htonl (unsigned long);
1589 static __inline__ unsigned short htons (unsigned int);
1590 static __inline__ unsigned long ntohl (unsigned long);
1591 static __inline__ unsigned short ntohs (unsigned int);
1592 #endif /* defined (__STDC__) */
1594 #if defined (__i386__)
1596 #ifndef __BYTE_ORDER__
1597 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1600 /* Convert a host long to a network long. */
1602 /* We must use a new-style function definition, so that this will also
1603 be valid for C++. */
1604 static __inline__ unsigned long
1605 htonl (unsigned long __arg)
1607 register unsigned long __result;
1609 __asm__ ("xchg%B0 %b0,%h0\n\
1611 xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1615 /* Convert a host short to a network short. */
1617 static __inline__ unsigned short
1618 htons (unsigned int __arg)
1620 register unsigned short __result;
1622 __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1626 #elif ((defined (__i860__) && !defined (__i860_big_endian__)) \
1627 || defined (__ns32k__) || defined (__vax__) \
1628 || defined (__spur__) || defined (__arm__))
1630 #ifndef __BYTE_ORDER__
1631 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1634 /* For other little-endian machines, using C code is just as efficient as
1635 using assembly code. */
1637 /* Convert a host long to a network long. */
1639 static __inline__ unsigned long
1640 htonl (unsigned long __arg)
1642 register unsigned long __result;
1644 __result = (__arg >> 24) & 0x000000ff;
1645 __result |= (__arg >> 8) & 0x0000ff00;
1646 __result |= (__arg << 8) & 0x00ff0000;
1647 __result |= (__arg << 24) & 0xff000000;
1651 /* Convert a host short to a network short. */
1653 static __inline__ unsigned short
1654 htons (unsigned int __arg)
1656 register unsigned short __result;
1658 __result = (__arg << 8) & 0xff00;
1659 __result |= (__arg >> 8) & 0x00ff;
1663 #else /* must be a big-endian machine */
1665 #ifndef __BYTE_ORDER__
1666 #define __BYTE_ORDER__ __BIG_ENDIAN__
1669 /* Convert a host long to a network long. */
1671 static __inline__ unsigned long
1672 htonl (unsigned long __arg)
1677 /* Convert a host short to a network short. */
1679 static __inline__ unsigned short
1680 htons (unsigned int __arg)
1685 #endif /* big-endian */
1687 /* Convert a network long to a host long. */
1689 static __inline__ unsigned long
1690 ntohl (unsigned long __arg)
1692 return htonl (__arg);
1695 /* Convert a network short to a host short. */
1697 static __inline__ unsigned short
1698 ntohs (unsigned int __arg)
1700 return htons (__arg);
1705 if [ -r ${INPUT}/sys
/byteorder.h
]; then
1706 if grep BYTE_ORDER
${INPUT}/sys
/byteorder.h
>/dev
/null
2>/dev
/null
; then
1707 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1709 #define LITTLE_ENDIAN __LITTLE_ENDIAN__
1710 #define BIG_ENDIAN __BIG_ENDIAN__
1711 #define PDP_ENDIAN __PDP_ENDIAN__
1712 #define BYTE_ORDER __BYTE_ORDER__
1719 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1720 #endif /* !defined (_SYS_BYTEORDER_H) */
1723 chmod a
+r
${LIB}/sys
/byteorder.h