diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-10-04 18:38:53 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-10-04 18:48:50 +0300 |
commit | 09d8f48ef2d0a92817d00bb9c8bc3ac795256ded (patch) | |
tree | 84c89c4109e645dbed2ed2a1c23049c3397a2e5c | |
parent | 28f94c4ed8634db0e3c5d44c8553d3ce4418f64c (diff) | |
download | ydb-09d8f48ef2d0a92817d00bb9c8bc3ac795256ded.tar.gz |
Remove more of unused sources from contrib/tools/m4
commit_hash:fd37308c3352f8dd47a9f4f2d4f58c2ca3f41452
32 files changed, 1 insertions, 2632 deletions
diff --git a/contrib/tools/m4/lib/calloc.c b/contrib/tools/m4/lib/calloc.c deleted file mode 100644 index 475d0aeab9..0000000000 --- a/contrib/tools/m4/lib/calloc.c +++ /dev/null @@ -1,73 +0,0 @@ -/* calloc() function that is glibc compatible. - This wrapper function is required at least on Tru64 UNIX 5.1 and mingw. - Copyright (C) 2004-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 and Bruno Haible */ - -#include <config.h> -/* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h. */ -#ifdef calloc -# define NEED_CALLOC_GNU 1 -# undef calloc -/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU. */ -#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU -# define NEED_CALLOC_GNU 1 -#endif - -/* Specification. */ -#include <stdlib.h> - -#include <errno.h> - -/* Call the system's calloc below. */ -#undef calloc - -/* Allocate and zero-fill an NxS-byte block of memory from the heap. - If N or S is zero, allocate and zero-fill a 1-byte block. */ - -void * -rpl_calloc (size_t n, size_t s) -{ - void *result; - -#if NEED_CALLOC_GNU - if (n == 0 || s == 0) - { - n = 1; - s = 1; - } - else - { - /* Defend against buggy calloc implementations that mishandle - size_t overflow. */ - size_t bytes = n * s; - if (bytes / s != n) - { - errno = ENOMEM; - return NULL; - } - } -#endif - - result = calloc (n, s); - -#if !HAVE_CALLOC_POSIX - if (result == NULL) - errno = ENOMEM; -#endif - - return result; -} diff --git a/contrib/tools/m4/lib/frexp.c b/contrib/tools/m4/lib/frexp.c deleted file mode 100644 index d847fa38b3..0000000000 --- a/contrib/tools/m4/lib/frexp.c +++ /dev/null @@ -1,168 +0,0 @@ -/* Split a double into fraction and mantissa. - 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/>. */ - -/* Written by Paolo Bonzini <bonzini@gnu.org>, 2003, and - Bruno Haible <bruno@clisp.org>, 2007. */ - -#if ! defined USE_LONG_DOUBLE -# include <config.h> -#endif - -/* Specification. */ -#include <math.h> - -#include <float.h> -#ifdef USE_LONG_DOUBLE -# include "isnanl-nolibm.h" -# include "fpucw.h" -#else -# include "isnand-nolibm.h" -#endif - -/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater - than 2, or not even a power of 2, some rounding errors can occur, so that - then the returned mantissa is only guaranteed to be <= 1.0, not < 1.0. */ - -#ifdef USE_LONG_DOUBLE -# define FUNC frexpl -# define DOUBLE long double -# define ISNAN isnanl -# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING -# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING () -# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING () -# define L_(literal) literal##L -#else -# define FUNC frexp -# define DOUBLE double -# define ISNAN isnand -# define DECL_ROUNDING -# define BEGIN_ROUNDING() -# define END_ROUNDING() -# define L_(literal) literal -#endif - -DOUBLE -FUNC (DOUBLE x, int *expptr) -{ - int sign; - int exponent; - DECL_ROUNDING - - /* Test for NaN, infinity, and zero. */ - if (ISNAN (x) || x + x == x) - { - *expptr = 0; - return x; - } - - sign = 0; - if (x < 0) - { - x = - x; - sign = -1; - } - - BEGIN_ROUNDING (); - - { - /* Since the exponent is an 'int', it fits in 64 bits. Therefore the - loops are executed no more than 64 times. */ - DOUBLE pow2[64]; /* pow2[i] = 2^2^i */ - DOUBLE powh[64]; /* powh[i] = 2^-2^i */ - int i; - - exponent = 0; - if (x >= L_(1.0)) - { - /* A positive exponent. */ - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x >= 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x >= pow2_i) - { - exponent += (1 << i); - x *= powh_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - /* Avoid making x too small, as it could become a denormalized - number and thus lose precision. */ - while (i > 0 && x < pow2[i - 1]) - { - i--; - powh_i = powh[i]; - } - exponent += (1 << i); - x *= powh_i; - /* Here 2^-2^i <= x < 1.0. */ - } - else - { - /* A negative or zero exponent. */ - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x < 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x < powh_i) - { - exponent -= (1 << i); - x *= pow2_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - /* Here 2^-2^i <= x < 1.0. */ - } - - /* Invariants: x * 2^exponent = argument, and 2^-2^i <= x < 1.0. */ - while (i > 0) - { - i--; - if (x < powh[i]) - { - exponent -= (1 << i); - x *= pow2[i]; - } - } - /* Here 0.5 <= x < 1.0. */ - } - - if (sign < 0) - x = - x; - - END_ROUNDING (); - - *expptr = exponent; - return x; -} diff --git a/contrib/tools/m4/lib/fseterr.c b/contrib/tools/m4/lib/fseterr.c deleted file mode 100644 index f2191b6923..0000000000 --- a/contrib/tools/m4/lib/fseterr.c +++ /dev/null @@ -1,81 +0,0 @@ -/* Set the error indicator of a stream. - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include "fseterr.h" - -#include <errno.h> - -#include "stdio-impl.h" - -void -fseterr (FILE *fp) -{ - /* Most systems provide FILE as a struct and the necessary bitmask in - <stdio.h>, because they need it for implementing getc() and putc() as - fast macros. */ -#if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ - fp->_flags |= _IO_ERR_SEEN; -#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ - fp_->_flags |= __SERR; -#elif defined __EMX__ /* emx+gcc */ - fp->_flags |= _IOERR; -#elif defined __minix /* Minix */ - fp->_flags |= _IOERR; -#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ - fp_->_flag |= _IOERR; -#elif WIN_SDK10 - ((TWinSdk10File*)fp)->_flags |= WIN_SDK10_IOERROR; -#elif defined __UCLIBC__ /* uClibc */ - fp->__modeflags |= __FLAG_ERROR; -#elif defined __QNX__ /* QNX */ - fp->_Mode |= 0x200 /* _MERR */; -#elif defined __MINT__ /* Atari FreeMiNT */ - fp->__error = 1; -#elif defined EPLAN9 /* Plan9 */ - if (fp->state != 0 /* CLOSED */) - fp->state = 5 /* ERR */; -#elif 0 /* unknown */ - /* Portable fallback, based on an idea by Rich Felker. - Wow! 6 system calls for something that is just a bit operation! - Not activated on any system, because there is no way to repair FP when - the sequence of system calls fails, and library code should not call - abort(). */ - int saved_errno; - int fd; - int fd2; - - saved_errno = errno; - fflush (fp); - fd = fileno (fp); - fd2 = dup (fd); - if (fd2 >= 0) - { - close (fd); - fputc ('\0', fp); /* This should set the error indicator. */ - fflush (fp); /* Or this. */ - if (dup2 (fd2, fd) < 0) - /* Whee... we botched the stream and now cannot restore it! */ - abort (); - close (fd2); - } - errno = saved_errno; -#else - #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib." -#endif -} diff --git a/contrib/tools/m4/lib/fseterr.h b/contrib/tools/m4/lib/fseterr.h deleted file mode 100644 index 630fa8647f..0000000000 --- a/contrib/tools/m4/lib/fseterr.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Set the error indicator of a stream. - Copyright (C) 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/>. */ - -#ifndef _FSETERR_H -#define _FSETERR_H - -#include <stdio.h> - -/* Set the error indicator of the stream FP. - The "error indicator" is set when an I/O operation on the stream fails, and - is cleared (together with the "end-of-file" indicator) by clearerr (FP). */ - -#if HAVE___FSETERR /* musl libc */ - -# include <stdio_ext.h> -# define fseterr(fp) __fseterr (fp) - -#else - -# ifdef __cplusplus -extern "C" { -# endif - -extern void fseterr (FILE *fp); - -# ifdef __cplusplus -} -# endif - -#endif - -#endif /* _FSETERR_H */ diff --git a/contrib/tools/m4/lib/ftello.c b/contrib/tools/m4/lib/ftello.c deleted file mode 100644 index 3a2a0f2012..0000000000 --- a/contrib/tools/m4/lib/ftello.c +++ /dev/null @@ -1,85 +0,0 @@ -/* An ftello() function that works around platform bugs. - Copyright (C) 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -/* Get lseek. */ -#include <unistd.h> - -#include "stdio-impl.h" - -off_t -ftello (FILE *fp) -#undef ftello -#if !HAVE_FTELLO -# undef ftell -# define ftello ftell -#endif -#if _GL_WINDOWS_64_BIT_OFF_T -# undef ftello -# if HAVE__FTELLI64 /* msvc, mingw64 */ -# define ftello _ftelli64 -# else /* mingw */ -# define ftello ftello64 -# endif -#endif -{ -#if LSEEK_PIPE_BROKEN - /* mingw gives bogus answers rather than failure on non-seekable files. */ - if (lseek (fileno (fp), 0, SEEK_CUR) == -1) - return -1; -#endif - -#if FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE /* Solaris */ - /* The Solaris stdio leaves the _IOREAD flag set after reading from a file - reaches EOF and the program then starts writing to the file. ftello - gets confused by this. */ - if (fp_->_flag & _IOWRT) - { - off_t pos; - - /* Call ftello nevertheless, for the side effects that it does on fp. */ - ftello (fp); - - /* Compute the file position ourselves. */ - pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR); - if (pos >= 0) - { - if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL) - pos += fp_->_ptr - fp_->_base; - } - return pos; - } -#endif - -#if defined __SL64 && defined __SCLE /* Cygwin */ - if ((fp->_flags & __SL64) == 0) - { - /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit - mode; but has an ftello that requires 64-bit mode. */ - FILE *tmp = fopen ("/dev/null", "r"); - if (!tmp) - return -1; - fp->_flags |= __SL64; - fp->_seek64 = tmp->_seek64; - fclose (tmp); - } -#endif - return ftello (fp); -} diff --git a/contrib/tools/m4/lib/get-errno.c b/contrib/tools/m4/lib/get-errno.c deleted file mode 100644 index 7865212cc7..0000000000 --- a/contrib/tools/m4/lib/get-errno.c +++ /dev/null @@ -1,42 +0,0 @@ -/* get-errno.c - get and set errno. - - Copyright (C) 2002, 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/>. */ - -/* Written by Paul Eggert. */ - -#include <config.h> - -#include "get-errno.h" - -#include <errno.h> - -/* Get and set errno. A source file that needs to set or get errno, - but doesn't need to test for specific errno values, can use these - functions to avoid namespace pollution. For example, a file that - defines EQUAL should not include <errno.h>, since <errno.h> might - define EQUAL; such a file can include <get-errno.h> instead. */ - -int -get_errno (void) -{ - return errno; -} - -void -set_errno (int e) -{ - errno = e; -} diff --git a/contrib/tools/m4/lib/get-errno.h b/contrib/tools/m4/lib/get-errno.h deleted file mode 100644 index 04b3d4c8de..0000000000 --- a/contrib/tools/m4/lib/get-errno.h +++ /dev/null @@ -1,19 +0,0 @@ -/* get-errno.h - get and set errno. - - Copyright (C) 2002, 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/>. */ - -extern int get_errno (void); -extern void set_errno (int); diff --git a/contrib/tools/m4/lib/lstat.c b/contrib/tools/m4/lib/lstat.c deleted file mode 100644 index 1a613a89c8..0000000000 --- a/contrib/tools/m4/lib/lstat.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Work around a bug of lstat on some systems - - Copyright (C) 1997-2006, 2008-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 */ - -/* If the user's config.h happens to include <sys/stat.h>, let it include only - the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to - rpl_lstat. */ -#define __need_system_sys_stat_h -#include <config.h> - -#if !HAVE_LSTAT -/* On systems that lack symlinks, our replacement <sys/stat.h> already - defined lstat as stat, so there is nothing further to do other than - avoid an empty file. */ -typedef int dummy; -#else /* HAVE_LSTAT */ - -/* Get the original definition of lstat. It might be defined as a macro. */ -# include <sys/types.h> -# include <sys/stat.h> -# undef __need_system_sys_stat_h - -static int -orig_lstat (const char *filename, struct stat *buf) -{ - return lstat (filename, buf); -} - -/* Specification. */ -/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc - eliminates this include because of the preliminary #include <sys/stat.h> - above. */ -# include "sys/stat.h" - -# include <string.h> -# include <errno.h> - -/* lstat works differently on Linux and Solaris systems. POSIX (see - "pathname resolution" in the glossary) requires that programs like - 'ls' take into consideration the fact that FILE has a trailing slash - when FILE is a symbolic link. On Linux and Solaris 10 systems, the - lstat function already has the desired semantics (in treating - 'lstat ("symlink/", sbuf)' just like 'lstat ("symlink/.", sbuf)', - but on Solaris 9 and earlier it does not. - - If FILE has a trailing slash and specifies a symbolic link, - then use stat() to get more info on the referent of FILE. - If the referent is a non-directory, then set errno to ENOTDIR - and return -1. Otherwise, return stat's result. */ - -int -rpl_lstat (const char *file, struct stat *sbuf) -{ - size_t len; - int lstat_result = orig_lstat (file, sbuf); - - if (lstat_result != 0) - return lstat_result; - - /* This replacement file can blindly check against '/' rather than - using the ISSLASH macro, because all platforms with '\\' either - lack symlinks (mingw) or have working lstat (cygwin) and thus do - not compile this file. 0 len should have already been filtered - out above, with a failure return of ENOENT. */ - len = strlen (file); - if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode)) - return 0; - - /* At this point, a trailing slash is only permitted on - symlink-to-dir; but it should have found information on the - directory, not the symlink. Call stat() to get info about the - link's referent. Our replacement stat guarantees valid results, - even if the symlink is not pointing to a directory. */ - if (!S_ISLNK (sbuf->st_mode)) - { - errno = ENOTDIR; - return -1; - } - return stat (file, sbuf); -} - -#endif /* HAVE_LSTAT */ diff --git a/contrib/tools/m4/lib/malloc.c b/contrib/tools/m4/lib/malloc.c deleted file mode 100644 index 908735d278..0000000000 --- a/contrib/tools/m4/lib/malloc.c +++ /dev/null @@ -1,56 +0,0 @@ -/* malloc() function that is glibc compatible. - - Copyright (C) 1997-1998, 2006-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, 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 and Bruno Haible */ - -#define _GL_USE_STDLIB_ALLOC 1 -#include <config.h> -/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */ -#ifdef malloc -# define NEED_MALLOC_GNU 1 -# undef malloc -/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */ -#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU -# define NEED_MALLOC_GNU 1 -#endif - -#include <stdlib.h> - -#include <errno.h> - -/* Allocate an N-byte block of memory from the heap. - If N is zero, allocate a 1-byte block. */ - -void * -rpl_malloc (size_t n) -{ - void *result; - -#if NEED_MALLOC_GNU - if (n == 0) - n = 1; -#endif - - result = malloc (n); - -#if !HAVE_MALLOC_POSIX - if (result == NULL) - errno = ENOMEM; -#endif - - return result; -} diff --git a/contrib/tools/m4/lib/mbswidth.c b/contrib/tools/m4/lib/mbswidth.c deleted file mode 100644 index 6571037592..0000000000 --- a/contrib/tools/m4/lib/mbswidth.c +++ /dev/null @@ -1,193 +0,0 @@ -/* Determine the number of screen columns needed for a string. - Copyright (C) 2000-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 <haible@clisp.cons.org>. */ - -#include <config.h> - -/* Specification. */ -#include "mbswidth.h" - -/* Get MB_CUR_MAX. */ -#include <stdlib.h> - -#include <string.h> - -/* Get isprint(). */ -#include <ctype.h> - -/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */ -#include "wchar--.h" - -/* Get iswcntrl(). */ -#include <wctype.h> - -/* Get INT_MAX. */ -#include <limits.h> - -/* Returns the number of columns needed to represent the multibyte - character string pointed to by STRING. If a non-printable character - occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. - With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is - the multibyte analogue of the wcswidth function. */ -int -mbswidth (const char *string, int flags) -{ - return mbsnwidth (string, strlen (string), flags); -} - -/* Returns the number of columns needed to represent the multibyte - character string pointed to by STRING of length NBYTES. If a - non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is - specified, -1 is returned. */ -int -mbsnwidth (const char *string, size_t nbytes, int flags) -{ - const char *p = string; - const char *plimit = p + nbytes; - int width; - - width = 0; - if (MB_CUR_MAX > 1) - { - while (p < plimit) - switch (*p) - { - case ' ': case '!': case '"': case '#': case '%': - case '&': case '\'': case '(': case ')': case '*': - case '+': case ',': case '-': case '.': case '/': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case ':': case ';': case '<': case '=': case '>': - case '?': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '[': case '\\': case ']': case '^': case '_': - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': case '{': case '|': case '}': case '~': - /* These characters are printable ASCII characters. */ - p++; - width++; - break; - default: - /* If we have a multibyte sequence, scan it up to its end. */ - { - mbstate_t mbstate; - memset (&mbstate, 0, sizeof mbstate); - do - { - wchar_t wc; - size_t bytes; - int w; - - bytes = mbrtowc (&wc, p, plimit - p, &mbstate); - - if (bytes == (size_t) -1) - /* An invalid multibyte sequence was encountered. */ - { - if (!(flags & MBSW_REJECT_INVALID)) - { - p++; - width++; - break; - } - else - return -1; - } - - if (bytes == (size_t) -2) - /* An incomplete multibyte character at the end. */ - { - if (!(flags & MBSW_REJECT_INVALID)) - { - p = plimit; - width++; - break; - } - else - return -1; - } - - if (bytes == 0) - /* A null wide character was encountered. */ - bytes = 1; - - w = wcwidth (wc); - if (w >= 0) - /* A printable multibyte character. */ - { - if (w > INT_MAX - width) - goto overflow; - width += w; - } - else - /* An unprintable multibyte character. */ - if (!(flags & MBSW_REJECT_UNPRINTABLE)) - { - if (!iswcntrl (wc)) - { - if (width == INT_MAX) - goto overflow; - width++; - } - } - else - return -1; - - p += bytes; - } - while (! mbsinit (&mbstate)); - } - break; - } - return width; - } - - while (p < plimit) - { - unsigned char c = (unsigned char) *p++; - - if (isprint (c)) - { - if (width == INT_MAX) - goto overflow; - width++; - } - else if (!(flags & MBSW_REJECT_UNPRINTABLE)) - { - if (!iscntrl (c)) - { - if (width == INT_MAX) - goto overflow; - width++; - } - } - else - return -1; - } - return width; - - overflow: - return INT_MAX; -} diff --git a/contrib/tools/m4/lib/mbswidth.h b/contrib/tools/m4/lib/mbswidth.h deleted file mode 100644 index e9c0b03938..0000000000 --- a/contrib/tools/m4/lib/mbswidth.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2004, 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/>. */ - -#include <stddef.h> - -/* Avoid a clash of our mbswidth() with a function of the same name defined - in UnixWare 7.1.1 <wchar.h>. We need this #include before the #define - below. - However, we don't want to #include <wchar.h> on all platforms because - - Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before - <wchar.h>. - - BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before - <wchar.h>. */ -#if HAVE_DECL_MBSWIDTH_IN_WCHAR_H -# include <wchar.h> -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Optional flags to influence mbswidth/mbsnwidth behavior. */ - -/* If this bit is set, return -1 upon finding an invalid or incomplete - character. Otherwise, assume invalid characters have width 1. */ -#define MBSW_REJECT_INVALID 1 - -/* If this bit is set, return -1 upon finding a non-printable character. - Otherwise, assume unprintable characters have width 0 if they are - control characters and 1 otherwise. */ -#define MBSW_REJECT_UNPRINTABLE 2 - - -/* Returns the number of screen columns needed for STRING. */ -#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ -extern int mbswidth (const char *string, int flags); - -/* Returns the number of screen columns needed for the NBYTES bytes - starting at BUF. */ -extern int mbsnwidth (const char *buf, size_t nbytes, int flags); - - -#ifdef __cplusplus -} -#endif diff --git a/contrib/tools/m4/lib/perror.c b/contrib/tools/m4/lib/perror.c deleted file mode 100644 index 74e088cc73..0000000000 --- a/contrib/tools/m4/lib/perror.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Print a message describing error code. - Copyright (C) 2008-2013 Free Software Foundation, Inc. - Written by Bruno Haible and Simon Josefsson. - - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -void -perror (const char *string) -{ - if (string != NULL && *string != '\0') - fprintf (stderr, "%s\n", string); -} diff --git a/contrib/tools/m4/lib/readlink.c b/contrib/tools/m4/lib/readlink.c deleted file mode 100644 index f83a1e0123..0000000000 --- a/contrib/tools/m4/lib/readlink.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Stub for readlink(). - Copyright (C) 2003-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <unistd.h> - -#include <errno.h> -#include <string.h> -#include <sys/stat.h> - -#if !HAVE_READLINK - -/* readlink() substitute for systems that don't have a readlink() function, - such as DJGPP 2.03 and mingw32. */ - -ssize_t -readlink (const char *name, char *buf _GL_UNUSED, - size_t bufsize _GL_UNUSED) -{ - struct stat statbuf; - - /* In general we should use lstat() here, not stat(). But on platforms - without symbolic links, lstat() - if it exists - would be equivalent to - stat(), therefore we can use stat(). This saves us a configure check. */ - if (stat (name, &statbuf) >= 0) - errno = EINVAL; - return -1; -} - -#else /* HAVE_READLINK */ - -# undef readlink - -/* readlink() wrapper that uses correct types, for systems like cygwin - 1.5.x where readlink returns int, and which rejects trailing slash, - for Solaris 9. */ - -ssize_t -rpl_readlink (const char *name, char *buf, size_t bufsize) -{ -# if READLINK_TRAILING_SLASH_BUG - size_t len = strlen (name); - if (len && name[len - 1] == '/') - { - /* Even if name without the slash is a symlink to a directory, - both lstat() and stat() must resolve the trailing slash to - the directory rather than the symlink. We can therefore - safely use stat() to distinguish between EINVAL and - ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ - struct stat st; - if (stat (name, &st) == 0) - errno = EINVAL; - return -1; - } -# endif /* READLINK_TRAILING_SLASH_BUG */ - return readlink (name, buf, bufsize); -} - -#endif /* HAVE_READLINK */ diff --git a/contrib/tools/m4/lib/rename.c b/contrib/tools/m4/lib/rename.c deleted file mode 100644 index 3e463ea86a..0000000000 --- a/contrib/tools/m4/lib/rename.c +++ /dev/null @@ -1,473 +0,0 @@ -/* Work around rename bugs in some systems. - - Copyright (C) 2001-2003, 2005-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/>. */ - -/* Written by Volker Borchert, Eric Blake. */ - -#include <config.h> - -#include <stdio.h> - -#undef rename - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* The mingw rename has problems with trailing slashes; it also - requires use of native Windows calls to allow atomic renames over - existing files. */ - -# include <errno.h> -# include <stdbool.h> -# include <stdlib.h> -# include <sys/stat.h> -# include <unistd.h> - -# define WIN32_LEAN_AND_MEAN -# include <windows.h> - -# include "dirname.h" - -/* Rename the file SRC to DST. This replacement is necessary on - Windows, on which the system rename function will not replace - an existing DST. */ -int -rpl_rename (char const *src, char const *dst) -{ - int error; - size_t src_len = strlen (src); - size_t dst_len = strlen (dst); - char *src_base = last_component (src); - char *dst_base = last_component (dst); - bool src_slash; - bool dst_slash; - bool dst_exists; - struct stat src_st; - struct stat dst_st; - - /* Filter out dot as last component. */ - if (!src_len || !dst_len) - { - errno = ENOENT; - return -1; - } - if (*src_base == '.') - { - size_t len = base_len (src_base); - if (len == 1 || (len == 2 && src_base[1] == '.')) - { - errno = EINVAL; - return -1; - } - } - if (*dst_base == '.') - { - size_t len = base_len (dst_base); - if (len == 1 || (len == 2 && dst_base[1] == '.')) - { - errno = EINVAL; - return -1; - } - } - - /* Presence of a trailing slash requires directory semantics. If - the source does not exist, or if the destination cannot be turned - into a directory, give up now. Otherwise, strip trailing slashes - before calling rename. There are no symlinks on mingw, so stat - works instead of lstat. */ - src_slash = ISSLASH (src[src_len - 1]); - dst_slash = ISSLASH (dst[dst_len - 1]); - if (stat (src, &src_st)) - return -1; - if (stat (dst, &dst_st)) - { - if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash)) - return -1; - dst_exists = false; - } - else - { - if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode)) - { - errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR; - return -1; - } - dst_exists = true; - } - - /* There are no symlinks, so if a file existed with a trailing - slash, it must be a directory, and we don't have to worry about - stripping strip trailing slash. However, mingw refuses to - replace an existing empty directory, so we have to help it out. - And canonicalize_file_name is not yet ported to mingw; however, - for directories, getcwd works as a viable alternative. Ensure - that we can get back to where we started before using it; later - attempts to return are fatal. Note that we can end up losing a - directory if rename then fails, but it was empty, so not much - damage was done. */ - if (dst_exists && S_ISDIR (dst_st.st_mode)) - { - char *cwd = getcwd (NULL, 0); - char *src_temp; - char *dst_temp; - if (!cwd || chdir (cwd)) - return -1; - if (IS_ABSOLUTE_FILE_NAME (src)) - { - dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0); - src_temp = chdir (src) ? NULL : getcwd (NULL, 0); - } - else - { - src_temp = chdir (src) ? NULL : getcwd (NULL, 0); - if (!IS_ABSOLUTE_FILE_NAME (dst) && chdir (cwd)) - abort (); - dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0); - } - if (chdir (cwd)) - abort (); - free (cwd); - if (!src_temp || !dst_temp) - { - free (src_temp); - free (dst_temp); - errno = ENOMEM; - return -1; - } - src_len = strlen (src_temp); - if (strncmp (src_temp, dst_temp, src_len) == 0 - && (ISSLASH (dst_temp[src_len]) || dst_temp[src_len] == '\0')) - { - error = dst_temp[src_len]; - free (src_temp); - free (dst_temp); - if (error) - { - errno = EINVAL; - return -1; - } - return 0; - } - if (rmdir (dst)) - { - error = errno; - free (src_temp); - free (dst_temp); - errno = error; - return -1; - } - free (src_temp); - free (dst_temp); - } - - /* MoveFileEx works if SRC is a directory without any flags, but - fails with MOVEFILE_REPLACE_EXISTING, so try without flags first. - Thankfully, MoveFileEx handles hard links correctly, even though - rename() does not. */ - if (MoveFileEx (src, dst, 0)) - return 0; - - /* Retry with MOVEFILE_REPLACE_EXISTING if the move failed - due to the destination already existing. */ - error = GetLastError (); - if (error == ERROR_FILE_EXISTS || error == ERROR_ALREADY_EXISTS) - { - if (MoveFileEx (src, dst, MOVEFILE_REPLACE_EXISTING)) - return 0; - - error = GetLastError (); - } - - switch (error) - { - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - case ERROR_BAD_PATHNAME: - case ERROR_DIRECTORY: - errno = ENOENT; - break; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - errno = EACCES; - break; - - case ERROR_OUTOFMEMORY: - errno = ENOMEM; - break; - - case ERROR_CURRENT_DIRECTORY: - errno = EBUSY; - break; - - case ERROR_NOT_SAME_DEVICE: - errno = EXDEV; - break; - - case ERROR_WRITE_PROTECT: - errno = EROFS; - break; - - case ERROR_WRITE_FAULT: - case ERROR_READ_FAULT: - case ERROR_GEN_FAILURE: - errno = EIO; - break; - - case ERROR_HANDLE_DISK_FULL: - case ERROR_DISK_FULL: - case ERROR_DISK_TOO_FRAGMENTED: - errno = ENOSPC; - break; - - case ERROR_FILE_EXISTS: - case ERROR_ALREADY_EXISTS: - errno = EEXIST; - break; - - case ERROR_BUFFER_OVERFLOW: - case ERROR_FILENAME_EXCED_RANGE: - errno = ENAMETOOLONG; - break; - - case ERROR_INVALID_NAME: - case ERROR_DELETE_PENDING: - errno = EPERM; /* ? */ - break; - -# ifndef ERROR_FILE_TOO_LARGE -/* This value is documented but not defined in all versions of windows.h. */ -# define ERROR_FILE_TOO_LARGE 223 -# endif - case ERROR_FILE_TOO_LARGE: - errno = EFBIG; - break; - - default: - errno = EINVAL; - break; - } - - return -1; -} - -#else /* ! W32 platform */ - -# include <errno.h> -# include <stdio.h> -# include <stdlib.h> -# include <string.h> -# include <sys/stat.h> -# include <unistd.h> - -# include "dirname.h" -# include "same-inode.h" - -/* Rename the file SRC to DST, fixing any trailing slash bugs. */ - -int -rpl_rename (char const *src, char const *dst) -{ - size_t src_len = strlen (src); - size_t dst_len = strlen (dst); - char *src_temp = (char *) src; - char *dst_temp = (char *) dst; - bool src_slash; - bool dst_slash; - bool dst_exists; - int ret_val = -1; - int rename_errno = ENOTDIR; - struct stat src_st; - struct stat dst_st; - - if (!src_len || !dst_len) - return rename (src, dst); /* Let strace see the ENOENT failure. */ - -# if RENAME_DEST_EXISTS_BUG - { - char *src_base = last_component (src); - char *dst_base = last_component (dst); - if (*src_base == '.') - { - size_t len = base_len (src_base); - if (len == 1 || (len == 2 && src_base[1] == '.')) - { - errno = EINVAL; - return -1; - } - } - if (*dst_base == '.') - { - size_t len = base_len (dst_base); - if (len == 1 || (len == 2 && dst_base[1] == '.')) - { - errno = EINVAL; - return -1; - } - } - } -# endif /* RENAME_DEST_EXISTS_BUG */ - - src_slash = src[src_len - 1] == '/'; - dst_slash = dst[dst_len - 1] == '/'; - -# if !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG - /* If there are no trailing slashes, then trust the native - implementation unless we also suspect issues with hard link - detection or file/directory conflicts. */ - if (!src_slash && !dst_slash) - return rename (src, dst); -# endif /* !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG */ - - /* Presence of a trailing slash requires directory semantics. If - the source does not exist, or if the destination cannot be turned - into a directory, give up now. Otherwise, strip trailing slashes - before calling rename. */ - if (lstat (src, &src_st)) - return -1; - if (lstat (dst, &dst_st)) - { - if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash)) - return -1; - dst_exists = false; - } - else - { - if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode)) - { - errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR; - return -1; - } -# if RENAME_HARD_LINK_BUG - if (SAME_INODE (src_st, dst_st)) - return 0; -# endif /* RENAME_HARD_LINK_BUG */ - dst_exists = true; - } - -# if (RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG \ - || RENAME_HARD_LINK_BUG) - /* If the only bug was that a trailing slash was allowed on a - non-existing file destination, as in Solaris 10, then we've - already covered that situation. But if there is any problem with - a trailing slash on an existing source or destination, as in - Solaris 9, or if a directory can overwrite a symlink, as on - Cygwin 1.5, or if directories cannot be created with trailing - slash, as on NetBSD 1.6, then we must strip the offending slash - and check that we have not encountered a symlink instead of a - directory. - - Stripping a trailing slash interferes with POSIX semantics, where - rename behavior on a symlink with a trailing slash operates on - the corresponding target directory. We prefer the GNU semantics - of rejecting any use of a symlink with trailing slash, but do not - enforce them, since Solaris 10 is able to obey POSIX semantics - and there might be clients expecting it, as counter-intuitive as - those semantics are. - - Technically, we could also follow the POSIX behavior by chasing a - readlink trail, but that is harder to implement. */ - if (src_slash) - { - src_temp = strdup (src); - if (!src_temp) - { - /* Rather than rely on strdup-posix, we set errno ourselves. */ - rename_errno = ENOMEM; - goto out; - } - strip_trailing_slashes (src_temp); - if (lstat (src_temp, &src_st)) - { - rename_errno = errno; - goto out; - } - if (S_ISLNK (src_st.st_mode)) - goto out; - } - if (dst_slash) - { - dst_temp = strdup (dst); - if (!dst_temp) - { - rename_errno = ENOMEM; - goto out; - } - strip_trailing_slashes (dst_temp); - if (lstat (dst_temp, &dst_st)) - { - if (errno != ENOENT) - { - rename_errno = errno; - goto out; - } - } - else if (S_ISLNK (dst_st.st_mode)) - goto out; - } -# endif /* RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG - || RENAME_HARD_LINK_BUG */ - -# if RENAME_DEST_EXISTS_BUG - /* Cygwin 1.5 sometimes behaves oddly when moving a non-empty - directory on top of an empty one (the old directory name can - reappear if the new directory tree is removed). Work around this - by removing the target first, but don't remove the target if it - is a subdirectory of the source. Note that we can end up losing - a directory if rename then fails, but it was empty, so not much - damage was done. */ - if (dst_exists && S_ISDIR (dst_st.st_mode)) - { - if (src_st.st_dev != dst_st.st_dev) - { - rename_errno = EXDEV; - goto out; - } - if (src_temp != src) - free (src_temp); - src_temp = canonicalize_file_name (src); - if (dst_temp != dst) - free (dst_temp); - dst_temp = canonicalize_file_name (dst); - if (!src_temp || !dst_temp) - { - rename_errno = ENOMEM; - goto out; - } - src_len = strlen (src_temp); - if (strncmp (src_temp, dst_temp, src_len) == 0 - && dst_temp[src_len] == '/') - { - rename_errno = EINVAL; - goto out; - } - if (rmdir (dst)) - { - rename_errno = errno; - goto out; - } - } -# endif /* RENAME_DEST_EXISTS_BUG */ - - ret_val = rename (src_temp, dst_temp); - rename_errno = errno; - out: - if (src_temp != src) - free (src_temp); - if (dst_temp != dst) - free (dst_temp); - errno = rename_errno; - return ret_val; -} -#endif /* ! W32 platform */ diff --git a/contrib/tools/m4/lib/same-inode.h b/contrib/tools/m4/lib/same-inode.h deleted file mode 100644 index 3843b07078..0000000000 --- a/contrib/tools/m4/lib/same-inode.h +++ /dev/null @@ -1,33 +0,0 @@ -/* 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/snprintf.c b/contrib/tools/m4/lib/snprintf.c deleted file mode 100644 index 9c34de3bb2..0000000000 --- a/contrib/tools/m4/lib/snprintf.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. - Written by Simon Josefsson and Paul Eggert. - - 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/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <limits.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> - -#include "vasnprintf.h" - -#if defined(_MSC_VER) && _MSC_VER < 1900 -/* Print formatted output to string STR. Similar to sprintf, but - additional length SIZE limit how much is written into STR. Returns - string length of formatted string (which may be larger than SIZE). - STR may be NULL, in which case nothing will be written. On error, - return a negative value. */ -int -snprintf (char *str, size_t size, const char *format, ...) -{ - char *output; - size_t len; - size_t lenbuf = size; - va_list args; - - va_start (args, format); - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - va_end (args); - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (INT_MAX < len) - { -#if (defined _MSC_VER) && (MSC_VER < 1800) -#else - errno = EOVERFLOW; -#endif - return -1; - } - - return len; -} -#endif diff --git a/contrib/tools/m4/lib/spawn_faction_addclose.c b/contrib/tools/m4/lib/spawn_faction_addclose.c deleted file mode 100644 index 86a9aba2e7..0000000000 --- a/contrib/tools/m4/lib/spawn_faction_addclose.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'close' for the given file descriptor during the 'spawn' call. */ -int -posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions, - int fd) -#undef posix_spawn_file_actions_addclose -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || fd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_addclose (file_actions, fd); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_close; - rec->action.open_action.fd = fd; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/m4/lib/spawn_faction_adddup2.c b/contrib/tools/m4/lib/spawn_faction_adddup2.c deleted file mode 100644 index 56ff1ecc18..0000000000 --- a/contrib/tools/m4/lib/spawn_faction_adddup2.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'dup2' for the given file descriptors during the 'spawn' call. */ -int -posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions, - int fd, int newfd) -#undef posix_spawn_file_actions_adddup2 -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_dup2; - rec->action.dup2_action.fd = fd; - rec->action.dup2_action.newfd = newfd; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/m4/lib/spawn_faction_addopen.c b/contrib/tools/m4/lib/spawn_faction_addopen.c deleted file mode 100644 index 8aaeca6a50..0000000000 --- a/contrib/tools/m4/lib/spawn_faction_addopen.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <unistd.h> - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if !HAVE_WORKING_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'open' for the given file during the 'spawn' call. */ -int -posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions, - int fd, const char *path, int oflag, - mode_t mode) -#undef posix_spawn_file_actions_addopen -{ - int maxfd = __sysconf (_SC_OPEN_MAX); - - /* Test for the validity of the file descriptor. */ - if (fd < 0 || fd >= maxfd) - return EBADF; - -#if HAVE_WORKING_POSIX_SPAWN - return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode); -#else - /* Allocate more memory if needed. */ - if (file_actions->_used == file_actions->_allocated - && __posix_spawn_file_actions_realloc (file_actions) != 0) - /* This can only mean we ran out of memory. */ - return ENOMEM; - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_open; - rec->action.open_action.fd = fd; - rec->action.open_action.path = path; - rec->action.open_action.oflag = oflag; - rec->action.open_action.mode = mode; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } -#endif -} diff --git a/contrib/tools/m4/lib/spawn_faction_destroy.c b/contrib/tools/m4/lib/spawn_faction_destroy.c deleted file mode 100644 index 942733dc6b..0000000000 --- a/contrib/tools/m4/lib/spawn_faction_destroy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <stdlib.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions) -{ - /* Free the memory allocated. */ - free (file_actions->_actions); - return 0; -} diff --git a/contrib/tools/m4/lib/spawn_faction_init.c b/contrib/tools/m4/lib/spawn_faction_init.c deleted file mode 100644 index cf1d0a6adc..0000000000 --- a/contrib/tools/m4/lib/spawn_faction_init.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#include "spawn_int.h" - - -/* Function used to increase the size of the allocated array. This - function is called from the 'add'-functions. */ -int -__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions) -{ - int newalloc = file_actions->_allocated + 8; - void *newmem = realloc (file_actions->_actions, - newalloc * sizeof (struct __spawn_action)); - - if (newmem == NULL) - /* Not enough memory. */ - return ENOMEM; - - file_actions->_actions = (struct __spawn_action *) newmem; - file_actions->_allocated = newalloc; - - return 0; -} - - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions) -{ - /* Simply clear all the elements. */ - memset (file_actions, '\0', sizeof (*file_actions)); - return 0; -} diff --git a/contrib/tools/m4/lib/spawn_int.h b/contrib/tools/m4/lib/spawn_int.h deleted file mode 100644 index f22a659fbe..0000000000 --- a/contrib/tools/m4/lib/spawn_int.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (C) 2000, 2008-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/>. */ - -#include <sys/types.h> - -/* Data structure to contain the action information. */ -struct __spawn_action -{ - enum - { - spawn_do_close, - spawn_do_dup2, - spawn_do_open - } tag; - - union - { - struct - { - int fd; - } close_action; - struct - { - int fd; - int newfd; - } dup2_action; - struct - { - int fd; - const char *path; - int oflag; - mode_t mode; - } open_action; - } action; -}; - -#if !_LIBC -# define __posix_spawn_file_actions_realloc gl_posix_spawn_file_actions_realloc -#endif -extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t * - file_actions); - -#if !_LIBC -# define __spawni gl_posix_spawn_internal -#endif -extern int __spawni (pid_t *pid, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, char *const argv[], - char *const envp[], int use_path); diff --git a/contrib/tools/m4/lib/spawnattr_destroy.c b/contrib/tools/m4/lib/spawnattr_destroy.c deleted file mode 100644 index ec6c7cf003..0000000000 --- a/contrib/tools/m4/lib/spawnattr_destroy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawnattr_destroy (posix_spawnattr_t *attr) -{ - /* Nothing to do in the moment. */ - return 0; -} diff --git a/contrib/tools/m4/lib/spawnattr_init.c b/contrib/tools/m4/lib/spawnattr_init.c deleted file mode 100644 index b050fb4ab7..0000000000 --- a/contrib/tools/m4/lib/spawnattr_init.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <string.h> - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawnattr_init (posix_spawnattr_t *attr) -{ - /* All elements have to be initialized to the default values which - is generally zero. */ - memset (attr, '\0', sizeof (*attr)); - - return 0; -} diff --git a/contrib/tools/m4/lib/spawnattr_setflags.c b/contrib/tools/m4/lib/spawnattr_setflags.c deleted file mode 100644 index babbb19593..0000000000 --- a/contrib/tools/m4/lib/spawnattr_setflags.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2000, 2004, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <errno.h> -#include <string.h> - -#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \ - | POSIX_SPAWN_SETPGROUP \ - | POSIX_SPAWN_SETSIGDEF \ - | POSIX_SPAWN_SETSIGMASK \ - | POSIX_SPAWN_SETSCHEDPARAM \ - | POSIX_SPAWN_SETSCHEDULER \ - | POSIX_SPAWN_USEVFORK) - -/* Store flags in the attribute structure. */ -int -posix_spawnattr_setflags (posix_spawnattr_t *attr, short int flags) -{ - /* Check no invalid bits are set. */ - if (flags & ~ALL_FLAGS) - return EINVAL; - - /* Store the flag word. */ - attr->_flags = flags; - - return 0; -} diff --git a/contrib/tools/m4/lib/spawnattr_setsigmask.c b/contrib/tools/m4/lib/spawnattr_setsigmask.c deleted file mode 100644 index 8aa6da9437..0000000000 --- a/contrib/tools/m4/lib/spawnattr_setsigmask.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include <string.h> - -/* Set signal mask for the new process in ATTR to SIGMASK. */ -int -posix_spawnattr_setsigmask (posix_spawnattr_t *attr, - const sigset_t *sigmask) -{ - /* Copy the sigset_t data to the user buffer. */ - memcpy (&attr->_ss, sigmask, sizeof (sigset_t)); - - return 0; -} diff --git a/contrib/tools/m4/lib/spawni.c b/contrib/tools/m4/lib/spawni.c deleted file mode 100644 index e2f7b45b60..0000000000 --- a/contrib/tools/m4/lib/spawni.c +++ /dev/null @@ -1,374 +0,0 @@ -/* Guts of POSIX spawn interface. Generic POSIX.1 version. - Copyright (C) 2000-2006, 2008-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> -#include "spawn_int.h" - -#include "palloca.h" -#include <errno.h> - -#include <fcntl.h> -#ifndef O_LARGEFILE -# define O_LARGEFILE 0 -#endif - -#if _LIBC || HAVE_PATHS_H -# include <paths.h> -#else -# define _PATH_BSHELL "/bin/sh" -#endif - -#include <signal.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#if _LIBC -# include <not-cancel.h> -#else -# define close_not_cancel close -# define open_not_cancel open -#endif - -#if _LIBC -# include <local-setxid.h> -#else -# if !HAVE_SETEUID -# define seteuid(id) setresuid (-1, id, -1) -# endif -# if !HAVE_SETEGID -# define setegid(id) setresgid (-1, id, -1) -# endif -# define local_seteuid(id) seteuid (id) -# define local_setegid(id) setegid (id) -#endif - -#if _LIBC -# define alloca __alloca -# define execve __execve -# define dup2 __dup2 -# define fork __fork -# define getgid __getgid -# define getuid __getuid -# define sched_setparam __sched_setparam -# define sched_setscheduler __sched_setscheduler -# define setpgid __setpgid -# define sigaction __sigaction -# define sigismember __sigismember -# define sigprocmask __sigprocmask -# define strchrnul __strchrnul -# define vfork __vfork -#else -# undef internal_function -# define internal_function /* empty */ -#endif - - -/* The Unix standard contains a long explanation of the way to signal - an error after the fork() was successful. Since no new wait status - was wanted there is no way to signal an error using one of the - available methods. The committee chose to signal an error by a - normal program exit with the exit code 127. */ -#define SPAWN_ERROR 127 - - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -/* Native Windows API. */ -int -__spawni (pid_t *pid, const char *file, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, char *const argv[], - char *const envp[], int use_path) -{ - /* Not yet implemented. */ - return ENOSYS; -} - -#else - - -/* The file is accessible but it is not an executable file. Invoke - the shell to interpret it as a script. */ -static void -internal_function -script_execute (const char *file, char *const argv[], char *const envp[]) -{ - /* Count the arguments. */ - int argc = 0; - while (argv[argc++]) - ; - - /* Construct an argument list for the shell. */ - { - char **new_argv = (char **) alloca ((argc + 1) * sizeof (char *)); - new_argv[0] = (char *) _PATH_BSHELL; - new_argv[1] = (char *) file; - while (argc > 1) - { - new_argv[argc] = argv[argc - 1]; - --argc; - } - - /* Execute the shell. */ - execve (new_argv[0], new_argv, envp); - } -} - - -/* Spawn a new process executing PATH with the attributes describes in *ATTRP. - Before running the process perform the actions described in FILE-ACTIONS. */ -int -__spawni (pid_t *pid, const char *file, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, char *const argv[], - char *const envp[], int use_path) -{ - pid_t new_pid; - char *path, *p, *name; - size_t len; - size_t pathlen; - - /* Do this once. */ - short int flags = attrp == NULL ? 0 : attrp->_flags; - - /* Avoid gcc warning - "variable 'flags' might be clobbered by 'longjmp' or 'vfork'" */ - (void) &flags; - - /* Generate the new process. */ -#if HAVE_VFORK - if ((flags & POSIX_SPAWN_USEVFORK) != 0 - /* If no major work is done, allow using vfork. Note that we - might perform the path searching. But this would be done by - a call to execvp(), too, and such a call must be OK according - to POSIX. */ - || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF - | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER - | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0 - && file_actions == NULL)) - new_pid = vfork (); - else -#endif - new_pid = fork (); - - if (new_pid != 0) - { - if (new_pid < 0) - return errno; - - /* The call was successful. Store the PID if necessary. */ - if (pid != NULL) - *pid = new_pid; - - return 0; - } - - /* Set signal mask. */ - if ((flags & POSIX_SPAWN_SETSIGMASK) != 0 - && sigprocmask (SIG_SETMASK, &attrp->_ss, NULL) != 0) - _exit (SPAWN_ERROR); - - /* Set signal default action. */ - if ((flags & POSIX_SPAWN_SETSIGDEF) != 0) - { - /* We have to iterate over all signals. This could possibly be - done better but it requires system specific solutions since - the sigset_t data type can be very different on different - architectures. */ - int sig; - struct sigaction sa; - - memset (&sa, '\0', sizeof (sa)); - sa.sa_handler = SIG_DFL; - - for (sig = 1; sig <= NSIG; ++sig) - if (sigismember (&attrp->_sd, sig) != 0 - && sigaction (sig, &sa, NULL) != 0) - _exit (SPAWN_ERROR); - - } - -#if (_LIBC ? defined _POSIX_PRIORITY_SCHEDULING : HAVE_SCHED_SETPARAM && HAVE_SCHED_SETSCHEDULER) - /* Set the scheduling algorithm and parameters. */ - if ((flags & (POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)) - == POSIX_SPAWN_SETSCHEDPARAM) - { - if (sched_setparam (0, &attrp->_sp) == -1) - _exit (SPAWN_ERROR); - } - else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0) - { - if (sched_setscheduler (0, attrp->_policy, - (flags & POSIX_SPAWN_SETSCHEDPARAM) != 0 - ? &attrp->_sp : NULL) == -1) - _exit (SPAWN_ERROR); - } -#endif - - /* Set the process group ID. */ - if ((flags & POSIX_SPAWN_SETPGROUP) != 0 - && setpgid (0, attrp->_pgrp) != 0) - _exit (SPAWN_ERROR); - - /* Set the effective user and group IDs. */ - if ((flags & POSIX_SPAWN_RESETIDS) != 0 - && (local_seteuid (getuid ()) != 0 - || local_setegid (getgid ()) != 0)) - _exit (SPAWN_ERROR); - - /* Execute the file actions. */ - if (file_actions != NULL) - { - int cnt; - - for (cnt = 0; cnt < file_actions->_used; ++cnt) - { - struct __spawn_action *action = &file_actions->_actions[cnt]; - - switch (action->tag) - { - case spawn_do_close: - if (close_not_cancel (action->action.close_action.fd) != 0) - /* Signal the error. */ - _exit (SPAWN_ERROR); - break; - - case spawn_do_open: - { - int new_fd = open_not_cancel (action->action.open_action.path, - action->action.open_action.oflag - | O_LARGEFILE, - action->action.open_action.mode); - - if (new_fd == -1) - /* The 'open' call failed. */ - _exit (SPAWN_ERROR); - - /* Make sure the desired file descriptor is used. */ - if (new_fd != action->action.open_action.fd) - { - if (dup2 (new_fd, action->action.open_action.fd) - != action->action.open_action.fd) - /* The 'dup2' call failed. */ - _exit (SPAWN_ERROR); - - if (close_not_cancel (new_fd) != 0) - /* The 'close' call failed. */ - _exit (SPAWN_ERROR); - } - } - break; - - case spawn_do_dup2: - if (dup2 (action->action.dup2_action.fd, - action->action.dup2_action.newfd) - != action->action.dup2_action.newfd) - /* The 'dup2' call failed. */ - _exit (SPAWN_ERROR); - break; - } - } - } - - if (! use_path || strchr (file, '/') != NULL) - { - /* The FILE parameter is actually a path. */ - execve (file, argv, envp); - - if (errno == ENOEXEC) - script_execute (file, argv, envp); - - /* Oh, oh. 'execve' returns. This is bad. */ - _exit (SPAWN_ERROR); - } - - /* We have to search for FILE on the path. */ - path = getenv ("PATH"); - if (path == NULL) - { -#if HAVE_CONFSTR - /* There is no 'PATH' in the environment. - The default search path is the current directory - followed by the path 'confstr' returns for '_CS_PATH'. */ - len = confstr (_CS_PATH, (char *) NULL, 0); - path = (char *) alloca (1 + len); - path[0] = ':'; - (void) confstr (_CS_PATH, path + 1, len); -#else - /* Pretend that the PATH contains only the current directory. */ - path = ""; -#endif - } - - len = strlen (file) + 1; - pathlen = strlen (path); - name = alloca (pathlen + len + 1); - /* Copy the file name at the top. */ - name = (char *) memcpy (name + pathlen + 1, file, len); - /* And add the slash. */ - *--name = '/'; - - p = path; - do - { - char *startp; - - path = p; - p = strchrnul (path, ':'); - - if (p == path) - /* Two adjacent colons, or a colon at the beginning or the end - of 'PATH' means to search the current directory. */ - startp = name + 1; - else - startp = (char *) memcpy (name - (p - path), path, p - path); - - /* Try to execute this name. If it works, execv will not return. */ - execve (startp, argv, envp); - - if (errno == ENOEXEC) - script_execute (startp, argv, envp); - - switch (errno) - { - case EACCES: - case ENOENT: - case ESTALE: - case ENOTDIR: - /* Those errors indicate the file is missing or not executable - by us, in which case we want to just try the next path - directory. */ - break; - - default: - /* Some other error means we found an executable file, but - something went wrong executing it; return the error to our - caller. */ - _exit (SPAWN_ERROR); - } - } - while (*p++ != '\0'); - - /* Return with an error. */ - _exit (SPAWN_ERROR); -} - -#endif diff --git a/contrib/tools/m4/lib/spawnp.c b/contrib/tools/m4/lib/spawnp.c deleted file mode 100644 index 8bc5f99aca..0000000000 --- a/contrib/tools/m4/lib/spawnp.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-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/>. */ - -#include <config.h> - -/* Specification. */ -#include <spawn.h> - -#include "spawn_int.h" - -/* Spawn a new process executing FILE with the attributes describes in *ATTRP. - Before running the process perform the actions described in FILE-ACTIONS. */ -int -posix_spawnp (pid_t *pid, const char *file, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, char *const argv[], - char *const envp[]) -{ - return __spawni (pid, file, file_actions, attrp, argv, envp, 1); -} diff --git a/contrib/tools/m4/lib/wchar--.h b/contrib/tools/m4/lib/wchar--.h deleted file mode 100644 index 41751e00ac..0000000000 --- a/contrib/tools/m4/lib/wchar--.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include <wchar.h> - -#if defined(_WIN32) -int wcwidth(wchar_t c); -#endif diff --git a/contrib/tools/m4/lib/xmemdup0.c b/contrib/tools/m4/lib/xmemdup0.c deleted file mode 100644 index c070fa6343..0000000000 --- a/contrib/tools/m4/lib/xmemdup0.c +++ /dev/null @@ -1,44 +0,0 @@ -/* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL - - Copyright (C) 2008-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/>. */ - -#include <config.h> - -#include "xmemdup0.h" -#include "xalloc.h" - -#include <string.h> - -/* Clone an arbitrary block of bytes P of size S, with error checking, - and include a terminating NUL byte. P is of type 'void const *', - to make it easier to use this with other mem* functions that return - 'void *', but since appending a NUL byte only makes sense on bytes, - the return type is 'char *'. - - The terminating NUL makes it safe to use strlen or rawmemchr to - check for embedded NUL; it also speeds up algorithms such as escape - sequence processing on arbitrary memory, by making it always safe - to read the byte after the escape character rather than having to - check if each escape character is the last byte in the object. */ - -char * -xmemdup0 (void const *p, size_t s) -{ - char *result = xcharalloc (s + 1); - memcpy (result, p, s); - result[s] = 0; - return result; -} diff --git a/contrib/tools/m4/lib/xmemdup0.h b/contrib/tools/m4/lib/xmemdup0.h deleted file mode 100644 index 9ec827107a..0000000000 --- a/contrib/tools/m4/lib/xmemdup0.h +++ /dev/null @@ -1,41 +0,0 @@ -/* xmemdup0.h -- copy a block of arbitrary bytes, plus a trailing NUL - - Copyright (C) 2008-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 XMEMDUP_H_ -# define XMEMDUP_H_ - -# include <stddef.h> - - -# ifdef __cplusplus -extern "C" { -# endif - -/* This function is always triggered when memory is exhausted. - It must be defined by the application, either explicitly - or by using gnulib's xalloc-die module. This is the - function to call when one wants the program to die because of a - memory allocation failure. */ -extern _Noreturn void xalloc_die (void); - -char *xmemdup0 (void const *p, size_t s); - -# ifdef __cplusplus -} -# endif - -#endif /* !XMEMDUP0_H_ */ diff --git a/contrib/tools/m4/lib/ya.make b/contrib/tools/m4/lib/ya.make index 21b3b59c56..3b63acf0b2 100644 --- a/contrib/tools/m4/lib/ya.make +++ b/contrib/tools/m4/lib/ya.make @@ -55,7 +55,6 @@ SRCS( c-stack.c c-strcasecmp.c c-strncasecmp.c - calloc.c clean-temp.c cloexec.c close-stream.c @@ -85,7 +84,6 @@ SRCS( fpurge.c freading.c fstat.c - get-errno.c getdtablesize.c getopt.c getopt1.c @@ -97,16 +95,13 @@ SRCS( gl_xoset.c hash.c isnand.c - isnanf.c isnanl.c + isnanf.c itold.c localcharset.c lseek.c - lstat.c - malloc.c malloca.c mbrtowc.c - mbswidth.c memchr2.c mkstemp-safer.c nl_langinfo.c @@ -120,10 +115,8 @@ SRCS( quotearg.c raise.c rawmemchr.c - readlink.c realloc.c regex.c - rename.c rmdir.c secure_getenv.c sig-handler.c @@ -150,7 +143,6 @@ SRCS( xconcat-filename.c xmalloc.c xmalloca.c - xmemdup0.c xprintf.c xsize.c xstrndup.c @@ -160,8 +152,6 @@ SRCS( IF (NOT MUSL) SRCS( freadahead.c - fseterr.c - # fseek.c ) ENDIF() @@ -179,16 +169,13 @@ ENDIF() IF (OS_WINDOWS) SRCS( - frexp.c wcrtomb.c - perror.c mkstemp.c vasprintf.c strsignal.c mkdtemp.c fseeko.c fopen.c - ftello.c gettimeofday.c localeconv.c msvc-inval.c @@ -196,18 +183,6 @@ IF (OS_WINDOWS) open.c sigaction.c sigprocmask.c - snprintf.c - spawn_faction_addclose.c - spawn_faction_adddup2.c - spawn_faction_addopen.c - spawn_faction_destroy.c - spawn_faction_init.c - spawnattr_destroy.c - spawnattr_init.c - spawnattr_setflags.c - spawnattr_setsigmask.c - spawni.c - spawnp.c waitpid.c wcwidth.c uniwidth/width.c |