diff options
author | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 12:29:46 +0300 |
---|---|---|
committer | maxim-yurchuk <maxim-yurchuk@yandex-team.com> | 2024-10-09 13:14:22 +0300 |
commit | 9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80 (patch) | |
tree | a8fb3181d5947c0d78cf402aa56e686130179049 /contrib/tools/m4 | |
parent | a44b779cd359f06c3ebbef4ec98c6b38609d9d85 (diff) | |
download | ydb-9731d8a4bb7ee2cc8554eaf133bb85498a4c7d80.tar.gz |
publishFullContrib: true for ydb
<HIDDEN_URL>
commit_hash:c82a80ac4594723cebf2c7387dec9c60217f603e
Diffstat (limited to 'contrib/tools/m4')
-rw-r--r-- | contrib/tools/m4/.yandex_meta/licenses.list.txt | 65 | ||||
-rw-r--r-- | contrib/tools/m4/lib/.yandex_meta/licenses.list.txt | 1054 | ||||
-rw-r--r-- | contrib/tools/m4/lib/canonicalize-lgpl.c | 411 | ||||
-rw-r--r-- | contrib/tools/m4/lib/glthread/lock.c | 1057 | ||||
-rw-r--r-- | contrib/tools/m4/lib/glthread/threadlib.c | 73 | ||||
-rw-r--r-- | contrib/tools/m4/lib/glthread/tls.c | 61 | ||||
-rw-r--r-- | contrib/tools/m4/lib/intprops.h | 319 | ||||
-rw-r--r-- | contrib/tools/m4/lib/isnanf-nolibm.h | 40 | ||||
-rw-r--r-- | contrib/tools/m4/lib/math.c | 3 | ||||
-rw-r--r-- | contrib/tools/m4/lib/printf.c | 40 | ||||
-rw-r--r-- | contrib/tools/m4/lib/same-inode.h | 33 | ||||
-rw-r--r-- | contrib/tools/m4/lib/vfprintf.c | 74 | ||||
-rw-r--r-- | contrib/tools/m4/patches/o-binary-text.patch | 14 | ||||
-rw-r--r-- | contrib/tools/m4/src/Makefile.am | 29 |
14 files changed, 3273 insertions, 0 deletions
diff --git a/contrib/tools/m4/.yandex_meta/licenses.list.txt b/contrib/tools/m4/.yandex_meta/licenses.list.txt new file mode 100644 index 0000000000..c0c24001ed --- /dev/null +++ b/contrib/tools/m4/.yandex_meta/licenses.list.txt @@ -0,0 +1,65 @@ +====================COPYRIGHT==================== + Copyright (C) 1989-1993, 2004, 2006-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 2000, 2004, 2006-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 2003, 2006-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1991-1994, 2004, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2006-2013 Free Software Foundation, Inc. + + +====================GPL-3.0-or-later==================== + GNU M4 is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GNU M4 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + +====================GPL-3.0-or-later==================== +## GNU M4 is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## GNU M4 is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see <http://www.gnu.org/licenses/>. diff --git a/contrib/tools/m4/lib/.yandex_meta/licenses.list.txt b/contrib/tools/m4/lib/.yandex_meta/licenses.list.txt new file mode 100644 index 0000000000..8d30fca783 --- /dev/null +++ b/contrib/tools/m4/lib/.yandex_meta/licenses.list.txt @@ -0,0 +1,1054 @@ +====================BSD-3-Clause==================== +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the product nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +====================COPYRIGHT==================== + Copyright (C) 1998, 2001, 2003-2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1988, 1990, 1999, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1988-1994, 1996-1999, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1988-1994, 1996-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990, 2001, 2003-2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1990-2000, 2002-2006, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1991, 2004-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1991-1992, 1994-1999, 2003, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1991-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1995-1997, 2003, 2006, 2008-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1996-1997, 2003, 2005, 2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1996-1999, 2008-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1996-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 1997, 2000, 2002, 2004, 2006, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997. + + +====================COPYRIGHT==================== + Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1997-2006, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-1999, 2001, 2003, 2009-2013 Free Software Foundation, + Inc. + Written by Jim Meyering <meyering@ascend.com>, 1998. + + +====================COPYRIGHT==================== + Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-2001, 2003, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-2002, 2004, 2006, 2008-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-2002, 2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-2002, 2004-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1998-2004, 2006-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002, 2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2004, 2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2002-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2003, 2005, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999, 2004-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999-2000, 2002-2003, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 1999-2002, 2005-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2008. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2002, 2004, 2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2002, 2004, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2003, 2005-2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2003-2004, 2008-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2004, 2006-2007, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2003, 2006, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2003, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU CHARSET Library. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2004, 2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2000-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2003, 2005, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2003, 2005, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2003, 2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2003, 2006-2007, 2009-2013 Free Software Foundation, + Inc. + Written by Bruno Haible <bruno@clisp.org>, 2006. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2003-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2004, 2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2004-2006, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2005, 2007, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2005-2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2002. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2006-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2002. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2002, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible <haible@clisp.cons.org>, 2001. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2003, 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible <haible@clisp.cons.org>, 2001. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2004, 2006, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2001. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2004, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2004, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2004, 2006, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2004, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2005-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2003, 2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2003, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation, + Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2003, 2005, 2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2003, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2003-2004, 2006-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2003-2004, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2003. + + +====================COPYRIGHT==================== + Copyright (C) 2003-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2004, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2004-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2005, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2005-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2006, 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2006. + + +====================COPYRIGHT==================== + Copyright (C) 2006-2007, 2010-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2006-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2008. + + +====================COPYRIGHT==================== + Copyright (C) 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright (C) 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2011. + + +====================COPYRIGHT==================== + Copyright 2000-2003, 2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright 2002-2003, 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== + Copyright 2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 1999-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2002-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2007-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2008-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +# Copyright (C) 2012-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013 + Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +/* Copyright (C) 1991, 1994-2002, 2005, 2008-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + + +====================COPYRIGHT==================== +/* Copyright (C) 1991, 1997, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + This file is derived from the one in the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1999, 2001-2002, 2006, 2009-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 2000, 2004, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Copyright (C) 2000, 2008-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + +====================COPYRIGHT==================== +/* Sequential list data type implemented by a hash table with a linked list. + Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2006. + + +====================COPYRIGHT==================== +/* Variable with FSF copyright information, for version-etc. + Copyright (C) 1999-2006, 2009-2013 Free Software Foundation, Inc. + + +====================COPYRIGHT==================== +// Copyright (c) 2006-2013 Alexander Chemeris + + +====================COPYRIGHT==================== +Copyright d Free Software Foundation, Inc. + +====================File: gnulib/src/filenamecat-lgpl.c==================== +/* Concatenate two arbitrary file names. + + Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Jim Meyering. */ + +#include <config.h> + +/* Specification. */ +#include "filenamecat.h" + +#include <stdlib.h> +#include <string.h> + +#include "dirname.h" + +#if ! HAVE_MEMPCPY && ! defined mempcpy +# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) +#endif + +/* Return the longest suffix of F that is a relative file name. + If it has no such suffix, return the empty string. */ + +static char const * _GL_ATTRIBUTE_PURE +longest_relative_suffix (char const *f) +{ + for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++) + continue; + return f; +} + +/* Concatenate two file name components, DIR and ABASE, in + newly-allocated storage and return the result. + The resulting file name F is such that the commands "ls F" and "(cd + DIR; ls BASE)" refer to the same file, where BASE is ABASE with any + file system prefixes and leading separators removed. + Arrange for a directory separator if necessary between DIR and BASE + in the result, removing any redundant separators. + In any case, if BASE_IN_RESULT is non-NULL, set + *BASE_IN_RESULT to point to the copy of ABASE in the returned + concatenation. However, if ABASE begins with more than one slash, + set *BASE_IN_RESULT to point to the sole corresponding slash that + is copied into the result buffer. + + Return NULL if malloc fails. */ + +char * +mfile_name_concat (char const *dir, char const *abase, char **base_in_result) +{ + char const *dirbase = last_component (dir); + size_t dirbaselen = base_len (dirbase); + size_t dirlen = dirbase - dir + dirbaselen; + size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1])); + + char const *base = longest_relative_suffix (abase); + size_t baselen = strlen (base); + + char *p_concat = malloc (dirlen + needs_separator + baselen + 1); + char *p; + + if (p_concat == NULL) + return NULL; + + p = mempcpy (p_concat, dir, dirlen); + *p = DIRECTORY_SEPARATOR; + p += needs_separator; + + if (base_in_result) + *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase); + + p = mempcpy (p, base, baselen); + *p = '\0'; + + return p_concat; +} + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, see + <http://www.gnu.org/licenses/>. + + +====================GPL-3.0-or-later==================== + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\ +This is free software: you are free to change and redistribute it.\n\ +There is NO WARRANTY, to the extent permitted by law.\n\ + + +====================GPL-3.0-or-later==================== +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + +====================GPL-3.0-or-later==================== +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, see <http://www.gnu.org/licenses/>. */ + + +====================LGPL-2.0-or-later==================== +/* Just like mfile_name_concat (filenamecat-lgpl.c), except, rather than diff --git a/contrib/tools/m4/lib/canonicalize-lgpl.c b/contrib/tools/m4/lib/canonicalize-lgpl.c new file mode 100644 index 0000000000..5cc9c5b4a0 --- /dev/null +++ b/contrib/tools/m4/lib/canonicalize-lgpl.c @@ -0,0 +1,411 @@ +/* Return the canonical absolute name of a given file. + Copyright (C) 1996-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +# define _GL_ARG_NONNULL(params) + +# define _GL_USE_STDLIB_ALLOC 1 +# include <config.h> +#endif + +#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC + +/* Specification. */ +#include <stdlib.h> + +#include "palloca.h" +#include <string.h> +#include <unistd.h> +#include <limits.h> +#if HAVE_SYS_PARAM_H || defined _LIBC +# include <sys/param.h> +#endif +#include <sys/stat.h> +#include <errno.h> +#include <stddef.h> + +#ifdef _LIBC +# include <shlib-compat.h> +#else +# define SHLIB_COMPAT(lib, introduced, obsoleted) 0 +# define versioned_symbol(lib, local, symbol, version) extern int dummy +# define compat_symbol(lib, local, symbol, version) +# define weak_alias(local, symbol) +# define __canonicalize_file_name canonicalize_file_name +# define __realpath realpath +# include "pathmax.h" +# include "malloca.h" +# include "dosname.h" +# if HAVE_GETCWD +# if IN_RELOCWRAPPER + /* When building the relocatable program wrapper, use the system's getcwd + function, not the gnulib override, otherwise we would get a link error. + */ +# undef getcwd +# endif +# ifdef VMS + /* We want the directory in Unix syntax, not in VMS syntax. */ +# define __getcwd(buf, max) getcwd (buf, max, 0) +# else +# define __getcwd getcwd +# endif +# else +# define __getcwd(buf, max) getwd (buf) +# endif +# define __readlink readlink +# define __set_errno(e) errno = (e) +# ifndef MAXSYMLINKS +# ifdef SYMLOOP_MAX +# define MAXSYMLINKS SYMLOOP_MAX +# else +# define MAXSYMLINKS 20 +# endif +# endif +#endif + +#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT +# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 +#endif + +#if !FUNC_REALPATH_WORKS || defined _LIBC +/* Return the canonical absolute name of file NAME. A canonical name + does not contain any ".", ".." components nor any repeated path + separators ('/') or symlinks. All path components must exist. If + RESOLVED is null, the result is malloc'd; otherwise, if the + canonical name is PATH_MAX chars or more, returns null with 'errno' + set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, + returns the name in RESOLVED. If the name cannot be resolved and + RESOLVED is non-NULL, it contains the path of the first component + that cannot be resolved. If the path can be resolved, RESOLVED + holds the same value as the value returned. */ + +char * +__realpath (const char *name, char *resolved) +{ + char *rpath, *dest, *extra_buf = NULL; + const char *start, *end, *rpath_limit; + long int path_max; + int num_links = 0; + size_t prefix_len; + + if (name == NULL) + { + /* As per Single Unix Specification V2 we must return an error if + either parameter is a null pointer. We extend this to allow + the RESOLVED parameter to be NULL in case the we are expected to + allocate the room for the return value. */ + __set_errno (EINVAL); + return NULL; + } + + if (name[0] == '\0') + { + /* As per Single Unix Specification V2 we must return an error if + the name argument points to an empty string. */ + __set_errno (ENOENT); + return NULL; + } + +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf (name, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 8192; +#endif + + if (resolved == NULL) + { + rpath = malloc (path_max); + if (rpath == NULL) + { + /* It's easier to set errno to ENOMEM than to rely on the + 'malloc-posix' gnulib module. */ + errno = ENOMEM; + return NULL; + } + } + else + rpath = resolved; + rpath_limit = rpath + path_max; + + /* This is always zero for Posix hosts, but can be 2 for MS-Windows + and MS-DOS X:/foo/bar file names. */ + prefix_len = FILE_SYSTEM_PREFIX_LEN (name); + + if (!IS_ABSOLUTE_FILE_NAME (name)) + { + if (!__getcwd (rpath, path_max)) + { + rpath[0] = '\0'; + goto error; + } + dest = strchr (rpath, '\0'); + start = name; + prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath); + } + else + { + dest = rpath; + if (prefix_len) + { + memcpy (rpath, name, prefix_len); + dest += prefix_len; + } + *dest++ = '/'; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len) + *dest++ = '/'; + *dest = '\0'; + } + start = name + prefix_len; + } + + for (end = start; *start; start = end) + { +#ifdef _LIBC + struct stat64 st; +#else + struct stat st; +#endif + int n; + + /* Skip sequence of multiple path-separators. */ + while (ISSLASH (*start)) + ++start; + + /* Find end of path component. */ + for (end = start; *end && !ISSLASH (*end); ++end) + /* Nothing. */; + + if (end - start == 0) + break; + else if (end - start == 1 && start[0] == '.') + /* nothing */; + else if (end - start == 2 && start[0] == '.' && start[1] == '.') + { + /* Back up to previous component, ignore if at root already. */ + if (dest > rpath + prefix_len + 1) + for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) + continue; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT + && dest == rpath + 1 && !prefix_len + && ISSLASH (*dest) && !ISSLASH (dest[1])) + dest++; + } + else + { + size_t new_size; + + if (!ISSLASH (dest[-1])) + *dest++ = '/'; + + if (dest + (end - start) >= rpath_limit) + { + ptrdiff_t dest_offset = dest - rpath; + char *new_rpath; + + if (resolved) + { + __set_errno (ENAMETOOLONG); + if (dest > rpath + prefix_len + 1) + dest--; + *dest = '\0'; + goto error; + } + new_size = rpath_limit - rpath; + if (end - start + 1 > path_max) + new_size += end - start + 1; + else + new_size += path_max; + new_rpath = (char *) realloc (rpath, new_size); + if (new_rpath == NULL) + { + /* It's easier to set errno to ENOMEM than to rely on the + 'realloc-posix' gnulib module. */ + errno = ENOMEM; + goto error; + } + rpath = new_rpath; + rpath_limit = rpath + new_size; + + dest = rpath + dest_offset; + } + +#ifdef _LIBC + dest = __mempcpy (dest, start, end - start); +#else + memcpy (dest, start, end - start); + dest += end - start; +#endif + *dest = '\0'; + +#ifdef _LIBC + if (__lxstat64 (_STAT_VER, rpath, &st) < 0) +#else + if (lstat (rpath, &st) < 0) +#endif + goto error; + + if (S_ISLNK (st.st_mode)) + { + char *buf; + size_t len; + + if (++num_links > MAXSYMLINKS) + { + __set_errno (ELOOP); + goto error; + } + + buf = malloca (path_max); + if (!buf) + { + errno = ENOMEM; + goto error; + } + + n = __readlink (rpath, buf, path_max - 1); + if (n < 0) + { + int saved_errno = errno; + freea (buf); + errno = saved_errno; + goto error; + } + buf[n] = '\0'; + + if (!extra_buf) + { + extra_buf = malloca (path_max); + if (!extra_buf) + { + freea (buf); + errno = ENOMEM; + goto error; + } + } + + len = strlen (end); + if ((long int) (n + len) >= path_max) + { + freea (buf); + __set_errno (ENAMETOOLONG); + goto error; + } + + /* Careful here, end may be a pointer into extra_buf... */ + memmove (&extra_buf[n], end, len + 1); + name = end = memcpy (extra_buf, buf, n); + + if (IS_ABSOLUTE_FILE_NAME (buf)) + { + size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf); + + if (pfxlen) + memcpy (rpath, buf, pfxlen); + dest = rpath + pfxlen; + *dest++ = '/'; /* It's an absolute symlink */ + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen) + *dest++ = '/'; + *dest = '\0'; + } + /* Install the new prefix to be in effect hereafter. */ + prefix_len = pfxlen; + } + else + { + /* Back up to previous component, ignore if at root + already: */ + if (dest > rpath + prefix_len + 1) + for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) + continue; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len) + dest++; + } + } + else if (!S_ISDIR (st.st_mode) && *end != '\0') + { + __set_errno (ENOTDIR); + goto error; + } + } + } + if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1])) + --dest; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len + && ISSLASH (*dest) && !ISSLASH (dest[1])) + dest++; + *dest = '\0'; + + if (extra_buf) + freea (extra_buf); + + return rpath; + +error: + { + int saved_errno = errno; + if (extra_buf) + freea (extra_buf); + if (resolved == NULL) + free (rpath); + errno = saved_errno; + } + return NULL; +} +versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); +#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */ + + +#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3) +char * +attribute_compat_text_section +__old_realpath (const char *name, char *resolved) +{ + if (resolved == NULL) + { + __set_errno (EINVAL); + return NULL; + } + + return __realpath (name, resolved); +} +compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0); +#endif + + +char * +__canonicalize_file_name (const char *name) +{ + return __realpath (name, NULL); +} +weak_alias (__canonicalize_file_name, canonicalize_file_name) + +#else + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; + +#endif diff --git a/contrib/tools/m4/lib/glthread/lock.c b/contrib/tools/m4/lib/glthread/lock.c new file mode 100644 index 0000000000..f62aa301fe --- /dev/null +++ b/contrib/tools/m4/lib/glthread/lock.c @@ -0,0 +1,1057 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, + gthr-win32.h. */ + +#include <config.h> + +#include "glthread/lock.h" + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK + +# if !defined PTHREAD_RWLOCK_INITIALIZER + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_rwlock_init (&lock->rwlock, NULL); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_rdlock (&lock->rwlock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_wrlock (&lock->rwlock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_rwlock_unlock (&lock->rwlock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_rwlock_destroy (&lock->rwlock); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->lock, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_readers, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_writers, NULL); + if (err != 0) + return err; + lock->waiting_writers_count = 0; + lock->runcount = 0; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow. */ + /* POSIX says: "It is implementation-defined whether the calling thread + acquires the lock when a writer does not hold the lock and there are + writers blocked on the lock." Let's say, no: give the writers a higher + priority. */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + lock->runcount++; + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); + if (err != 0) + { + lock->waiting_writers_count--; + pthread_mutex_unlock (&lock->lock); + return err; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + err = pthread_cond_signal (&lock->waiting_writers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + else + { + /* Wake up all waiting readers. */ + err = pthread_cond_broadcast (&lock->waiting_readers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + } + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_destroy (&lock->lock); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_readers); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_writers); + if (err != 0) + return err; + return 0; +} + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (lock, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + return 0; +} + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (&lock->recmutex, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_recursive_lock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_mutex_lock (&lock->recmutex); +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_mutex_unlock (&lock->recmutex); +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_mutex_destroy (&lock->recmutex); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->mutex, NULL); + if (err != 0) + return err; + lock->owner = (pthread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_t self = pthread_self (); + if (lock->owner != self) + { + int err; + + err = pthread_mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != pthread_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (pthread_t) 0; + return pthread_mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (pthread_t) 0) + return EBUSY; + return pthread_mutex_destroy (&lock->mutex); +} + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; + +int +glthread_once_singlethreaded (pthread_once_t *once_control) +{ + /* We don't know whether pthread_once_t is an integer type, a floating-point + type, a pointer type, or a structure type. */ + char *firstbyte = (char *)once_control; + if (*firstbyte == *(const char *)&fresh_once) + { + /* First time use of once_control. Invert the first byte. */ + *firstbyte = ~ *(const char *)&fresh_once; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_PTH_THREADS + +/* Use the GNU Pth threads library. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static void +glthread_once_call (void *arg) +{ + void (**gl_once_temp_addr) (void) = (void (**) (void)) arg; + void (*initfunction) (void) = *gl_once_temp_addr; + initfunction (); +} + +int +glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void)) +{ + void (*temp) (void) = initfunction; + return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0); +} + +int +glthread_once_singlethreaded (pth_once_t *once_control) +{ + /* We know that pth_once_t is an integer type. */ + if (*once_control == PTH_ONCE_INIT) + { + /* First time use of once_control. Invert the marker. */ + *once_control = ~ PTH_ONCE_INIT; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_SOLARIS_THREADS + +/* Use the old Solaris threads library. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = mutex_init (&lock->mutex, USYNC_THREAD, NULL); + if (err != 0) + return err; + lock->owner = (thread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + thread_t self = thr_self (); + if (lock->owner != self) + { + int err; + + err = mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != thr_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (thread_t) 0; + return mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (thread_t) 0) + return EBUSY; + return mutex_destroy (&lock->mutex); +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +int +glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void)) +{ + if (!once_control->inited) + { + int err; + + /* Use the mutex to guarantee that if another thread is already calling + the initfunction, this thread waits until it's finished. */ + err = mutex_lock (&once_control->mutex); + if (err != 0) + return err; + if (!once_control->inited) + { + once_control->inited = 1; + initfunction (); + } + return mutex_unlock (&once_control->mutex); + } + else + return 0; +} + +int +glthread_once_singlethreaded (gl_once_t *once_control) +{ + /* We know that gl_once_t contains an integer type. */ + if (!once_control->inited) + { + /* First time use of once_control. Invert the marker. */ + once_control->inited = ~ 0; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +void +glthread_lock_init_func (gl_lock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + lock->guard.done = 1; +} + +int +glthread_lock_lock_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_lock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + return 0; +} + +int +glthread_lock_unlock_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_lock_destroy_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + DeleteCriticalSection (&lock->lock); + lock->guard.done = 0; + return 0; +} + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* In this file, the waitqueues are implemented as circular arrays. */ +#define gl_waitqueue_t gl_carray_waitqueue_t + +static void +gl_waitqueue_init (gl_waitqueue_t *wq) +{ + wq->array = NULL; + wq->count = 0; + wq->alloc = 0; + wq->offset = 0; +} + +/* Enqueues the current thread, represented by an event, in a wait queue. + Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ +static HANDLE +gl_waitqueue_add (gl_waitqueue_t *wq) +{ + HANDLE event; + unsigned int index; + + if (wq->count == wq->alloc) + { + unsigned int new_alloc = 2 * wq->alloc + 1; + HANDLE *new_array = + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + if (new_array == NULL) + /* No more memory. */ + return INVALID_HANDLE_VALUE; + /* Now is a good opportunity to rotate the array so that its contents + starts at offset 0. */ + if (wq->offset > 0) + { + unsigned int old_count = wq->count; + unsigned int old_alloc = wq->alloc; + unsigned int old_offset = wq->offset; + unsigned int i; + if (old_offset + old_count > old_alloc) + { + unsigned int limit = old_offset + old_count - old_alloc; + for (i = 0; i < limit; i++) + new_array[old_alloc + i] = new_array[i]; + } + for (i = 0; i < old_count; i++) + new_array[i] = new_array[old_offset + i]; + wq->offset = 0; + } + wq->array = new_array; + wq->alloc = new_alloc; + } + /* Whether the created event is a manual-reset one or an auto-reset one, + does not matter, since we will wait on it only once. */ + event = CreateEvent (NULL, TRUE, FALSE, NULL); + if (event == INVALID_HANDLE_VALUE) + /* No way to allocate an event. */ + return INVALID_HANDLE_VALUE; + index = wq->offset + wq->count; + if (index >= wq->alloc) + index -= wq->alloc; + wq->array[index] = event; + wq->count++; + return event; +} + +/* Notifies the first thread from a wait queue and dequeues it. */ +static void +gl_waitqueue_notify_first (gl_waitqueue_t *wq) +{ + SetEvent (wq->array[wq->offset + 0]); + wq->offset++; + wq->count--; + if (wq->count == 0 || wq->offset == wq->alloc) + wq->offset = 0; +} + +/* Notifies all threads from a wait queue and dequeues them all. */ +static void +gl_waitqueue_notify_all (gl_waitqueue_t *wq) +{ + unsigned int i; + + for (i = 0; i < wq->count; i++) + { + unsigned int index = wq->offset + i; + if (index >= wq->alloc) + index -= wq->alloc; + SetEvent (wq->array[index]); + } + wq->count = 0; + wq->offset = 0; +} + +void +glthread_rwlock_init_func (gl_rwlock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + gl_waitqueue_init (&lock->waiting_readers); + gl_waitqueue_init (&lock->waiting_writers); + lock->runcount = 0; + lock->guard.done = 1; +} + +int +glthread_rwlock_rdlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow. */ + if (!(lock->runcount + 1 > 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + HANDLE event = gl_waitqueue_add (&lock->waiting_readers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_readers, incremented lock->runcount. */ + if (!(lock->runcount > 0)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_wrlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + HANDLE event = gl_waitqueue_add (&lock->waiting_writers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_writers, set lock->runcount = -1. */ + if (!(lock->runcount == -1)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_unlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + EnterCriticalSection (&lock->lock); + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + abort (); + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + LeaveCriticalSection (&lock->lock); + return EPERM; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers.count > 0) + { + /* Wake up one of the waiting writers. */ + lock->runcount--; + gl_waitqueue_notify_first (&lock->waiting_writers); + } + else + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + gl_waitqueue_notify_all (&lock->waiting_readers); + } + } + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_destroy_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + if (lock->runcount != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + if (lock->waiting_readers.array != NULL) + free (lock->waiting_readers.array); + if (lock->waiting_writers.array != NULL) + free (lock->waiting_writers.array); + lock->guard.done = 0; + return 0; +} + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +void +glthread_recursive_lock_init_func (gl_recursive_lock_t *lock) +{ + lock->owner = 0; + lock->depth = 0; + InitializeCriticalSection (&lock->lock); + lock->guard.done = 1; +} + +int +glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_recursive_lock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + { + DWORD self = GetCurrentThreadId (); + if (lock->owner != self) + { + EnterCriticalSection (&lock->lock); + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock) +{ + if (lock->owner != GetCurrentThreadId ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = 0; + LeaveCriticalSection (&lock->lock); + } + return 0; +} + +int +glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock) +{ + if (lock->owner != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + lock->guard.done = 0; + return 0; +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +void +glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)) +{ + if (once_control->inited <= 0) + { + if (InterlockedIncrement (&once_control->started) == 0) + { + /* This thread is the first one to come to this once_control. */ + InitializeCriticalSection (&once_control->lock); + EnterCriticalSection (&once_control->lock); + once_control->inited = 0; + initfunction (); + once_control->inited = 1; + LeaveCriticalSection (&once_control->lock); + } + else + { + /* Undo last operation. */ + InterlockedDecrement (&once_control->started); + /* Some other thread has already started the initialization. + Yield the CPU while waiting for the other thread to finish + initializing and taking the lock. */ + while (once_control->inited < 0) + Sleep (0); + if (once_control->inited <= 0) + { + /* Take the lock. This blocks until the other thread has + finished calling the initfunction. */ + EnterCriticalSection (&once_control->lock); + LeaveCriticalSection (&once_control->lock); + if (!(once_control->inited > 0)) + abort (); + } + } + } +} + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/m4/lib/glthread/threadlib.c b/contrib/tools/m4/lib/glthread/threadlib.c new file mode 100644 index 0000000000..b447657302 --- /dev/null +++ b/contrib/tools/m4/lib/glthread/threadlib.c @@ -0,0 +1,73 @@ +/* Multithreading primitives. + Copyright (C) 2005-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#include <config.h> + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include <pthread.h> +# include <stdlib.h> + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + +#endif + +/* ========================================================================= */ + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; diff --git a/contrib/tools/m4/lib/glthread/tls.c b/contrib/tools/m4/lib/glthread/tls.c new file mode 100644 index 0000000000..bcd285c273 --- /dev/null +++ b/contrib/tools/m4/lib/glthread/tls.c @@ -0,0 +1,61 @@ +/* Thread-local storage in multithreaded situations. + Copyright (C) 2005-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#include <config.h> + +#include "glthread/tls.h" + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_PTH_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_SOLARIS_THREADS + +/* Use the old Solaris threads library. */ + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +void * +glthread_tls_get_multithreaded (thread_key_t key) +{ + void *value; + + if (thr_getspecific (key, &value) != 0) + abort (); + return value; +} + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/m4/lib/intprops.h b/contrib/tools/m4/lib/intprops.h new file mode 100644 index 0000000000..f57f9b4dda --- /dev/null +++ b/contrib/tools/m4/lib/intprops.h @@ -0,0 +1,319 @@ +/* intprops.h -- properties of integer types + + Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_INTPROPS_H +#define _GL_INTPROPS_H + +#include <limits.h> + +/* Return an integer value, converted to the same type as the integer + expression E after integer type promotion. V is the unconverted value. */ +#define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) + +/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see + <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */ +#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if negative values of the signed integer type T use two's + complement, ones' complement, or signed magnitude representation, + respectively. Much GNU code assumes two's complement, but some + people like to be portable to all possible C hosts. */ +#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) +#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) +#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) + +/* True if the signed integer expression E uses two's complement. */ +#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1) + +/* True if the arithmetic type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Return 1 if the integer expression E, after integer promotion, has + a signed type. */ +#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) + + +/* Minimum and maximum values for integer types and expressions. These + macros have undefined behavior if T is signed and has padding bits. + If this is a problem for you, please let us know how to fix it for + your host. */ + +/* The maximum and minimum values for the integer type T. */ +#define TYPE_MINIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ TYPE_MAXIMUM (t))) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) + +/* The maximum and minimum values for the type of the expression E, + after integer promotion. E should not have side effects. */ +#define _GL_INT_MINIMUM(e) \ + (_GL_INT_SIGNED (e) \ + ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_CONVERT (e, 0)) +#define _GL_INT_MAXIMUM(e) \ + (_GL_INT_SIGNED (e) \ + ? _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_NEGATE_CONVERT (e, 1)) +#define _GL_SIGNED_INT_MAXIMUM(e) \ + (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) + + +/* Return 1 if the __typeof__ keyword works. This could be done by + 'configure', but for now it's easier to do it by hand. */ +#if 2 <= __GNUC__ || defined __IBM__TYPEOF__ || 0x5110 <= __SUNPRO_C +# define _GL_HAVE___TYPEOF__ 1 +#else +# define _GL_HAVE___TYPEOF__ 0 +#endif + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argument, + and expands to an integer constant expression. */ +#if _GL_HAVE___TYPEOF__ +# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define _GL_SIGNED_TYPE_OR_EXPR(t) 1 +#endif + +/* Bound on length of the string representing an unsigned integer + value representable in B bits. log10 (2.0) < 146/485. The + smallest value of B where this bound is not tight is 2621. */ +#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) + +/* Bound on length of the string representing an integer type or expression T. + Subtract 1 for the sign bit if T is signed, and then add 1 more for + a minus sign if needed. + + Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is + signed, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ +#define INT_STRLEN_BOUND(t) \ + (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ + - _GL_SIGNED_TYPE_OR_EXPR (t)) \ + + _GL_SIGNED_TYPE_OR_EXPR (t)) + +/* Bound on buffer size needed to represent an integer type or expression T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) + + +/* Range overflow checks. + + The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C + operators might not yield numerically correct answers due to + arithmetic overflow. They do not rely on undefined or + implementation-defined behavior. Their implementations are simple + and straightforward, but they are a bit harder to use than the + INT_<op>_OVERFLOW macros described below. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + Restrictions on *_RANGE_OVERFLOW macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, + so the arguments should not have side effects. The arithmetic + arguments (including the MIN and MAX arguments) must be of the same + integer type after the usual arithmetic conversions, and the type + must have minimum value MIN and maximum MAX. Unsigned types should + use a zero MIN of the proper type. + + These macros are tuned for constant MIN and MAX. For commutative + operations such as A + B, they are also tuned for constant B. */ + +/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (a) < (min) - (b) \ + : (max) - (b) < (a)) + +/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (max) + (b) < (a) \ + : (a) < (min) + (b)) + +/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ + ((min) < 0 \ + ? (a) < - (max) \ + : 0 < (a)) + +/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Avoid && and || as they tickle + bugs in Sun C 5.11 2010/08/13 and other compilers; see + <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */ +#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (a) < (max) / (b) \ + : (b) == -1 \ + ? 0 \ + : (min) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (a) < (min) / (b) \ + : (max) / (b) < (a))) + +/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. */ +#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ + ((min) < 0 && (b) == -1 && (a) < - (max)) + +/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. + Mathematically, % should never overflow, but on x86-like hosts + INT_MIN % -1 traps, and the C standard permits this, so treat this + as an overflow too. */ +#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ + INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max) + +/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Here, MIN and MAX are for A only, and B need + not be of the same type as the other arguments. The C standard says that + behavior is undefined for shifts unless 0 <= B < wordwidth, and that when + A is negative then A << B has undefined behavior and A >> B has + implementation-defined behavior, but do not check these other + restrictions. */ +#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ + ((a) < 0 \ + ? (a) < (min) >> (b) \ + : (max) >> (b) < (a)) + + +/* The _GL*_OVERFLOW macros have the same restrictions as the + *_RANGE_OVERFLOW macros, except that they do not assume that operands + (e.g., A and B) have the same type as MIN and MAX. Instead, they assume + that the result (e.g., A + B) has that type. */ +#define _GL_ADD_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? (b) <= (a) + (b) \ + : (b) < 0 ? (a) <= (a) + (b) \ + : (a) + (b) < (b)) +#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? 1 \ + : (b) < 0 ? (a) - (b) <= (a) \ + : (a) < (b)) +#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ + || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) +#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (b) <= (a) + (b) - 1 \ + : (b) < 0 && (a) + (b) <= (a)) +#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ + : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) + +/* Return a nonzero value if A is a mathematical multiple of B, where + A is unsigned, B is negative, and MAX is the maximum value of A's + type. A's type must be the same as (A % B)'s type. Normally (A % + -B == 0) suffices, but things get tricky if -B would overflow. */ +#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \ + (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \ + ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \ + ? (a) \ + : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \ + : (a) % - (b)) \ + == 0) + + +/* Integer overflow checks. + + The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators + might not yield numerically correct answers due to arithmetic overflow. + They work correctly on all known practical hosts, and do not rely + on undefined behavior due to signed arithmetic overflow. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_OVERFLOW (i, j)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + These macros are tuned for their last argument being a constant. + + Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, + A % B, and A << B would overflow, respectively. */ + +#define INT_ADD_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) +#define INT_SUBTRACT_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) +#define INT_NEGATE_OVERFLOW(a) \ + INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) +#define INT_MULTIPLY_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) +#define INT_DIVIDE_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW) +#define INT_REMAINDER_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW) +#define INT_LEFT_SHIFT_OVERFLOW(a, b) \ + INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \ + _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) + +/* Return 1 if the expression A <op> B would overflow, + where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, + assuming MIN and MAX are the minimum and maximum for the result type. + Arguments should be free of side effects. */ +#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ + op_result_overflow (a, b, \ + _GL_INT_MINIMUM (0 * (b) + (a)), \ + _GL_INT_MAXIMUM (0 * (b) + (a))) + +#endif /* _GL_INTPROPS_H */ diff --git a/contrib/tools/m4/lib/isnanf-nolibm.h b/contrib/tools/m4/lib/isnanf-nolibm.h new file mode 100644 index 0000000000..804c65f06c --- /dev/null +++ b/contrib/tools/m4/lib/isnanf-nolibm.h @@ -0,0 +1,40 @@ +/* Test for NaN that does not need libm. + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#if HAVE_ISNANF_IN_LIBC +/* Get declaration of isnan macro or (older) isnanf function. */ +# include <math.h> +# if __GNUC__ >= 4 && !__clang__ + /* GCC 4.0 and newer provides three built-ins for isnan. */ +# undef isnanf +# define isnanf(x) __builtin_isnanf ((float)(x)) +# elif defined isnan +# undef isnanf +# define isnanf(x) isnan ((float)(x)) +# else + /* Get declaration of isnanf(), if not declared in <math.h>. */ +# if defined __sgi + /* We can't include <ieeefp.h>, because it conflicts with our definition of + isnand. Therefore declare isnanf separately. */ +extern int isnanf (float x); +# endif +# endif +#else +/* Test whether X is a NaN. */ +# undef isnanf +# define isnanf rpl_isnanf +extern int isnanf (float x); +#endif diff --git a/contrib/tools/m4/lib/math.c b/contrib/tools/m4/lib/math.c new file mode 100644 index 0000000000..ddb2ded530 --- /dev/null +++ b/contrib/tools/m4/lib/math.c @@ -0,0 +1,3 @@ +#include <config.h> +#define _GL_MATH_INLINE _GL_EXTERN_INLINE +#include "math.h" diff --git a/contrib/tools/m4/lib/printf.c b/contrib/tools/m4/lib/printf.c new file mode 100644 index 0000000000..7f682497cc --- /dev/null +++ b/contrib/tools/m4/lib/printf.c @@ -0,0 +1,40 @@ +/* Formatted output to a stream. + Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#if 1 +# include <config.h> +#endif + +/* Specification. */ +#include <stdio.h> + +#include <stdarg.h> + +/* Print formatted output to standard output. + Return string length of formatted string. On error, return a negative + value. */ +int +printf (const char *format, ...) +{ + int retval; + va_list args; + + va_start (args, format); + retval = vfprintf (stdout, format, args); + va_end (args); + + return retval; +} diff --git a/contrib/tools/m4/lib/same-inode.h b/contrib/tools/m4/lib/same-inode.h new file mode 100644 index 0000000000..3843b07078 --- /dev/null +++ b/contrib/tools/m4/lib/same-inode.h @@ -0,0 +1,33 @@ +/* Determine whether two stat buffers refer to the same file. + + Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SAME_INODE_H +# define SAME_INODE_H 1 + +# ifdef __VMS +# define SAME_INODE(a, b) \ + ((a).st_ino[0] == (b).st_ino[0] \ + && (a).st_ino[1] == (b).st_ino[1] \ + && (a).st_ino[2] == (b).st_ino[2] \ + && (a).st_dev == (b).st_dev) +# else +# define SAME_INODE(a, b) \ + ((a).st_ino == (b).st_ino \ + && (a).st_dev == (b).st_dev) +# endif + +#endif diff --git a/contrib/tools/m4/lib/vfprintf.c b/contrib/tools/m4/lib/vfprintf.c new file mode 100644 index 0000000000..635e36eb59 --- /dev/null +++ b/contrib/tools/m4/lib/vfprintf.c @@ -0,0 +1,74 @@ +/* Formatted output to a stream. + Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#if 1 +# include <config.h> +#endif + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <limits.h> +#include <stdarg.h> +#include <stdlib.h> + +#include "fseterr.h" +#include "vasnprintf.h" + +/* Print formatted output to the stream FP. + Return string length of formatted string. On error, return a negative + value. */ +int +vfprintf (FILE *fp, const char *format, va_list args) +{ + char buf[2000]; + char *output; + size_t len; + size_t lenbuf = sizeof (buf); + + output = vasnprintf (buf, &lenbuf, format, args); + len = lenbuf; + + if (!output) + { + fseterr (fp); + return -1; + } + + if (fwrite (output, 1, len, fp) < len) + { + if (output != buf) + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } + return -1; + } + + if (output != buf) + free (output); + + if (len > INT_MAX) + { + errno = EOVERFLOW; + fseterr (fp); + return -1; + } + + return len; +} diff --git a/contrib/tools/m4/patches/o-binary-text.patch b/contrib/tools/m4/patches/o-binary-text.patch new file mode 100644 index 0000000000..d5ab371373 --- /dev/null +++ b/contrib/tools/m4/patches/o-binary-text.patch @@ -0,0 +1,14 @@ +--- a/lib/binary-io.h (212d53b3ad2c86407d6763129fe182ff06c0cd95) ++++ b/lib/binary-io.h (a21c9f41948a7d01f275966b6e9e9ff0a3ab10da) +@@ -25,3 +25,11 @@ + #include <stdio.h> + ++#ifndef O_BINARY ++ #define O_BINARY 0 ++#endif ++ ++#ifndef O_TEXT ++ #define O_TEXT 0 ++#endif ++ + #ifndef _GL_INLINE_HEADER_BEGIN diff --git a/contrib/tools/m4/src/Makefile.am b/contrib/tools/m4/src/Makefile.am new file mode 100644 index 0000000000..29e05c0def --- /dev/null +++ b/contrib/tools/m4/src/Makefile.am @@ -0,0 +1,29 @@ +## Makefile.am - template for generating Makefile via Automake +## +## Copyright (C) 2006-2013 Free Software Foundation, Inc. +## +## This file is part of GNU M4. +## +## GNU M4 is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## GNU M4 is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see <http://www.gnu.org/licenses/>. +## +## This file written by Eric Blake <ebb9@byu.net> + +AUTOMAKE_OPTIONS = nostdinc +AM_CPPFLAGS = -I$(top_srcdir)/lib -I../lib +AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) +bin_PROGRAMS = m4 +noinst_HEADERS = m4.h +m4_SOURCES = m4.c builtin.c debug.c eval.c format.c freeze.c input.c \ +macro.c output.c path.c symtab.c +m4_LDADD = ../lib/libm4.a $(LIBM4_LIBDEPS) $(LIBCSTACK) $(LIBTHREAD) |