xref: /onnv-gate/usr/src/lib/libc/port/gen/errlist.awk (revision 6812:febeba71273d)
10Sstevel@tonic-gate#
20Sstevel@tonic-gate# CDDL HEADER START
30Sstevel@tonic-gate#
40Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5*6812Sraf# Common Development and Distribution License (the "License").
6*6812Sraf# You may not use this file except in compliance with the License.
70Sstevel@tonic-gate#
80Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate# See the License for the specific language governing permissions
110Sstevel@tonic-gate# and limitations under the License.
120Sstevel@tonic-gate#
130Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate#
190Sstevel@tonic-gate# CDDL HEADER END
200Sstevel@tonic-gate#
21*6812Sraf# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
22*6812Sraf# Use is subject to license terms.
23*6812Sraf#
240Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
250Sstevel@tonic-gate#
260Sstevel@tonic-gate# Create two files from a list of input strings;
270Sstevel@tonic-gate# new_list.c contains an array of characters indexed into by perror and
280Sstevel@tonic-gate# strerror;
290Sstevel@tonic-gate# errlst.c contains an array of pointers to strings for compatibility
300Sstevel@tonic-gate# with existing user programs that reference it directly;
310Sstevel@tonic-gate# errlst.c references the strings in new_list.c indirectly using a library
320Sstevel@tonic-gate# private symbol, __sys_errs[], in order to get relative relocations.
330Sstevel@tonic-gate#
340Sstevel@tonic-gate# Since the 64 bit ABI doesn't define the old symbols, the second file
350Sstevel@tonic-gate# should be left out 64 bit libraries.
360Sstevel@tonic-gate#
370Sstevel@tonic-gate# WARNING!
380Sstevel@tonic-gate#        Do NOT add entries to this list such that it grows the list
390Sstevel@tonic-gate#        beyond the last entry:
400Sstevel@tonic-gate#              151     Stale NFS file handle
410Sstevel@tonic-gate#        Growing this list may damage programs because this array is
420Sstevel@tonic-gate#        copied into a reserved array at runtime.  See bug 4097669.
430Sstevel@tonic-gate#
440Sstevel@tonic-gate#        If you need to add an entry please use one of the empty
450Sstevel@tonic-gate#        slots.
460Sstevel@tonic-gate#        The arrays _sys_errs[], accessible via perror(3C) and strerror(3C)
470Sstevel@tonic-gate#        interfaces, and sys_errlist[] are created from this list.
480Sstevel@tonic-gate#        It is the direct referencing of sys_errlist[] that is the problem.
490Sstevel@tonic-gate#        Your code should only use perror() or strerror().
500Sstevel@tonic-gate
510Sstevel@tonic-gate
520Sstevel@tonic-gateBEGIN	{
530Sstevel@tonic-gate		FS = "\t"
540Sstevel@tonic-gate		hi = 0
550Sstevel@tonic-gate
560Sstevel@tonic-gate		newfile = "new_list.c"
570Sstevel@tonic-gate		oldfile = "errlst.c"
580Sstevel@tonic-gate
590Sstevel@tonic-gate		print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >oldfile
60*6812Sraf		print "#pragma weak _sys_errlist = sys_errlist\n" >oldfile
61*6812Sraf		print "#include \"lint.h\"\n" >oldfile
620Sstevel@tonic-gate		# We need to include the errors strings proper in the
630Sstevel@tonic-gate		# C source for gettext; the macro C allows us to embed
640Sstevel@tonic-gate		# them as comment.
650Sstevel@tonic-gate		print "#define\tC(x)\n" >oldfile
660Sstevel@tonic-gate		print "extern const char __sys_errs[];\n" >oldfile
670Sstevel@tonic-gate		print "const char *sys_errlist[] = {" >oldfile
680Sstevel@tonic-gate
690Sstevel@tonic-gate		print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >newfile
70*6812Sraf		print "#include \"lint.h\"" >newfile
710Sstevel@tonic-gate		print "#include <sys/isa_defs.h>\n" >newfile
720Sstevel@tonic-gate		print "#pragma weak __sys_errs = _sys_errs\n" >newfile
730Sstevel@tonic-gate	}
740Sstevel@tonic-gate
750Sstevel@tonic-gate/^[0-9]+/ {
760Sstevel@tonic-gate		if ($1 > hi)
770Sstevel@tonic-gate			hi = $1
780Sstevel@tonic-gate		astr[$1] = $2
790Sstevel@tonic-gate	}
800Sstevel@tonic-gate
810Sstevel@tonic-gateEND	{
820Sstevel@tonic-gate		print "const int _sys_index[] =\n{" >newfile
830Sstevel@tonic-gate		k = 0
840Sstevel@tonic-gate		mx = 151	# max number of entries for sys_errlist[]
850Sstevel@tonic-gate		if (hi > mx)
860Sstevel@tonic-gate		{
870Sstevel@tonic-gate			printf "awk: ERROR! sys_errlist[] > %d entries\n", mx
880Sstevel@tonic-gate			printf "Please read comments in"
890Sstevel@tonic-gate			printf " usr/src/lib/libc/port/gen/errlist\n"
900Sstevel@tonic-gate			exit 1
910Sstevel@tonic-gate		}
920Sstevel@tonic-gate		for (j = 0; j <= hi; ++j)
930Sstevel@tonic-gate		{
940Sstevel@tonic-gate			if (astr[j] == "")
950Sstevel@tonic-gate				astr[j] = sprintf("Error %d", j)
960Sstevel@tonic-gate			printf "\t%d,\n", k >newfile
970Sstevel@tonic-gate			printf "\t&__sys_errs[%d], C(\"%s\")\n", k, astr[j] \
980Sstevel@tonic-gate				>oldfile
990Sstevel@tonic-gate			k += length(astr[j]) + 1
1000Sstevel@tonic-gate		}
1010Sstevel@tonic-gate		print "};\n" >newfile
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate		print "/* This is one long string */" >newfile
1040Sstevel@tonic-gate		printf "const char _sys_errs[%d] =\n", k >newfile
1050Sstevel@tonic-gate		for (j = 0; j <= hi; ++j)
1060Sstevel@tonic-gate		{
1070Sstevel@tonic-gate			printf "\t\"%s\\0\"\n", astr[j] >newfile
1080Sstevel@tonic-gate		}
1090Sstevel@tonic-gate		print ";\n" >newfile
1100Sstevel@tonic-gate		print "};\n" >oldfile
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate		print "const int _sys_num_err = " hi + 1 ";\n" >newfile
1130Sstevel@tonic-gate		print "#undef sys_nerr" >newfile
1140Sstevel@tonic-gate		print "#ifndef _LP64" >newfile
1150Sstevel@tonic-gate		print "#pragma weak _sys_nerr = _sys_num_err" >newfile
1160Sstevel@tonic-gate		print "#pragma weak sys_nerr = _sys_num_err" >newfile
1170Sstevel@tonic-gate		print "#endif /* _LP64 */" >newfile
1180Sstevel@tonic-gate	}
119