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 /^typedef[ ][ ]*[unsigned ]*long[ ][ ]*[u_]*longlong_t;/s/long/long long/
207 ' $2/$file > $2/$file.
sed
208 mv $2/$file.
sed $2/$file
209 if cmp $file $2/$file >/dev
/null
2>&1; then
219 # Install the proper definition of the three standard types in header files
220 # that they come from.
221 for file in sys
/types.h stdlib.h sys
/stdtypes.h stddef.h memory.h unistd.h
; do
222 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
223 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
224 chmod +w
${LIB}/$file 2>/dev
/null
225 chmod a
+r
${LIB}/$file 2>/dev
/null
228 if [ -r ${LIB}/$file ]; then
229 echo Fixing size_t
, ptrdiff_t and wchar_t
in $file
231 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]size_t/i\
232 #ifndef __SIZE_TYPE__\
233 #define __SIZE_TYPE__ long unsigned int\
236 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]size_t/typedef __SIZE_TYPE__ size_t/' \
237 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]ptrdiff_t/i\
238 #ifndef __PTRDIFF_TYPE__\
239 #define __PTRDIFF_TYPE__ long int\
242 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
243 -e '/typedef[ ][ ]*[a-z_][ a-z_]*[ ]wchar_t/i\
244 #ifndef __WCHAR_TYPE__\
245 #define __WCHAR_TYPE__ int\
248 -e 's/typedef[ ][ ]*[a-z_][ a-z_]*[ ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
249 ${LIB}/$file > ${LIB}/${file}.
sed
250 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
251 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
257 # Fix first broken decl of getcwd present on some svr4 systems.
260 base
=`basename $file`
261 if [ -r ${LIB}/$file ]; then
262 file_to_fix
=${LIB}/$file
264 if [ -r ${INPUT}/$file ]; then
265 file_to_fix
=${INPUT}/$file
270 if [ \
! -z "$file_to_fix" ]; then
271 echo Checking
$file_to_fix
272 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp
/$base
273 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
276 echo Fixed
$file_to_fix
278 cp /tmp
/$base ${LIB}/$file
279 chmod a
+r
${LIB}/$file
284 # Fix second broken decl of getcwd present on some svr4 systems. Also
285 # fix the incorrect decl of profil present on some svr4 systems.
288 base
=`basename $file`
289 if [ -r ${LIB}/$file ]; then
290 file_to_fix
=${LIB}/$file
292 if [ -r ${INPUT}/$file ]; then
293 file_to_fix
=${INPUT}/$file
298 if [ \
! -z "$file_to_fix" ]; then
299 echo Checking
$file_to_fix
300 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
301 |
sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp
/$base
302 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
305 echo Fixed
$file_to_fix
307 cp /tmp
/$base ${LIB}/$file
308 chmod a
+r
${LIB}/$file
313 # Fix the definition of NULL in <sys/param.h> so that it is conditional
314 # and so that it is correct for both C and C++.
317 base
=`basename $file`
318 if [ -r ${LIB}/$file ]; then
319 file_to_fix
=${LIB}/$file
321 if [ -r ${INPUT}/$file ]; then
322 file_to_fix
=${INPUT}/$file
327 if [ \
! -z "$file_to_fix" ]; then
328 echo Checking
$file_to_fix
329 cp $file_to_fix /tmp
/$base
332 sed -e '/^#define[ ]*NULL[ ]*0$/c\
336 #else /* !defined(__cplusplus) */\
337 #define __NULL_TYPE (void *)\
338 #endif /* !defined(__cplusplus) */\
339 #define NULL (__NULL_TYPE 0)\
340 #endif /* !defined(NULL) */' /tmp
/$base > /tmp
/$base.
sed
341 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
344 echo Fixed
$file_to_fix
346 cp /tmp
/$base.
sed ${LIB}/$file
347 chmod a
+r
${LIB}/$file
349 rm -f /tmp
/$base /tmp
/$base.
sed
352 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
353 # and so that it is correct for both C and C++.
356 base
=`basename $file`
357 if [ -r ${LIB}/$file ]; then
358 file_to_fix
=${LIB}/$file
360 if [ -r ${INPUT}/$file ]; then
361 file_to_fix
=${INPUT}/$file
366 if [ \
! -z "$file_to_fix" ]; then
367 echo Checking
$file_to_fix
368 cp $file_to_fix /tmp
/$base
370 sed -e '/^#define[ ]*NULL[ ]*0$/c\
373 #else /* !defined(__cplusplus) */\
374 #define __NULL_TYPE (void *)\
375 #endif /* !defined(__cplusplus) */\
376 #define NULL (__NULL_TYPE 0)' /tmp
/$base > /tmp
/$base.
sed
377 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
380 echo Fixed
$file_to_fix
382 cp /tmp
/$base.
sed ${LIB}/$file
383 chmod a
+r
${LIB}/$file
385 rm -f /tmp
/$base /tmp
/$base.
sed
388 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
389 # and so that it is correct for both C and C++.
392 base
=`basename $file`
393 if [ -r ${LIB}/$file ]; then
394 file_to_fix
=${LIB}/$file
396 if [ -r ${INPUT}/$file ]; then
397 file_to_fix
=${INPUT}/$file
402 if [ \
! -z "$file_to_fix" ]; then
403 echo Checking
$file_to_fix
404 cp $file_to_fix /tmp
/$base
406 sed -e '/^#define[ ]*NULL[ ]*((char \*) 0)$/c\
410 #else /* !defined(__cplusplus) */\
411 #define __NULL_TYPE (void *)\
412 #endif /* !defined(__cplusplus) */\
413 #define NULL (__NULL_TYPE 0)\
414 #endif /* !defined(NULL) */' /tmp
/$base > /tmp
/$base.
sed
415 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
418 echo Fixed
$file_to_fix
420 cp /tmp
/$base.
sed ${LIB}/$file
421 chmod a
+r
${LIB}/$file
423 rm -f /tmp
/$base /tmp
/$base.
sed
426 # Add a prototyped declaration of mmap to <sys/mman.h>.
429 base
=`basename $file`
430 if [ -r ${LIB}/$file ]; then
431 file_to_fix
=${LIB}/$file
433 if [ -r ${INPUT}/$file ]; then
434 file_to_fix
=${INPUT}/$file
439 if [ \
! -z "$file_to_fix" ]; then
440 echo Checking
$file_to_fix
441 cp $file_to_fix /tmp
/$base
443 sed -e '/^extern caddr_t mmap();$/c\
445 extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
446 #else /* !defined(__STDC__) */\
447 extern caddr_t mmap ();\
448 #endif /* !defined(__STDC__) */' /tmp
/$base > /tmp
/$base.
sed
449 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
452 echo Fixed
$file_to_fix
454 cp /tmp
/$base.
sed ${LIB}/$file
455 chmod a
+r
${LIB}/$file
457 rm -f /tmp
/$base /tmp
/$base.
sed
460 # Fix declarations of `ftw' and `nftw' in <ftw.h>. On some/most SVR4 systems
461 # the file <ftw.h> contains extern declarations of these functions followed
462 # by explicitly `static' definitions of these functions... and that's not
463 # allowed according to ANSI C. (Note however that on Solaris, this header
464 # file glitch has been pre-fixed by Sun. In the Solaris version of <ftw.h>
465 # there are no static definitions of any function so we don't need to do
466 # any of this stuff when on Solaris.
469 base
=`basename $file`
470 if [ -r ${LIB}/$file ]; then
471 file_to_fix
=${LIB}/$file
473 if [ -r ${INPUT}/$file ]; then
474 file_to_fix
=${INPUT}/$file
479 if test -z "$file_to_fix" ||
grep 'define ftw' $file_to_fix > /dev
/null
; then
480 # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
481 # one. Either way, we don't have to do anything.
484 echo Checking
$file_to_fix
485 cp $file_to_fix /tmp
/$base
487 sed -e '/^extern int ftw(const/i\
488 #if !defined(_STYPES)\
494 -e 's/extern \(int ftw(const.*\)$/\1/' \
495 -e '/^extern int nftw/i\
496 #if defined(_STYPES)\
502 -e 's/extern \(int nftw.*\)$/\1/' \
503 -e '/^extern int ftw(),/c\
504 #if !defined(_STYPES)\
510 #if defined(_STYPES)\
515 int nftw();' /tmp
/$base > /tmp
/$base.
sed
516 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
519 echo Fixed
$file_to_fix
521 cp /tmp
/$base.
sed ${LIB}/$file
522 chmod a
+r
${LIB}/$file
524 rm -f /tmp
/$base /tmp
/$base.
sed
527 # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
528 # g++, since it's now an official type in the C++ language.
530 base
=`basename $file`
531 if [ -r ${LIB}/$file ]; then
532 file_to_fix
=${LIB}/$file
534 if [ -r ${INPUT}/$file ]; then
535 file_to_fix
=${INPUT}/$file
541 if [ \
! -z "$file_to_fix" ]; then
542 echo Checking
$file_to_fix
543 cp $file_to_fix /tmp
/$base
545 sed -e 's,^typedef[ ]char[ ]bool;$,#ifndef __cplusplus\
547 #endif /* !defined __cplusplus */,' /tmp
/$base > /tmp
/$base.
sed
548 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
551 echo Fixed
$file_to_fix
553 cp /tmp
/$base.
sed ${LIB}/$file
554 chmod a
+r
${LIB}/$file
556 rm -f /tmp
/$base /tmp
/$base.
sed
559 # Add a `static' declaration of `getrnge' into <regexp.h>.
561 # Don't do this if there is already a `static void getrnge' declaration
562 # present, since this would cause a redeclaration error. Solaris 2.x has
563 # such a declaration.
566 base
=`basename $file`
567 if [ -r ${LIB}/$file ]; then
568 file_to_fix
=${LIB}/$file
570 if [ -r ${INPUT}/$file ]; then
571 file_to_fix
=${INPUT}/$file
576 if [ \
! -z "$file_to_fix" ]; then
577 echo Checking
$file_to_fix
578 if grep "static void getrnge" $file_to_fix > /dev
/null
; then
581 cp $file_to_fix /tmp
/$base
583 sed -e '/^static int[ ]*size;/c\
586 static int getrnge ();' /tmp
/$base > /tmp
/$base.
sed
587 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
590 echo Fixed
$file_to_fix
592 cp /tmp
/$base.
sed ${LIB}/$file
593 chmod a
+r
${LIB}/$file
596 rm -f /tmp
/$base /tmp
/$base.
sed
599 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
600 # that is visible to any ANSI compiler using this include. Simply
601 # delete the lines that #define some string functions to internal forms.
604 base
=`basename $file`
605 if [ -r ${LIB}/$file ]; then
606 file_to_fix
=${LIB}/$file
608 if [ -r ${INPUT}/$file ]; then
609 file_to_fix
=${INPUT}/$file
614 if [ \
! -z "$file_to_fix" ]; then
615 echo Checking
$file_to_fix
616 cp $file_to_fix /tmp
/$base
618 sed -e '/#define.*__std_hdr_/d' /tmp
/$base > /tmp
/$base.
sed
619 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
622 echo Fixed
$file_to_fix
624 cp /tmp
/$base.
sed ${LIB}/$file
625 chmod a
+r
${LIB}/$file
627 rm -f /tmp
/$base /tmp
/$base.
sed
630 # Delete any #defines of `__i386' which may be present in <ieeefp.h>. They
631 # tend to conflict with the compiler's own definition of this symbol. (We
632 # will use the compiler's definition.)
633 # Likewise __sparc, for Solaris, and __i860, and a few others
634 # (guessing it is necessary for all of them).
637 base
=`basename $file`
638 if [ -r ${LIB}/$file ]; then
639 file_to_fix
=${LIB}/$file
641 if [ -r ${INPUT}/$file ]; then
642 file_to_fix
=${INPUT}/$file
647 if [ \
! -z "$file_to_fix" ]; then
648 echo Checking
$file_to_fix
649 cp $file_to_fix /tmp
/$base
651 sed -e '/#define[ ]*__i386 /d' -e '/#define[ ]*__sparc /d' \
652 -e '/#define[ ]*__i860 /d' -e '/#define[ ]*__m88k /d' \
653 -e '/#define[ ]*__mips /d' -e '/#define[ ]*__m68k /d' \
654 /tmp
/$base > /tmp
/$base.
sed
655 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
658 echo Fixed
$file_to_fix
660 cp /tmp
/$base.
sed ${LIB}/$file
661 chmod a
+r
${LIB}/$file
663 rm -f /tmp
/$base /tmp
/$base.
sed
666 # Add a #define of _SIGACTION_ into <sys/signal.h>.
667 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
670 base
=`basename $file`
671 if [ -r ${LIB}/$file ]; then
672 file_to_fix
=${LIB}/$file
674 if [ -r ${INPUT}/$file ]; then
675 file_to_fix
=${INPUT}/$file
680 if [ \
! -z "$file_to_fix" ]; then
681 echo Checking
$file_to_fix
682 cp $file_to_fix /tmp
/$base
684 sed -e '/^struct sigaction {/c\
686 struct sigaction {' \
687 -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp
/$base > /tmp
/$base.
sed
688 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
691 echo Fixed
$file_to_fix
693 cp /tmp
/$base.
sed ${LIB}/$file
694 chmod a
+r
${LIB}/$file
696 rm -f /tmp
/$base /tmp
/$base.
sed
699 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
702 base
=`basename $file`
703 if [ -r ${LIB}/$file ]; then
704 file_to_fix
=${LIB}/$file
706 if [ -r ${INPUT}/$file ]; then
707 file_to_fix
=${INPUT}/$file
712 if [ \
! -z "$file_to_fix" ]; then
713 echo Checking
$file_to_fix
714 cp $file_to_fix /tmp
/$base
716 sed -e '/^dev_t makedev(const/c\
717 static dev_t makedev(const major_t, const minor_t);' \
718 -e '/^dev_t makedev()/c\
719 static dev_t makedev();' \
720 -e '/^major_t major(const/c\
721 static major_t major(const dev_t);' \
722 -e '/^major_t major()/c\
723 static major_t major();' \
724 -e '/^minor_t minor(const/c\
725 static minor_t minor(const dev_t);' \
726 -e '/^minor_t minor()/c\
727 static minor_t minor();' /tmp
/$base > /tmp
/$base.
sed
728 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
731 echo Fixed
$file_to_fix
733 cp /tmp
/$base.
sed ${LIB}/$file
734 chmod a
+r
${LIB}/$file
736 rm -f /tmp
/$base /tmp
/$base.
sed
739 # Fix reference to NMSZ in <sys/adv.h>.
742 base
=`basename $file`
743 if [ -r ${LIB}/$file ]; then
744 file_to_fix
=${LIB}/$file
746 if [ -r ${INPUT}/$file ]; then
747 file_to_fix
=${INPUT}/$file
752 if [ \
! -z "$file_to_fix" ]; then
753 echo Checking
$file_to_fix
754 sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp
/$base
755 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
758 echo Fixed
$file_to_fix
760 cp /tmp
/$base ${LIB}/$file
761 chmod a
+r
${LIB}/$file
766 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>. Also fix types of
767 # array initializers.
770 base
=`basename $file`
771 if [ -r ${LIB}/$file ]; then
772 file_to_fix
=${LIB}/$file
774 if [ -r ${INPUT}/$file ]; then
775 file_to_fix
=${INPUT}/$file
780 if [ \
! -z "$file_to_fix" ]; then
781 echo Checking
$file_to_fix
782 sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
783 |
sed 's/NC_/(unsigned long) NC_/' > /tmp
/$base
784 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
787 echo Fixed
$file_to_fix
789 cp /tmp
/$base ${LIB}/$file
790 chmod a
+r
${LIB}/$file
795 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
797 file=fs
/rfs
/rf_cache.h
798 base
=`basename $file`
799 if [ -r ${LIB}/$file ]; then
800 file_to_fix
=${LIB}/$file
802 if [ -r ${INPUT}/$file ]; then
803 file_to_fix
=${INPUT}/$file
808 if [ \
! -z "$file_to_fix" ]; then
809 echo Checking
$file_to_fix
810 if grep _KERNEL
$file_to_fix > /dev
/null
; then
813 echo '#ifdef _KERNEL' > /tmp
/$base
814 cat $file_to_fix >> /tmp
/$base
815 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
816 echo Fixed
$file_to_fix
818 cp /tmp
/$base ${LIB}/$file
819 chmod a
+r
${LIB}/$file
824 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
827 base
=`basename $file`
828 if [ -r ${LIB}/$file ]; then
829 file_to_fix
=${LIB}/$file
831 if [ -r ${INPUT}/$file ]; then
832 file_to_fix
=${INPUT}/$file
837 if [ \
! -z "$file_to_fix" ]; then
838 echo Checking
$file_to_fix
839 if grep _KERNEL
$file_to_fix > /dev
/null
; then
842 echo '#ifdef _KERNEL' > /tmp
/$base
843 cat $file_to_fix >> /tmp
/$base
844 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
845 echo Fixed
$file_to_fix
847 cp /tmp
/$base ${LIB}/$file
848 chmod a
+r
${LIB}/$file
853 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
856 base
=`basename $file`
857 if [ -r ${LIB}/$file ]; then
858 file_to_fix
=${LIB}/$file
860 if [ -r ${INPUT}/$file ]; then
861 file_to_fix
=${INPUT}/$file
866 if [ \
! -z "$file_to_fix" ]; then
867 echo Checking
$file_to_fix
868 if grep _KERNEL
$file_to_fix > /dev
/null
; then
871 echo '#ifdef _KERNEL' > /tmp
/$base
872 cat $file_to_fix >> /tmp
/$base
873 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
874 echo Fixed
$file_to_fix
876 cp /tmp
/$base ${LIB}/$file
877 chmod a
+r
${LIB}/$file
882 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
885 base
=`basename $file`
886 if [ -r ${LIB}/$file ]; then
887 file_to_fix
=${LIB}/$file
889 if [ -r ${INPUT}/$file ]; then
890 file_to_fix
=${INPUT}/$file
895 if [ \
! -z "$file_to_fix" ]; then
896 echo Checking
$file_to_fix
897 if grep _KERNEL
$file_to_fix > /dev
/null
; then
900 echo '#ifdef _KERNEL' > /tmp
/$base
901 cat $file_to_fix >> /tmp
/$base
902 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
903 echo Fixed
$file_to_fix
905 cp /tmp
/$base ${LIB}/$file
906 chmod a
+r
${LIB}/$file
911 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
914 base
=`basename $file`
915 if [ -r ${LIB}/$file ]; then
916 file_to_fix
=${LIB}/$file
918 if [ -r ${INPUT}/$file ]; then
919 file_to_fix
=${INPUT}/$file
924 if [ \
! -z "$file_to_fix" ]; then
925 echo Checking
$file_to_fix
926 if grep _KERNEL
$file_to_fix > /dev
/null
; then
929 echo '#ifdef _KERNEL' > /tmp
/$base
930 cat $file_to_fix >> /tmp
/$base
931 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
932 echo Fixed
$file_to_fix
934 cp /tmp
/$base ${LIB}/$file
935 chmod a
+r
${LIB}/$file
940 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
943 base
=`basename $file`
944 if [ -r ${LIB}/$file ]; then
945 file_to_fix
=${LIB}/$file
947 if [ -r ${INPUT}/$file ]; then
948 file_to_fix
=${INPUT}/$file
953 if [ \
! -z "$file_to_fix" ]; then
954 echo Checking
$file_to_fix
955 if grep _KERNEL
$file_to_fix > /dev
/null
; then
958 echo '#ifdef _KERNEL' > /tmp
/$base
959 cat $file_to_fix >> /tmp
/$base
960 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
961 echo Fixed
$file_to_fix
963 cp /tmp
/$base ${LIB}/$file
964 chmod a
+r
${LIB}/$file
969 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
972 base
=`basename $file`
973 if [ -r ${LIB}/$file ]; then
974 file_to_fix
=${LIB}/$file
976 if [ -r ${INPUT}/$file ]; then
977 file_to_fix
=${INPUT}/$file
982 if [ \
! -z "$file_to_fix" ]; then
983 echo Checking
$file_to_fix
984 if grep _KERNEL
$file_to_fix > /dev
/null
; then
987 echo '#ifdef _KERNEL' > /tmp
/$base
988 cat $file_to_fix >> /tmp
/$base
989 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
990 echo Fixed
$file_to_fix
992 cp /tmp
/$base ${LIB}/$file
993 chmod a
+r
${LIB}/$file
998 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
1000 file=sys
/kdebugger.h
1001 base
=`basename $file`
1002 if [ -r ${LIB}/$file ]; then
1003 file_to_fix
=${LIB}/$file
1005 if [ -r ${INPUT}/$file ]; then
1006 file_to_fix
=${INPUT}/$file
1011 if [ \
! -z "$file_to_fix" ]; then
1012 echo Checking
$file_to_fix
1013 if grep _KERNEL
$file_to_fix > /dev
/null
; then
1016 echo '#ifdef _KERNEL' > /tmp
/$base
1017 cat $file_to_fix >> /tmp
/$base
1018 echo '#endif /* defined(_KERNEL) */' >> /tmp
/$base
1019 echo Fixed
$file_to_fix
1021 cp /tmp
/$base ${LIB}/$file
1022 chmod a
+r
${LIB}/$file
1027 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
1028 # This has been taken out because it breaks on some versions of
1029 # DYNIX/ptx, and it does not seem to do much good on any system.
1031 # base=`basename $file`
1032 # if [ -r ${LIB}/$file ]; then
1033 # file_to_fix=${LIB}/$file
1035 # if [ -r ${INPUT}/$file ]; then
1036 # file_to_fix=${INPUT}/$file
1041 # if [ \! -z "$file_to_fix" ]; then
1042 # echo Checking $file_to_fix
1043 # if grep _KERNEL $file_to_fix > /dev/null; then
1046 # sed -e '/#ifdef INKERNEL/i\
1049 # -e '/#endif[ ]*\/\* INKERNEL \*\//a\
1050 # #endif /* _KERNEL */
1052 # $file_to_fix > ${LIB}/${file}.sed
1053 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1054 # echo Fixed $file_to_fix
1058 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
1061 base
=`basename $file`
1062 if [ -r ${LIB}/$file ]; then
1063 file_to_fix
=${LIB}/$file
1065 if [ -r ${INPUT}/$file ]; then
1066 file_to_fix
=${INPUT}/$file
1071 if [ \
! -z "$file_to_fix" ]; then
1072 echo Checking
$file_to_fix
1073 if grep __GNUC__
$file_to_fix > /dev
/null
; then
1076 sed -e '/# ifdef __STDC__/i\
1077 # if !defined (__GNUC__) && !defined (__GNUG__)
1079 -e '/# include <sys\/byteorder.h>/s/ / /'\
1080 -e '/# include <sys\/byteorder.h>/i\
1081 # endif /* !defined (__GNUC__) && !defined (__GNUG__) */
1083 $file_to_fix > ${LIB}/${file}.
sed
1084 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1085 echo Fixed
$file_to_fix
1089 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
1090 # and the text in types.h is not erroneous.
1091 ## In sys/types.h, don't name the enum for booleans.
1094 #base=`basename $file`
1095 #if [ -r ${LIB}/$file ]; then
1096 # file_to_fix=${LIB}/$file
1098 # if [ -r ${INPUT}/$file ]; then
1099 # file_to_fix=${INPUT}/$file
1104 #if [ \! -z "$file_to_fix" ]; then
1105 # echo Checking $file_to_fix
1106 # if grep "enum boolean" $file_to_fix > /dev/null; then
1107 # sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1108 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1109 # echo Fixed $file_to_fix
1115 # Remove useless extern keyword from struct forward declarations in
1116 # <sys/stream.h> and <sys/strsubr.h>
1119 base
=`basename $file`
1120 if [ -r ${LIB}/$file ]; then
1121 file_to_fix
=${LIB}/$file
1123 if [ -r ${INPUT}/$file ]; then
1124 file_to_fix
=${INPUT}/$file
1129 if [ \
! -z "$file_to_fix" ]; then
1130 echo Checking
$file_to_fix
1132 s/extern struct stdata;/struct stdata;/g
1133 s/extern struct strevent;/struct strevent;/g
1134 ' $file_to_fix > /tmp
/$base
1135 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1138 echo Fixed
$file_to_fix
1140 cp /tmp
/$base ${LIB}/$file
1141 chmod a
+r
${LIB}/$file
1147 base
=`basename $file`
1148 if [ -r ${LIB}/$file ]; then
1149 file_to_fix
=${LIB}/$file
1151 if [ -r ${INPUT}/$file ]; then
1152 file_to_fix
=${INPUT}/$file
1157 if [ \
! -z "$file_to_fix" ]; then
1158 echo Checking
$file_to_fix
1160 s/extern struct strbuf;/struct strbuf;/g
1161 s/extern struct uio;/struct uio;/g
1162 s/extern struct thread;/struct thread;/g
1163 s/extern struct proc;/struct proc;/g
1164 ' $file_to_fix > /tmp
/$base
1165 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1168 echo Fixed
$file_to_fix
1170 cp /tmp
/$base ${LIB}/$file
1171 chmod a
+r
${LIB}/$file
1176 # Put storage class at start of decl, to avoid warning.
1178 base
=`basename $file`
1179 if [ -r ${LIB}/$file ]; then
1180 file_to_fix
=${LIB}/$file
1182 if [ -r ${INPUT}/$file ]; then
1183 file_to_fix
=${INPUT}/$file
1188 if [ \
! -z "$file_to_fix" ]; then
1189 echo Checking
$file_to_fix
1191 s/const extern/extern const/g
1192 ' $file_to_fix > /tmp
/$base
1193 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1196 echo Fixed
$file_to_fix
1198 cp /tmp
/$base ${LIB}/$file
1199 chmod a
+r
${LIB}/$file
1204 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1207 base
=`basename $file`
1208 if [ -r ${LIB}/$file ]; then
1209 file_to_fix
=${LIB}/$file
1211 if [ -r ${INPUT}/$file ]; then
1212 file_to_fix
=${INPUT}/$file
1217 if [ \
! -z "$file_to_fix" ]; then
1218 echo Checking
$file_to_fix
1219 cp $file_to_fix /tmp
/$base
1221 sed -e '/^stat([ ]*[^c]/{
1228 -e '/^lstat([ ]*[^c]/{
1235 -e '/^fstat([ ]*[^i]/{
1242 -e '/^mknod([ ]*[^c]/{
1250 -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1251 -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1252 -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1253 -e '1,$s/ret\([^u]\)/__ret\1/g' \
1254 -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1255 -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp
/$base > /tmp
/$base.
sed
1256 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then \
1259 echo Fixed
$file_to_fix
1261 cp /tmp
/$base.
sed ${LIB}/$file
1262 chmod a
+r
${LIB}/$file
1264 rm -f /tmp
/$base /tmp
/$base.
sed
1267 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1269 if [ -x /bin
/sony
]; then
1272 # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1275 base
=`basename $file`
1276 if [ -r ${LIB}/$file ]; then
1277 file_to_fix
=${LIB}/$file
1279 if [ -r ${INPUT}/$file ]; then
1280 file_to_fix
=${INPUT}/$file
1285 if [ \
! -z "$file_to_fix" ]; then
1286 echo Checking
$file_to_fix
1287 cp $file_to_fix /tmp
/$base
1290 s/__filbuf/_filbuf/g
1291 s/__flsbuf/_flsbuf/g
1293 ' /tmp
/$base > /tmp
/$base.
sed
1294 mv /tmp
/$base.
sed /tmp
/$base
1295 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then
1298 echo Fixed
$file_to_fix
1300 cp /tmp
/$base ${LIB}/$file
1301 chmod a
+r
${LIB}/$file
1306 # Change <ctype.h> to not define __ctype
1309 base
=`basename $file`
1310 if [ -r ${LIB}/$file ]; then
1311 file_to_fix
=${LIB}/$file
1313 if [ -r ${INPUT}/$file ]; then
1314 file_to_fix
=${INPUT}/$file
1319 if [ \
! -z "$file_to_fix" ]; then
1320 echo Checking
$file_to_fix
1321 cp $file_to_fix /tmp
/$base
1325 ' /tmp
/$base > /tmp
/$base.
sed
1326 mv /tmp
/$base.
sed /tmp
/$base
1327 if cmp $file_to_fix /tmp
/$base.
sed >/dev
/null
2>&1; then
1330 echo Fixed
$file_to_fix
1332 cp /tmp
/$base ${LIB}/$file
1333 chmod a
+r
${LIB}/$file
1340 # In limits.h, put #ifndefs around things that are supposed to be defined
1341 # in float.h to avoid redefinition errors if float.h is included first.
1342 # Solaris 2.1 has this problem.
1345 base
=`basename $file`
1346 if [ -r ${LIB}/$file ]; then
1347 file_to_fix
=${LIB}/$file
1349 if [ -r ${INPUT}/$file ]; then
1350 file_to_fix
=${INPUT}/$file
1355 if [ \
! -z "$file_to_fix" ]; then
1356 echo Checking
$file_to_fix
1357 sed -e '/[ ]FLT_MIN[ ]/i\
1360 -e '/[ ]FLT_MIN[ ]/a\
1363 -e '/[ ]FLT_MAX[ ]/i\
1366 -e '/[ ]FLT_MAX[ ]/a\
1369 -e '/[ ]FLT_DIG[ ]/i\
1372 -e '/[ ]FLT_DIG[ ]/a\
1375 -e '/[ ]DBL_MIN[ ]/i\
1378 -e '/[ ]DBL_MIN[ ]/a\
1381 -e '/[ ]DBL_MAX[ ]/i\
1384 -e '/[ ]DBL_MAX[ ]/a\
1387 -e '/[ ]DBL_DIG[ ]/i\
1390 -e '/[ ]DBL_DIG[ ]/a\
1392 ' $file_to_fix > /tmp
/$base
1393 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1396 echo Fixed
$file_to_fix
1398 cp /tmp
/$base ${LIB}/$file
1399 chmod a
+r
${LIB}/$file
1404 # Completely replace <sys/varargs.h> with a file that includes gcc's
1405 # stdarg.h or varargs.h files as appropriate.
1408 if [ -r ${INPUT}/$file ]; then
1409 echo Replacing
$file
1410 cat > ${LIB}/$file << EOF
1411 /* This file was generated by fixincludes. */
1412 #ifndef _SYS_VARARGS_H
1413 #define _SYS_VARARGS_H
1418 #include <varargs.h>
1421 #endif /* _SYS_VARARGS_H */
1423 chmod a
+r
${LIB}/$file
1426 # In math.h, put #ifndefs around things that might be defined in a gcc
1427 # specific math-*.h file.
1430 base
=`basename $file`
1431 if [ -r ${LIB}/$file ]; then
1432 file_to_fix
=${LIB}/$file
1434 if [ -r ${INPUT}/$file ]; then
1435 file_to_fix
=${INPUT}/$file
1440 if [ \
! -z "$file_to_fix" ]; then
1441 echo Checking
$file_to_fix
1442 sed -e '/define[ ]HUGE_VAL[ ]/i\
1445 -e '/define[ ]HUGE_VAL[ ]/a\
1447 ' $file_to_fix > /tmp
/$base
1448 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1451 echo Fixed
$file_to_fix
1453 cp /tmp
/$base ${LIB}/$file
1454 chmod a
+r
${LIB}/$file
1459 # Solaris math.h and floatingpoint.h define __P without protection,
1460 # which conflicts with the fixproto definition. The fixproto
1461 # definition and the Solaris definition are used the same way.
1462 for file in math.h floatingpoint.h
; do
1463 base
=`basename $file`
1464 if [ -r ${LIB}/$file ]; then
1465 file_to_fix
=${LIB}/$file
1467 if [ -r ${INPUT}/$file ]; then
1468 file_to_fix
=${INPUT}/$file
1473 if [ \
! -z "$file_to_fix" ]; then
1474 echo Checking
$file_to_fix
1475 sed -e '/^#define[ ]*__P/i\
1478 -e '/^#define[ ]*__P/a\
1480 ' $file_to_fix > /tmp
/$base
1481 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1484 echo Fixed
$file_to_fix
1486 cp /tmp
/$base ${LIB}/$file
1487 chmod a
+r
${LIB}/$file
1493 # The Solaris math.h defines struct exception, which conflicts with
1494 # the class exception defined in the C++ file std/stdexcept.h. We
1495 # redefine it to __math_exception. This is not a great fix, but I
1496 # haven't been able to think of anything better.
1498 base
=`basename $file`
1499 if [ -r ${LIB}/$file ]; then
1500 file_to_fix
=${LIB}/$file
1502 if [ -r ${INPUT}/$file ]; then
1503 file_to_fix
=${INPUT}/$file
1508 if [ \
! -z "$file_to_fix" ]; then
1509 echo Checking
$file_to_fix
1510 sed -e '/struct exception/i\
1512 #define exception __math_exception\
1514 -e '/struct exception/a\
1517 #endif' $file_to_fix > /tmp
/$base
1518 if cmp $file_to_fix /tmp
/$base >/dev
/null
2>&1; then \
1521 echo Fixed
$file_to_fix
1523 cp /tmp
/$base ${LIB}/$file
1524 chmod a
+r
${LIB}/$file
1529 echo 'Removing unneeded directories:'
1531 files
=`find . -type d -print | sort -r`
1532 for file in $files; do
1533 rmdir $LIB/$file > /dev
/null
2>&1
1537 echo 'Making internal symbolic non-directory links'
1539 files
=`find . -type l -print`
1540 for file in $files; do
1541 dest
=`ls -ld $file | sed -n 's/.*-> //p'`
1542 if expr "$dest" : '[^/].*' > /dev
/null
; then
1543 target
=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
1544 if [ -f $target ]; then
1545 ln -s $dest ${LIB}/$file >/dev
/null
2>&1
1553 echo 'Replacing <sys/byteorder.h>'
1554 if [ \
! -d $LIB/sys
]; then
1557 rm -f ${LIB}/sys
/byteorder.h
1558 cat <<'__EOF__' >${LIB}/sys/byteorder.h
1559 #ifndef _SYS_BYTEORDER_H
1560 #define _SYS_BYTEORDER_H
1562 /* Functions to convert `short' and `long' quantities from host byte order
1563 to (internet) network byte order (i.e. big-endian).
1565 Written by Ron Guilmette (rfg@ncd.com).
1567 This isn't actually used by GCC. It is installed by fixinc.svr4.
1569 For big-endian machines these functions are essentially no-ops.
1571 For little-endian machines, we define the functions using specialized
1572 asm sequences in cases where doing so yields better code (e.g. i386). */
1574 #if !defined (__GNUC__) && !defined (__GNUG__)
1575 #error You lose! This file is only useful with GNU compilers.
1578 #ifndef __BYTE_ORDER__
1579 /* Byte order defines. These are as defined on UnixWare 1.1, but with
1580 double underscores added at the front and back. */
1581 #define __LITTLE_ENDIAN__ 1234
1582 #define __BIG_ENDIAN__ 4321
1583 #define __PDP_ENDIAN__ 3412
1587 static __inline__ unsigned long htonl (unsigned long);
1588 static __inline__ unsigned short htons (unsigned int);
1589 static __inline__ unsigned long ntohl (unsigned long);
1590 static __inline__ unsigned short ntohs (unsigned int);
1591 #endif /* defined (__STDC__) */
1593 #if defined (__i386__)
1595 #ifndef __BYTE_ORDER__
1596 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1599 /* Convert a host long to a network long. */
1601 /* We must use a new-style function definition, so that this will also
1602 be valid for C++. */
1603 static __inline__ unsigned long
1604 htonl (unsigned long __arg)
1606 register unsigned long __result;
1608 __asm__ ("xchg%B0 %b0,%h0\n\
1610 xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1614 /* Convert a host short to a network short. */
1616 static __inline__ unsigned short
1617 htons (unsigned int __arg)
1619 register unsigned short __result;
1621 __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1625 #elif ((defined (__i860__) && !defined (__i860_big_endian__)) \
1626 || defined (__ns32k__) || defined (__vax__) \
1627 || defined (__spur__) || defined (__arm__))
1629 #ifndef __BYTE_ORDER__
1630 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1633 /* For other little-endian machines, using C code is just as efficient as
1634 using assembly code. */
1636 /* Convert a host long to a network long. */
1638 static __inline__ unsigned long
1639 htonl (unsigned long __arg)
1641 register unsigned long __result;
1643 __result = (__arg >> 24) & 0x000000ff;
1644 __result |= (__arg >> 8) & 0x0000ff00;
1645 __result |= (__arg << 8) & 0x00ff0000;
1646 __result |= (__arg << 24) & 0xff000000;
1650 /* Convert a host short to a network short. */
1652 static __inline__ unsigned short
1653 htons (unsigned int __arg)
1655 register unsigned short __result;
1657 __result = (__arg << 8) & 0xff00;
1658 __result |= (__arg >> 8) & 0x00ff;
1662 #else /* must be a big-endian machine */
1664 #ifndef __BYTE_ORDER__
1665 #define __BYTE_ORDER__ __BIG_ENDIAN__
1668 /* Convert a host long to a network long. */
1670 static __inline__ unsigned long
1671 htonl (unsigned long __arg)
1676 /* Convert a host short to a network short. */
1678 static __inline__ unsigned short
1679 htons (unsigned int __arg)
1684 #endif /* big-endian */
1686 /* Convert a network long to a host long. */
1688 static __inline__ unsigned long
1689 ntohl (unsigned long __arg)
1691 return htonl (__arg);
1694 /* Convert a network short to a host short. */
1696 static __inline__ unsigned short
1697 ntohs (unsigned int __arg)
1699 return htons (__arg);
1704 if [ -r ${INPUT}/sys
/byteorder.h
]; then
1705 if grep BYTE_ORDER
${INPUT}/sys
/byteorder.h
>/dev
/null
2>/dev
/null
; then
1706 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1708 #define LITTLE_ENDIAN __LITTLE_ENDIAN__
1709 #define BIG_ENDIAN __BIG_ENDIAN__
1710 #define PDP_ENDIAN __PDP_ENDIAN__
1711 #define BYTE_ORDER __BYTE_ORDER__
1718 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1719 #endif /* !defined (_SYS_BYTEORDER_H) */
1722 chmod a
+r
${LIB}/sys
/byteorder.h