explicit_bzero: new module
[gnulib.git] / posix-modules
blob785dc9ccf64d5bae23566aa3608c788d549faa82
1 #!/bin/sh
3 # Copyright (C) 2002-2008, 2010-2017 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program 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
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 progname=$0
20 package=gnulib
22 # func_usage
23 # outputs to stdout the --help usage message.
24 func_usage ()
26 echo "\
27 Usage: posix-modules [option]
29 Lists the gnulib modules that implement POSIX interfaces.
31 Options:
33 --for-mingw list only modules that work on mingw
34 --for-msvc list only modules that work on MSVC
36 Report bugs to <bug-gnulib@gnu.org>."
39 # func_version
40 # outputs to stdout the --version message.
41 func_version ()
43 func_gnulib_dir
44 if test -d "$gnulib_dir"/.git \
45 && (git --version) >/dev/null 2>/dev/null \
46 && (date --version) >/dev/null 2>/dev/null; then
47 # gnulib checked out from git.
48 sed_extract_first_date='/^Date/{
49 s/^Date:[ ]*//p
52 date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
53 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
54 sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
55 date=`echo "$date" | sed -e "$sed_year_before_time"`
56 # Use GNU date to compute the time in GMT.
57 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
58 version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
59 else
60 # gnulib copy without versioning information.
61 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
62 version=
64 year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
65 echo "\
66 posix-modules (GNU $package $date)$version
67 Copyright (C) $year Free Software Foundation, Inc.
68 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
69 This is free software: you are free to change and redistribute it.
70 There is NO WARRANTY, to the extent permitted by law.
72 Written by" "Bruno Haible"
75 # func_exit STATUS
76 # exits with a given status.
77 # This function needs to be used, rather than 'exit', when a 'trap' handler is
78 # in effect that refers to $?.
79 func_exit ()
81 (exit $1); exit $1
84 # func_gnulib_dir
85 # locates the directory where the gnulib repository lives
86 # Input:
87 # - progname name of this program
88 # Sets variables
89 # - self_abspathname absolute pathname of this program
90 # - gnulib_dir absolute pathname of gnulib repository
91 func_gnulib_dir ()
93 case "$progname" in
94 /*) self_abspathname="$progname" ;;
95 */*) self_abspathname=`pwd`/"$progname" ;;
97 # Look in $PATH.
98 # Iterate through the elements of $PATH.
99 # We use IFS=: instead of
100 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
101 # because the latter does not work when some PATH element contains spaces.
102 # We use a canonicalized $pathx instead of $PATH, because empty PATH
103 # elements are by definition equivalent to '.', however field splitting
104 # according to IFS=: loses empty fields in many shells:
105 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
106 # beginning, at the end, and in the middle),
107 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
108 # at the beginning and at the end,
109 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
110 # Solaris lose empty fields at the end.
111 # The 'case' statement is an optimization, to avoid evaluating the
112 # explicit canonicalization command when $PATH contains no empty fields.
113 self_abspathname=
114 if test "${PATH_SEPARATOR+set}" != set; then
115 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
116 # contains only /bin. Note that ksh looks also at the FPATH variable,
117 # so we have to set that as well for the test.
118 PATH_SEPARATOR=:
119 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
120 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
121 || PATH_SEPARATOR=';'
124 if test "$PATH_SEPARATOR" = ";"; then
125 # On Windows, programs are searched in "." before $PATH.
126 pathx=".;$PATH"
127 else
128 # On Unix, we have to convert empty PATH elements to ".".
129 pathx="$PATH"
130 case :$PATH: in
131 *::*)
132 pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
134 esac
136 save_IFS="$IFS"
137 IFS="$PATH_SEPARATOR"
138 for d in $pathx; do
139 IFS="$save_IFS"
140 test -z "$d" && d=.
141 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
142 self_abspathname="$d/$progname"
143 break
145 done
146 IFS="$save_IFS"
147 if test -z "$self_abspathname"; then
148 func_fatal_error "could not locate the posix-modules program - how did you invoke it?"
151 esac
152 while test -h "$self_abspathname"; do
153 # Resolve symbolic link.
154 linkval=`func_readlink "$self_abspathname"`
155 test -n "$linkval" || break
156 case "$linkval" in
157 /* ) self_abspathname="$linkval" ;;
158 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
159 esac
160 done
161 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
164 # func_tmpdir
165 # creates a temporary directory.
166 # Input:
167 # - progname name of this program
168 # Sets variable
169 # - tmp pathname of freshly created temporary directory
170 func_tmpdir ()
172 # Use the environment variable TMPDIR, falling back to /tmp. This allows
173 # users to specify a different temporary directory, for example, if their
174 # /tmp is filled up or too small.
175 : ${TMPDIR=/tmp}
177 # Use the mktemp program if available. If not available, hide the error
178 # message.
179 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
180 test -n "$tmp" && test -d "$tmp"
181 } ||
183 # Use a simple mkdir command. It is guaranteed to fail if the directory
184 # already exists. $RANDOM is bash specific and expands to empty in shells
185 # other than bash, ksh and zsh. Its use does not increase security;
186 # rather, it minimizes the probability of failure in a very cluttered /tmp
187 # directory.
188 tmp=$TMPDIR/gl$$-$RANDOM
189 (umask 077 && mkdir "$tmp")
190 } ||
192 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
193 func_exit 1
197 # func_fatal_error message
198 # outputs to stderr a fatal error message, and terminates the program.
199 # Input:
200 # - progname name of this program
201 func_fatal_error ()
203 echo "$progname: *** $1" 1>&2
204 echo "$progname: *** Stop." 1>&2
205 func_exit 1
208 # func_readlink SYMLINK
209 # outputs the target of the given symlink.
210 if (type -p readlink) > /dev/null 2>&1; then
211 func_readlink ()
213 # Use the readlink program from GNU coreutils.
214 readlink "$1"
216 else
217 func_readlink ()
219 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
220 # would do the wrong thing if the link target contains " -> ".
221 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
225 # Excludes for mingw.
226 exclude_for_mingw=
227 # <grp.h> does not exist.
228 exclude_for_mingw="$exclude_for_mingw pt_chown grantpt posix_openpt-tests posix_openpt"
229 # The functions getuid, getgid, geteuid, getegid don't exist.
230 exclude_for_mingw="$exclude_for_mingw euidaccess faccessat"
231 exclude_for_mingw="$exclude_for_mingw fchownat-tests fchownat"
233 # Excludes for MSVC.
234 exclude_for_msvc="$exclude_for_mingw"
236 # Command-line option processing.
237 exclude=
238 while test $# -gt 0; do
239 case "$1" in
240 --for-mingw | --for-ming | --for-min | --for-mi )
241 exclude="$exclude $exclude_for_mingw"
242 shift ;;
243 --for-msvc | --for-msv | --for-ms )
244 exclude="$exclude $exclude_for_msvc"
245 shift ;;
246 --help | --hel | --he | --h )
247 func_usage
248 exit $? ;;
249 --version | --versio | --versi | --vers | --ver | --ve | --v )
250 func_version
251 exit $? ;;
252 -* )
253 echo "posix-modules: unknown option $1" 1>&2
254 echo "Try 'posix-modules --help' for more information." 1>&2
255 exit 1 ;;
257 echo "posix-modules: too many arguments" 1>&2
258 echo "Try 'posix-modules --help' for more information." 1>&2
259 exit 1 ;;
260 esac
261 done
263 func_gnulib_dir
264 func_tmpdir
265 trap 'exit_status=$?
266 if test "$signal" != 0; then
267 echo "caught signal $signal" >&2
269 rm -rf "$tmp"
270 exit $exit_status' 0
271 for signal in 1 2 3 13 15; do
272 trap '{ signal='$signal'; func_exit 1; }' $signal
273 done
274 signal=0
277 # Get the header modules.
278 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-headers/*.texi 2>/dev/null \
279 | sed -e 's,^Gnulib module: ,,'
280 # Get the function modules.
281 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-functions/*.texi 2>/dev/null \
282 | sed -e 's,^Gnulib module: ,,'
283 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
284 ) | sed -e 's/,/ /g' | LC_ALL=C sort | LC_ALL=C uniq \
285 | { # Then filter out the words "---", "and", "or" and remove *-gnu modules.
286 tr ' ' '\012' | sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
288 | LC_ALL=C sort | LC_ALL=C uniq \
289 | { # Then filter out the excludes.
290 if test -n "$exclude"; then
291 for m in $exclude; do echo $m; done | LC_ALL=C sort -u > "$tmp"/excludes
292 LC_ALL=C join -v 1 - "$tmp"/excludes
293 rm -f "$tmp"/excludes
294 else
299 # Local Variables:
300 # indent-tabs-mode: nil
301 # whitespace-check-buffer-indent: nil
302 # End: