2N/A#
2N/A# CDDL HEADER START
2N/A#
2N/A# The contents of this file are subject to the terms of the
2N/A# Common Development and Distribution License (the "License").
2N/A# You may not use this file except in compliance with the License.
2N/A#
2N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A# or http://www.opensolaris.org/os/licensing.
2N/A# See the License for the specific language governing permissions
2N/A# and limitations under the License.
2N/A#
2N/A# When distributing Covered Code, include this CDDL HEADER in each
2N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A# If applicable, add the following below this CDDL HEADER, with the
2N/A# fields enclosed by brackets "[]" replaced with your own identifying
2N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2N/A#
2N/A# CDDL HEADER END
2N/A#
2N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A# Use is subject to license terms.
2N/A#
2N/A# ident "%Z%%M% %I% %E% SMI"
2N/A#
2N/A# Create two files from a list of input strings;
2N/A# new_list.c contains an array of characters indexed into by perror and
2N/A# strerror;
2N/A# errlst.c contains an array of pointers to strings for compatibility
2N/A# with existing user programs that reference it directly;
2N/A# errlst.c references the strings in new_list.c indirectly using a library
2N/A# private symbol, __sys_errs[], in order to get relative relocations.
2N/A#
2N/A# Since the 64 bit ABI doesn't define the old symbols, the second file
2N/A# should be left out 64 bit libraries.
2N/A#
2N/A# WARNING!
2N/A# Do NOT add entries to this list such that it grows the list
2N/A# beyond the last entry:
2N/A# 151 Stale NFS file handle
2N/A# Growing this list may damage programs because this array is
2N/A# copied into a reserved array at runtime. See bug 4097669.
2N/A#
2N/A# If you need to add an entry please use one of the empty
2N/A# slots.
2N/A# The arrays _sys_errs[], accessible via perror(3C) and strerror(3C)
2N/A# interfaces, and sys_errlist[] are created from this list.
2N/A# It is the direct referencing of sys_errlist[] that is the problem.
2N/A# Your code should only use perror() or strerror().
2N/A
2N/A
2N/ABEGIN {
2N/A FS = "\t"
2N/A hi = 0
2N/A
2N/A newfile = "new_list.c"
2N/A oldfile = "errlst.c"
2N/A
2N/A print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >oldfile
2N/A print "#pragma weak _sys_errlist = sys_errlist\n" >oldfile
2N/A print "#include \"lint.h\"\n" >oldfile
2N/A # We need to include the errors strings proper in the
2N/A # C source for gettext; the macro C allows us to embed
2N/A # them as comment.
2N/A print "#define\tC(x)\n" >oldfile
2N/A print "extern const char __sys_errs[];\n" >oldfile
2N/A print "const char *sys_errlist[] = {" >oldfile
2N/A
2N/A print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >newfile
2N/A print "#include \"lint.h\"" >newfile
2N/A print "#include <sys/isa_defs.h>\n" >newfile
2N/A print "#pragma weak __sys_errs = _sys_errs\n" >newfile
2N/A }
2N/A
2N/A/^[0-9]+/ {
2N/A if ($1 > hi)
2N/A hi = $1
2N/A astr[$1] = $2
2N/A }
2N/A
2N/AEND {
2N/A print "const int _sys_index[] =\n{" >newfile
2N/A k = 0
2N/A mx = 151 # max number of entries for sys_errlist[]
2N/A if (hi > mx)
2N/A {
2N/A printf "awk: ERROR! sys_errlist[] > %d entries\n", mx
2N/A printf "Please read comments in"
2N/A printf " usr/src/lib/libc/port/gen/errlist\n"
2N/A exit 1
2N/A }
2N/A for (j = 0; j <= hi; ++j)
2N/A {
2N/A if (astr[j] == "")
2N/A astr[j] = sprintf("Error %d", j)
2N/A printf "\t%d,\n", k >newfile
2N/A printf "\t&__sys_errs[%d], C(\"%s\")\n", k, astr[j] \
2N/A >oldfile
2N/A k += length(astr[j]) + 1
2N/A }
2N/A print "};\n" >newfile
2N/A
2N/A print "/* This is one long string */" >newfile
2N/A printf "const char _sys_errs[%d] =\n", k >newfile
2N/A for (j = 0; j <= hi; ++j)
2N/A {
2N/A printf "\t\"%s\\0\"\n", astr[j] >newfile
2N/A }
2N/A print ";\n" >newfile
2N/A print "};\n" >oldfile
2N/A
2N/A print "const int _sys_num_err = " hi + 1 ";\n" >newfile
2N/A print "#undef sys_nerr" >newfile
2N/A print "#ifndef _LP64" >newfile
2N/A print "#pragma weak _sys_nerr = _sys_num_err" >newfile
2N/A print "#pragma weak sys_nerr = _sys_num_err" >newfile
2N/A print "#endif /* _LP64 */" >newfile
2N/A }