]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/gnu/errlist-compat.awk
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / gnu / errlist-compat.awk
CommitLineData
4022d8ed 1# awk script to generate errlist-compat.c
f7a9f785 2# Copyright (C) 2002-2016 Free Software Foundation, Inc.
4022d8ed
RM
3# This file is part of the GNU C Library.
4
5# The GNU C Library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9
10# The GNU C Library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14
15# You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16# License along with the GNU C Library; if not, see
17# <http://www.gnu.org/licenses/>.
4022d8ed
RM
18
19#
20# This script takes the Versions file as input and looks for #errlist-compat
21# magic comments, which have the form:
22# #errlist-compat NNN
23# where NNN is the number of elements in the sys_errlist for that version set.
24# We need the awk variable `maxerr' defined to the current size of sys_errlist.
25#
26# If there is no magic comment matching the current size, we barf.
27# Otherwise we generate code (errlist-compat.c) to define all the
28# necessary compatibility symbols for older, smaller versions of sys_errlist.
29#
30
4022d8ed
RM
31# These two rules catch the Versions file contents.
32NF == 2 && $2 == "{" { last_version = $1; next }
33$1 == "#errlist-compat" {
5fe14d96
UD
34 # Don't process any further Versions files
35 ARGC = ARGIND + 1;
36 cnt = $2 + 0;
c2b22a08 37 if (cnt < 80) {
4022d8ed
RM
38 print "*** this line seems bogus:", $0 > "/dev/stderr";
39 exit 1;
40 }
5fe14d96
UD
41 version[pos + 0] = cnt SUBSEP last_version;
42 pos++;
43 if (cnt < highest) {
44 printf "*** %s #errlist-compat counts are not sorted\n", ARGV[ARGIND];
45 exit 1;
46 }
47 if (cnt > highest)
48 highest = cnt;
49 highest_version = last_version;
4022d8ed
RM
50 next;
51}
52
53END {
7a9ce79a
RM
54 if (! highest_version) {
55 print "/* No sys_errlist/sys_nerr symbols defined on this platform. */";
56 exit 0;
57 }
58
4022d8ed
RM
59 count = maxerr + 1;
60
4b359a27 61 if (highest < count) {
4022d8ed 62 printf "*** errlist.c count %d vs Versions sys_errlist@%s count %d\n", \
5fe14d96 63 count, highest_version, highest > "/dev/stderr";
4022d8ed
RM
64 exit 1;
65 }
66
67 lastv = "";
5fe14d96
UD
68 for (n = 0; n < pos; ++n) {
69 split(version[n], t, SUBSEP)
70 v = t[2];
71 gsub(/[^A-Z0-9_]/, "_", v);
72 if (lastv != "")
73 compat[lastv] = v;
74 lastv = v;
75 vcount[v] = t[1];
76 }
4022d8ed
RM
77
78 print "/* This file was generated by errlist-compat.awk; DO NOT EDIT! */\n";
79 print "#include <shlib-compat.h>\n";
80
4b359a27
RM
81 if (highest > count) {
82 printf "*** errlist.c count %d inflated to %s count %d (old errno.h?)\n", \
83 count, highest_version, highest > "/dev/stderr";
ff3d51ec 84 printf "#define ERR_MAX %d\n\n", highest - 1;
4b359a27
RM
85 }
86
b1eeb65d
CD
87 # same regardless of awk's ordering of the associative array.
88 num_compat_elems = asorti(compat, compat_indices)
89 for (i = 1; i <= num_compat_elems; i++) {
90 old = compat_indices[i]
4022d8ed
RM
91 new = compat[old];
92 n = vcount[old];
93 printf "#if SHLIB_COMPAT (libc, %s, %s)\n", old, new;
a7b8a17b 94 printf "# include <bits/wordsize.h>\n";
aa6938f7 95 printf "extern const char *const __sys_errlist_%s[NERR];\n", old;
4022d8ed 96 printf "const int __sys_nerr_%s = %d;\n", old, n;
11bf311e
UD
97 printf "declare_symbol_alias (__sys_errlist_%s, _sys_errlist_internal,", \
98 old;
99 printf " object, __WORDSIZE/8*%d)\n", n;
4022d8ed
RM
100 printf "compat_symbol (libc, __sys_errlist_%s, sys_errlist, %s);\n", \
101 old, old;
102 printf "compat_symbol (libc, __sys_nerr_%s, sys_nerr, %s);\n", old, old;
103
aa6938f7 104 printf "extern const char *const ___sys_errlist_%s[NERR];\n", old;
4022d8ed 105 printf "extern const int __sys_nerr_%s;\n", old;
11bf311e
UD
106 printf "declare_symbol_alias (___sys_errlist_%s, _sys_errlist_internal,", \
107 old;
108 printf " object, __WORDSIZE/8*%d)\n", n;
4022d8ed
RM
109 printf "strong_alias (__sys_nerr_%s, ___sys_nerr_%s)\n", old, old;
110 printf "compat_symbol (libc, ___sys_errlist_%s, _sys_errlist, %s);\n", \
111 old, old;
112 printf "compat_symbol (libc, ___sys_nerr_%s, _sys_nerr, %s);\n", old, old;
113 printf "#endif\n\n";
114 }
115
116 printf "\
2103c260 117extern const char *const __sys_errlist_internal[NERR];\n\
4022d8ed
RM
118extern const int __sys_nerr_internal;\n\
119strong_alias (_sys_errlist_internal, __sys_errlist_internal)\n\
120strong_alias (_sys_nerr_internal, __sys_nerr_internal)\n\
2103c260 121extern const char *const sys_errlist[NERR];\n\
4022d8ed
RM
122versioned_symbol (libc, _sys_errlist_internal, sys_errlist, %s);\n\
123versioned_symbol (libc, __sys_errlist_internal, _sys_errlist, %s);\n\
124versioned_symbol (libc, _sys_nerr_internal, sys_nerr, %s);\n\
125versioned_symbol (libc, __sys_nerr_internal, _sys_nerr, %s);\n", \
126 lastv, lastv, lastv, lastv;
1ce8aaae
RM
127
128 print "\n\
129link_warning (sys_errlist, \"\
130`sys_errlist' is deprecated; use `strerror' or `strerror_r' instead\")\n\
131link_warning (sys_nerr, \"\
132`sys_nerr' is deprecated; use `strerror' or `strerror_r' instead\")";
4022d8ed 133}