From b3fe0ac62e97ea2e05fc2767989dbd7e83bc0e5c Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Sat, 19 Dec 2020 17:57:50 +0100 Subject: Correct argument order in comment * etc/ETAGS.EBNF (position): Correct comment. --- etc/ETAGS.EBNF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/ETAGS.EBNF b/etc/ETAGS.EBNF index 80deb162186..04db4e3dc8a 100644 --- a/etc/ETAGS.EBNF +++ b/etc/ETAGS.EBNF @@ -52,7 +52,7 @@ pattern ::= regstring /* a tag pattern */ tagname ::= regchar regstring /* a tag name */ -position ::= realposition | "," /* charpos,linepos */ +position ::= realposition | "," /* linepos,charpos */ realposition ::= "," unsint | unsint "," | unsint "," unsint -- cgit v1.2.1 From 52b30834fb1cf7bb20ed08ec8dc7d2d9b8a770e6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 19 Dec 2020 20:54:11 +0200 Subject: * lisp/face-remap.el (face-remap-set-base): Doc fix. (Bug#45264) --- lisp/face-remap.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lisp/face-remap.el b/lisp/face-remap.el index 028269a4b0c..cfda6428c3a 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el @@ -33,7 +33,7 @@ ;; ;; (face RELATIVE_SPECS_1 RELATIVE_SPECS_2 ... BASE_SPECS) ;; -;; The "specs" values are a lists of face names or face attribute-value +;; The "specs" values are lists of face names or face attribute-value ;; pairs, and are merged together, with earlier values taking precedence. ;; ;; The RELATIVE_SPECS_* values are added by `face-remap-add-relative' @@ -183,13 +183,13 @@ to apply on top of the normal definition of FACE." This causes the remappings specified by `face-remap-add-relative' to apply on top of the face specification given by SPECS. -The remaining arguments, SPECS, should form a list of faces. -Each list element should be either a face name or a property list +The remaining arguments, SPECS, specify the base of the remapping. +Each one of SPECS should be either a face name or a property list of face attribute/value pairs, like in a `face' text property. -If SPECS is empty, call `face-remap-reset-base' to use the normal -definition of FACE as the base remapping; note that this is -different from SPECS containing a single value nil, which means +If SPECS is empty or a single face `eq' to FACE, call `face-remap-reset-base' +to use the normal definition of FACE as the base remapping; note that +this is different from SPECS containing a single value nil, which means not to inherit from the global definition of FACE at all." (while (and (consp specs) (not (null (car specs))) (null (cdr specs))) (setq specs (car specs))) -- cgit v1.2.1 From 711fe70dd8bcee840ba9b91e85eac56b97850ada Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 21 Dec 2020 15:43:05 +0100 Subject: * doc/misc/efaq.texi (Latest version of Emacs): Bump version. --- doc/misc/efaq.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index f948a489f44..0fc91933f4b 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -951,7 +951,7 @@ conventions}). Emacs @value{EMACSVER} is the current version as of this writing. A version number with two components (e.g., @samp{24.5}) indicates a released version; three components indicate a development -version (e.g., @samp{27.0.50} is what will eventually become @samp{27.1}). +version (e.g., @samp{28.0.50} is what will eventually become @samp{28.1}). Emacs is under active development, hosted at @uref{https://savannah.gnu.org/projects/emacs/, Savannah}. -- cgit v1.2.1 From a90836c6386f6b35c0d36c720a529292090cf690 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 21 Dec 2020 15:57:30 +0100 Subject: * doc/misc/efaq.texi (New in Emacs 27): Add section. --- doc/misc/efaq.texi | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi index 0fc91933f4b..e9703e75197 100644 --- a/doc/misc/efaq.texi +++ b/doc/misc/efaq.texi @@ -901,6 +901,7 @@ status of its latest version. @menu * Origin of the term Emacs:: * Latest version of Emacs:: +* New in Emacs 27:: * New in Emacs 26:: * New in Emacs 25:: * New in Emacs 24:: @@ -970,6 +971,63 @@ Emacs, type @kbd{C-h C-n} (@kbd{M-x view-emacs-news}). As of Emacs 22, you can give this command a prefix argument to read about which features were new in older versions. +@node New in Emacs 27 +@section What is different about Emacs 27? +@cindex Differences between Emacs 26 and Emacs 27 +@cindex Emacs 27, new features in + +@itemize +@cindex bignum support +@item +Emacs now uses the GNU Multiple Precision (@acronym{GMP}) library to +support integers whose size is too large to support natively. The +integers supported natively are known as ``fixnums'', while the larger +ones are ``bignums''. All the arithmetic, comparison, and logical +(also known as ``bitwise'') operations where bignums make sense now +support both fixnums and bignums. + +@cindex HarfBuzz +@item +Emacs now uses HarfBuzz as its default shaping engine. + +@cindex JSON, native parsing +@item +Native support for @acronym{JSON} parsing that is much faster than +@file{json.el}. + +@item +Cairo drawing is no longer experimental. + +@cindex portable dumper +@item +Emacs now uses a ``portable dumper'' instead of unexec. This improves +compatibility with memory allocation on modern systems, and in +particular better supports the Address Space Layout Randomization +(@acronym{ASLR}) feature, a security technique used by most modern +operating systems. + +@cindex XDG convention +@item +Emacs can now use the @acronym{XDG} convention for init files. + +@cindex early init file +@item +Emacs can now be configured using an early init file. The primary +purpose is to allow customizing how the package system is initialized +given that initialization now happens before loading the regular init +file. + +@cindex tabs +@item +Built-in support for tabs (tab bar and tab line). + +@item +Support for resizing and rotating of images without ImageMagick. +@end itemize + +Consult the Emacs @file{NEWS} file (@kbd{C-h n}) for the full list of +changes in Emacs 27. + @node New in Emacs 26 @section What is different about Emacs 26? @cindex Differences between Emacs 25 and Emacs 26 -- cgit v1.2.1 From 7b3367a0b5727170a7b3f1aca022b992174cd426 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 21 Dec 2020 18:44:40 +0100 Subject: * lisp/so-long.el: Decrease use of passive voice. Suggested by Richard Stallman . --- lisp/so-long.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/so-long.el b/lisp/so-long.el index c800c7a1430..ad0f6e2add0 100644 --- a/lisp/so-long.el +++ b/lisp/so-long.el @@ -41,9 +41,9 @@ ;; simply aren't optimised (remotely) for this scenario, so performance can ;; suffer significantly. ;; -;; When such files are detected, the command `so-long' is automatically called, -;; overriding certain minor modes and variables with performance implications -;; (all configurable), in order to enhance performance in the buffer. +;; When so-long detects such a file, it calls the command `so-long', which +;; overrides certain minor modes and variables (you can configure the details) +;; to improve performance in the buffer. ;; ;; The default action enables the major mode `so-long-mode' in place of the mode ;; that Emacs selected. This ensures that the original major mode cannot affect -- cgit v1.2.1 From 7f8793e5f1c69cf9311479e69d18a62ae87e35ce Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 22 Dec 2020 10:29:37 +0100 Subject: Update to Org 9.4.4 --- lisp/org/org-agenda.el | 4 ---- lisp/org/org-capture.el | 4 ---- lisp/org/org-macs.el | 41 +++++++++++++++++++++++------------------ lisp/org/org-version.el | 4 ++-- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lisp/org/org-agenda.el b/lisp/org/org-agenda.el index 83f30bf96af..2da6451523e 100644 --- a/lisp/org/org-agenda.el +++ b/lisp/org/org-agenda.el @@ -10751,8 +10751,4 @@ when defining today." (provide 'org-agenda) -;; Local variables: -;; generated-autoload-file: "org-loaddefs.el" -;; End: - ;;; org-agenda.el ends here diff --git a/lisp/org/org-capture.el b/lisp/org/org-capture.el index a9a1181935c..d3dc0ab3e75 100644 --- a/lisp/org/org-capture.el +++ b/lisp/org/org-capture.el @@ -1947,8 +1947,4 @@ Assume sexps have been marked with (provide 'org-capture) -;; Local variables: -;; generated-autoload-file: "org-loaddefs.el" -;; End: - ;;; org-capture.el ends here diff --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el index 506fba8aaf5..d397e3ed05b 100644 --- a/lisp/org/org-macs.el +++ b/lisp/org/org-macs.el @@ -377,18 +377,25 @@ error when the user input is empty." 'org-time-stamp-inactive) (apply #'completing-read args))) -(defun org--mks-read-key (allowed-keys prompt) +(defun org--mks-read-key (allowed-keys prompt navigation-keys) "Read a key and ensure it is a member of ALLOWED-KEYS. +Enable keys to scroll the window if NAVIGATION-KEYS is set. TAB, SPC and RET are treated equivalently." - (let* ((key (char-to-string - (pcase (read-char-exclusive prompt) - ((or ?\s ?\t ?\r) ?\t) - (char char))))) - (if (member key allowed-keys) - key - (message "Invalid key: `%s'" key) - (sit-for 1) - (org--mks-read-key allowed-keys prompt)))) + (setq header-line-format (when navigation-keys "Use C-n, C-p, C-v, M-v to navigate.")) + (let ((char-key (read-char-exclusive prompt))) + (if (and navigation-keys (memq char-key '(14 16 22 134217846))) + (progn + (org-scroll char-key) + (org--mks-read-key allowed-keys prompt navigation-keys)) + (let ((key (char-to-string + (pcase char-key + ((or ?\s ?\t ?\r) ?\t) + (char char))))) + (if (member key allowed-keys) + key + (message "Invalid key: `%s'" key) + (sit-for 1) + (org--mks-read-key allowed-keys prompt navigation-keys)))))) (defun org-mks (table title &optional prompt specials) "Select a member of an alist with multiple keys. @@ -461,15 +468,13 @@ is selected, only the bare key is returned." ;; Display UI and let user select an entry or ;; a sub-level prefix. (goto-char (point-min)) - (setq header-line-format nil) (org-fit-window-to-buffer) - (unless (pos-visible-in-window-p (1- (point-max))) - (setq header-line-format "Use C-n, C-p or C-v to navigate.") - (setq allowed-keys (append allowed-keys '("\C-n" "\C-p" "\C-v")))) - (let ((pressed (org--mks-read-key allowed-keys prompt))) - (while (and (member pressed '("\C-n" "\C-p" "\C-v"))) - (org-scroll (string-to-char pressed)) - (setq pressed (org--mks-read-key allowed-keys prompt))) + (message "") ; With this line the prompt appears in + ; the minibuffer. Else keystrokes may + ; appear, which is spurious. + (let ((pressed (org--mks-read-key + allowed-keys prompt + (not (pos-visible-in-window-p (1- (point-max))))))) (setq current (concat current pressed)) (cond ((equal pressed "\C-g") (user-error "Abort")) diff --git a/lisp/org/org-version.el b/lisp/org/org-version.el index 479ca460852..25b3354bdd7 100644 --- a/lisp/org/org-version.el +++ b/lisp/org/org-version.el @@ -5,13 +5,13 @@ (defun org-release () "The release version of Org. Inserted by installing Org mode or when a release is made." - (let ((org-release "9.4.3")) + (let ((org-release "9.4.4")) org-release)) ;;;###autoload (defun org-git-version () "The Git version of Org mode. Inserted by installing Org or when a release is made." - (let ((org-git-version "release_9.4.3")) + (let ((org-git-version "release_9.4.4")) org-git-version)) (provide 'org-version) -- cgit v1.2.1 From 5d46593568073b43fb0a901cbd7e019a1797cf93 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 14 Sep 2020 12:34:56 +0200 Subject: Support build of Emacs on ARM Macos machines * configure.ac: Add support for aarch64-* on Macos (i.e., 64-bit ARM) (bug#43369). --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e93a3331b72..c683e31f688 100644 --- a/configure.ac +++ b/configure.ac @@ -703,7 +703,7 @@ case "${canonical}" in *-apple-darwin* ) case "${canonical}" in *-apple-darwin[0-9].*) unported=yes ;; - i[3456]86-* | x86_64-* ) ;; + i[3456]86-* | x86_64-* | arm-* | aarch64-* ) ;; * ) unported=yes ;; esac opsys=darwin -- cgit v1.2.1 From 6bf22c933df642f20969b17036f8da784276f588 Mon Sep 17 00:00:00 2001 From: Itai Seggev Date: Tue, 24 Nov 2020 06:52:27 +0100 Subject: Codesign the executable on recene MacOS systems * src/Makefile.in (temacs$(EXEEXT)): Codesign the executable on recent (ARM) MacOS systems (bug#43878). Without this, building Emacs fails. Copyright-paperwork-exempt: yes --- src/Makefile.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Makefile.in b/src/Makefile.in index ab63b926272..cfd322a41fa 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -337,6 +337,10 @@ DUMPING=@DUMPING@ CHECK_STRUCTS = @CHECK_STRUCTS@ HAVE_PDUMPER = @HAVE_PDUMPER@ +## ARM Macs require that all code have a valid signature. Since pump +## invalidates the signature, we must re-sign to fix it. +DO_CODESIGN=$(patsubst aarch64-apple-darwin%,yes,@configuration@) + # 'make' verbosity. AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ @@ -653,6 +657,9 @@ temacs$(EXEEXT): $(LIBXMENU) $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(EMACSRES) \ $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(W32_RES_LINK) $(LIBES) ifeq ($(HAVE_PDUMPER),yes) $(AM_V_at)$(MAKE_PDUMPER_FINGERPRINT) $@.tmp +ifeq ($(DO_CODESIGN),yes) + codesign -s - -f $@.tmp +endif endif $(AM_V_at)mv $@.tmp $@ $(MKDIR_P) $(etc) -- cgit v1.2.1 From fda9b3e83a434706c31ab1bee5c15511c0181d5a Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Wed, 23 Dec 2020 19:15:56 +0100 Subject: * src/Makefile.in (DO_CODESIGN): Fix expected architecture name. --- src/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.in b/src/Makefile.in index cfd322a41fa..eb6d2f0e91e 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -339,7 +339,7 @@ HAVE_PDUMPER = @HAVE_PDUMPER@ ## ARM Macs require that all code have a valid signature. Since pump ## invalidates the signature, we must re-sign to fix it. -DO_CODESIGN=$(patsubst aarch64-apple-darwin%,yes,@configuration@) +DO_CODESIGN=$(patsubst arm-apple-darwin%,yes,@configuration@) # 'make' verbosity. AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -- cgit v1.2.1 From 33210c8dc07fe8e1aed302aff09cac9ba798a221 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 13 Dec 2020 05:54:28 +0000 Subject: * lisp/tab-line.el: New options, faces, and functions * lisp/tab-line.el: (tab-line-tab-face-functions): New option. (tab-line-tab-inactive-alternate): New face. (tab-line-tab-special): New face. (tab-line-tab-face-inactive-alternating): New function. (tab-line-tab-face-special): New function. (tab-line-format-template): Use them. * etc/NEWS: Update. With thanks to Juri Linkov and Eli Zaretskii for their guidance. --- etc/NEWS | 12 +++++++++++ lisp/tab-line.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index dee0a37727b..bbd372c199a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -383,6 +383,18 @@ value of 'tab-bar-show'. If your mouse or trackpad supports it, you can now scroll tabs when the mouse pointer is in the tab line by scrolling left or right. +--- +*** New tab-line faces and options +The face 'tab-line-tab-special' is used for tabs whose buffers are +special, i.e. not file-backed. The face +'tab-line-tab-inactive-alternate' is used to display inactive tabs +with an alternating background color, making them easier to +distinguish between, especially if the face 'tab-line-tab' is +configured to not display with a box; this alternate face is only +applied when the option 'tab-line-tab-face-functions' is +so-configured. That option may also be used to customize tab-line +faces in other ways. + ** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and 'previous-error-no-select' bound to 'p'. diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 46bf89f14eb..c9444718536 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -27,6 +27,7 @@ ;;; Code: +(require 'cl-lib) (require 'seq) ; tab-line.el is not pre-loaded so it's safe to use it here @@ -35,6 +36,18 @@ :group 'convenience :version "27.1") +(defcustom tab-line-tab-face-functions '(tab-line-tab-face-special) + "Functions called to modify tab faces. +Each function is called with five arguments: the tab, a list of +all tabs, the face returned by the previously called modifier, +whether the tab is a buffer, and whether the tab is selected." + :type '(repeat + (choice (function-item tab-line-tab-face-special) + (function-item tab-line-tab-face-inactive-alternating) + (function :tag "Custom function"))) + :group 'tab-line + :version "28.1") + (defgroup tab-line-faces '((tab-line custom-face)) ; tab-line is defined in faces.el "Faces used in the tab line." :group 'tab-line @@ -63,6 +76,25 @@ :version "27.1" :group 'tab-line-faces) +(defface tab-line-tab-inactive-alternate + `((t (:inherit tab-line-tab-inactive :background "grey65"))) + "Alternate face for inactive tab-line tabs. +Applied to alternating tabs when option +`tab-line-tab-face-functions' includes function +`tab-line-tab-face-inactive-alternating'." + :version "28.1" + :group 'tab-line-faces) + +(defface tab-line-tab-special + '((default (:weight bold)) + (((supports :slant italic)) + (:slant italic :weight normal))) + "Face for special (i.e. non-file-backed) tabs. +Applied when option `tab-line-tab-face-functions' includes +function `tab-line-tab-face-special'." + :version "28.1" + :group 'tab-line-faces) + (defface tab-line-tab-current '((default :inherit tab-line-tab) @@ -412,7 +444,14 @@ variable `tab-line-tabs-function'." (cdr (assq 'selected tab)))) (name (if buffer-p (funcall tab-line-tab-name-function tab tabs) - (cdr (assq 'name tab))))) + (cdr (assq 'name tab)))) + (face (if selected-p + (if (eq (selected-window) (old-selected-window)) + 'tab-line-tab-current + 'tab-line-tab) + 'tab-line-tab-inactive))) + (dolist (fn tab-line-tab-face-functions) + (setf face (funcall fn tab tabs face buffer-p selected-p))) (concat separator (apply 'propertize @@ -425,11 +464,7 @@ variable `tab-line-tabs-function'." `( tab ,tab ,@(if selected-p '(selected t)) - face ,(if selected-p - (if (eq (selected-window) (old-selected-window)) - 'tab-line-tab-current - 'tab-line-tab) - 'tab-line-tab-inactive) + face ,face mouse-face tab-line-highlight))))) tabs)) (hscroll-data (tab-line-auto-hscroll strings hscroll))) @@ -453,6 +488,24 @@ variable `tab-line-tabs-function'." tab-line-new-button) (list tab-line-new-button))))) +(defun tab-line-tab-face-inactive-alternating (tab tabs face _buffer-p selected-p) + "Return FACE for TAB in TABS with alternation. +When TAB is an inactive buffer and is even-numbered, make FACE +inherit from `tab-line-tab-inactive-alternate'. For use in +`tab-line-tab-face-functions'." + (when (and (not selected-p) (cl-evenp (cl-position tab tabs))) + (setf face `(:inherit (tab-line-tab-inactive-alternate ,face)))) + face) + +(defun tab-line-tab-face-special (tab _tabs face buffer-p _selected-p) + "Return FACE for TAB according to whether it's special. +When TAB is a non-file-backed buffer, make FACE inherit from +`tab-line-tab-special'. For use in +`tab-line-tab-face-functions'." + (when (and buffer-p (not (buffer-file-name tab))) + (setf face `(:inherit (tab-line-tab-special ,face)))) + face) + (defvar tab-line-auto-hscroll) (defun tab-line-format () -- cgit v1.2.1 From 3be0dc659fd1a5bc976a545c0bdeda9a3d39e084 Mon Sep 17 00:00:00 2001 From: TEC Date: Wed, 23 Dec 2020 22:34:35 +0100 Subject: authinfo-mode: add option to not hide any elements (and add font-lock) * lisp/auth-source.el (authinfo-hide-elements): New user option. (authinfo--keywords): New variable. (authinfo-mode): Use it. (authinfo--hide-passwords): Use doc-face instead of warning for the passwords. (authinfo--toggle-display): Ditto. --- etc/NEWS | 4 ++++ lisp/auth-source.el | 45 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index bbd372c199a..b155ff9d42e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1460,6 +1460,10 @@ that makes it a valid button. ** Miscellaneous +--- +*** New user option 'authinfo-hide-elements'. +This can be set to nil to inhibit hiding passwords in .authinfo files. + +++ *** A number of new string manipulation functions have been added. 'string-clean-whitespace', 'string-fill', 'string-limit', diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 50795ce7946..27cf94d3786 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -2408,23 +2408,51 @@ MODE can be \"login\" or \"password\"." (list user password auth-info))) ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just -;;; hides passwords). +;;; hides passwords and adds basic syntax highlighting). (defcustom authinfo-hidden "password" "Regexp matching elements in .authinfo/.netrc files that should be hidden." :type 'regexp :version "27.1") +(defcustom authinfo-hide-elements t + "Whether to use `authinfo-hidden' to hide elements in authinfo files." + :type 'boolean + :version "28.1") + +(defvar authinfo--keywords + '(("^#.*" . font-lock-comment-face) + ("^\\(machine\\)[ \t]+\\([^ \t\n]+\\)" + (1 font-lock-variable-name-face) + (2 font-lock-builtin-face)) + ("\\(login\\)[ \t]+\\([^ \t\n]+\\)" + (1 font-lock-comment-delimiter-face) + (2 font-lock-keyword-face)) + ("\\(password\\)[ \t]+\\([^ \t\n]+\\)" + (1 font-lock-comment-delimiter-face) + (2 font-lock-doc-face)) + ("\\(port\\)[ \t]+\\([^ \t\n]+\\)" + (1 font-lock-comment-delimiter-face) + (2 font-lock-type-face)) + ("\\([^ \t\n]+\\)[, \t]+\\([^ \t\n]+\\)" + (1 font-lock-constant-face) + (2 nil)))) + ;;;###autoload (define-derived-mode authinfo-mode fundamental-mode "Authinfo" "Mode for editing .authinfo/.netrc files. -This is just like `fundamental-mode', but hides passwords. The -passwords are revealed when point moved into the password. +This is just like `fundamental-mode', but has basic syntax +highlighting and hides passwords. Passwords are revealed when +point is moved into the passwords (see `authinfo-hide-elements'). \\{authinfo-mode-map}" - (authinfo--hide-passwords (point-min) (point-max)) - (reveal-mode)) + (font-lock-add-keywords nil authinfo--keywords) + (setq-local comment-start "#") + (setq-local comment-end "") + (when authinfo-hide-elements + (authinfo--hide-passwords (point-min) (point-max)) + (reveal-mode))) (defun authinfo--hide-passwords (start end) (save-excursion @@ -2436,14 +2464,15 @@ passwords are revealed when point moved into the password. nil t) (when (auth-source-netrc-looking-at-token) (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) - (overlay-put overlay 'display (propertize "****" - 'face 'warning)) + (overlay-put overlay 'display + (propertize "****" 'face 'font-lock-doc-face)) (overlay-put overlay 'reveal-toggle-invisible #'authinfo--toggle-display))))))) (defun authinfo--toggle-display (overlay hide) (if hide - (overlay-put overlay 'display (propertize "****" 'face 'warning)) + (overlay-put overlay 'display + (propertize "****" 'face 'font-lock-doc-face)) (overlay-put overlay 'display nil))) (provide 'auth-source) -- cgit v1.2.1 From b68d52c81b53ebe993620e1b80a1c923987b089b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 20 Dec 2020 23:21:51 -0500 Subject: * lisp/emacs-lisp/lisp-mnt.el (lm-section-end): Stop at the right heading `lisp-outline-level` assumes the match-data is that set by `outline-regexp`. --- lisp/emacs-lisp/lisp-mnt.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el index 0d57bc16a3a..f1901563429 100644 --- a/lisp/emacs-lisp/lisp-mnt.el +++ b/lisp/emacs-lisp/lisp-mnt.el @@ -208,6 +208,7 @@ a section." (when start (save-excursion (goto-char start) + (looking-at outline-regexp) (let ((level (lisp-outline-level)) (case-fold-search t) next-section-found) @@ -218,6 +219,7 @@ a section." nil t)) (> (save-excursion (beginning-of-line) + (looking-at outline-regexp) (lisp-outline-level)) level))) (min (if next-section-found -- cgit v1.2.1 From ccb3efffc5a41353abb6ae223a7dcff1ea20e5fb Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 23 Dec 2020 18:31:28 -0500 Subject: * src/dispnew.c (sit_for): Fix bug#45292 When reading, prefer staying in the selected-window over preserving the current-buffer. --- src/dispnew.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dispnew.c b/src/dispnew.c index 89dd32ad0fb..e0a64761904 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -6057,6 +6057,8 @@ sit_for (Lisp_Object timeout, bool reading, int display_option) intmax_t sec; int nsec; bool do_display = display_option > 0; + bool curbuf_eq_winbuf + = (current_buffer == XBUFFER (XWINDOW (selected_window)->contents)); swallow_events (do_display); @@ -6111,6 +6113,13 @@ sit_for (Lisp_Object timeout, bool reading, int display_option) wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display, Qnil, NULL, 0); + if (reading && curbuf_eq_winbuf) + /* Timers and process filters/sentinels may have changed the selected + window (e.g. in response to a connection from emacsclient), in which + case we should follow it (unless we weren't in the selected-window's + buffer to start with). */ + set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents)); + return detect_input_pending () ? Qnil : Qt; } -- cgit v1.2.1 From 3096437593ca6d1ea07809f7d0e2198705f20e55 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Thu, 24 Dec 2020 11:29:27 +0000 Subject: CC Mode: introduce a new cache for brace structures. This fixes bug #45248 Also fix three infinite loops. The new cache accelerates backward searches for struct beginnings in c-looking-at-or-maybe-in-bracelist. * lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): In the final loop over unary operators, add a check (> (point) lim) to avoid certain infinite loops. (c-beginning-of-decl-1): In the first loop add a similar check on point and lim. (c-laomib-loop): New function extracted from c-looking-at-or-maybe-in-bracelist. (c-laomib-cache): New buffer local variable. (c-laomib-get-cache, c-laomib-put-cache, c-laomib-fix-elt) (c-laomib-invalidate-cache): New functions which implement the cache. (c-looking-at-or-maybe-in-bracelist): Replace two invocations of c-go-up-list-backwards with calls to c-parse-state. Extract the new function c-laomib-loop. Insert code which calls c-laomib-loop minimally, with the help of the new cache. * lisp/progmodes/cc-mode.el (c-basic-common-init): Initialise the new cach (at mode start). (c-before-change): Invalidate the new cache. (c-fl-decl-start): Add an extra check (> (point) bod-lim) to prevent looping. Determine the enclosing brace to pass as arguments to c-looking-at-or-maybe-in-bracelist. --- lisp/progmodes/cc-engine.el | 332 ++++++++++++++++++++++++++++++++------------ lisp/progmodes/cc-mode.el | 34 +++-- 2 files changed, 266 insertions(+), 100 deletions(-) diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 218bbb47cd5..51f620ea1f0 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -1414,12 +1414,14 @@ comment at the start of cc-engine.el for more info." (setq ret 'label))) ;; Skip over the unary operators that can start the statement. - (while (progn - (c-backward-syntactic-ws lim) - ;; protect AWK post-inc/decrement operators, etc. - (and (not (c-at-vsemi-p (point))) - (/= (skip-chars-backward "-.+!*&~@`#") 0))) + (while (and (> (point) lim) + (progn + (c-backward-syntactic-ws lim) + ;; protect AWK post-inc/decrement operators, etc. + (and (not (c-at-vsemi-p (point))) + (/= (skip-chars-backward "-.+!*&~@`#") 0)))) (setq pos (point))) + (goto-char pos) ret))) @@ -3567,8 +3569,9 @@ mhtml-mode." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. (defun c-get-fallback-scan-pos (here) - ;; Return a start position for building `c-state-cache' from - ;; scratch. This will be at the top level, 2 defuns back. + ;; Return a start position for building `c-state-cache' from scratch. This + ;; will be at the top level, 2 defuns back. Return nil if we don't find + ;; these defun starts a reasonable way back. (save-excursion (save-restriction (when (> here (* 10 c-state-cache-too-far)) @@ -11177,6 +11180,7 @@ comment at the start of cc-engine.el for more info." (c-backward-syntactic-ws lim) (not (or (memq (char-before) '(?\; ?} ?: nil)) (c-at-vsemi-p)))) + (not (and lim (<= (point) lim))) (save-excursion (backward-char) (not (looking-at "\\s("))) @@ -11615,6 +11619,195 @@ comment at the start of cc-engine.el for more info." (or (looking-at c-brace-list-key) (progn (goto-char here) nil)))) +(defun c-laomib-loop (lim) + ;; The "expensive" loop from `c-looking-at-or-maybe-in-bracelist'. Move + ;; backwards over comma separated sexps as far as possible, but no further + ;; than LIM, which may be nil, meaning no limit. Return the final value of + ;; `braceassignp', which is t if we encountered "= {", usually nil + ;; otherwise. + (let ((braceassignp 'dontknow) + (class-key + ;; Pike can have class definitions anywhere, so we must + ;; check for the class key here. + (and (c-major-mode-is 'pike-mode) + c-decl-block-key))) + (while (eq braceassignp 'dontknow) + (cond ((eq (char-after) ?\;) + (setq braceassignp nil)) + ((and class-key + (looking-at class-key)) + (setq braceassignp nil)) + ((and c-has-compound-literals + (looking-at c-return-key)) + (setq braceassignp t) + nil) + ((eq (char-after) ?=) + ;; We've seen a =, but must check earlier tokens so + ;; that it isn't something that should be ignored. + (setq braceassignp 'maybe) + (while (and (eq braceassignp 'maybe) + (zerop (c-backward-token-2 1 t lim))) + (setq braceassignp + (cond + ;; Check for operator = + ((and c-opt-op-identifier-prefix + (looking-at c-opt-op-identifier-prefix)) + nil) + ;; Check for `= in Pike. + ((and (c-major-mode-is 'pike-mode) + (or (eq (char-after) ?`) + ;; Special case for Pikes + ;; `[]=, since '[' is not in + ;; the punctuation class. + (and (eq (char-after) ?\[) + (eq (char-before) ?`)))) + nil) + ((looking-at "\\s.") 'maybe) + ;; make sure we're not in a C++ template + ;; argument assignment + ((and + (c-major-mode-is 'c++-mode) + (save-excursion + (let ((here (point)) + (pos< (progn + (skip-chars-backward "^<>") + (point)))) + (and (eq (char-before) ?<) + (not (c-crosses-statement-barrier-p + pos< here)) + (not (c-in-literal)) + )))) + nil) + (t t))))) + ((and + (c-major-mode-is 'c++-mode) + (eq (char-after) ?\[) + ;; Be careful of "operator []" + (not (save-excursion + (c-backward-token-2 1 nil lim) + (looking-at c-opt-op-identifier-prefix)))) + (setq braceassignp t) + nil)) + (when (eq braceassignp 'dontknow) + (cond ((and + (not (eq (char-after) ?,)) + (save-excursion + (c-backward-syntactic-ws) + (eq (char-before) ?}))) + (setq braceassignp nil)) + ((/= (c-backward-token-2 1 t lim) 0) + (if (save-excursion + (and c-has-compound-literals + (eq (c-backward-token-2 1 nil lim) 0) + (eq (char-after) ?\())) + (setq braceassignp t) + (setq braceassignp nil)))))) + braceassignp)) + +;; The following variable is a cache of up to four entries, each entry of +;; which is a list representing a call to c-laomib-loop. It contains the +;; following elements: +;; 0: `lim' argument - used as an alist key, never nil. +;; 1: Position in buffer where the scan started. +;; 2: Position in buffer where the scan ended. +;; 3: Result of the call to `c-laomib-loop'. +(defvar c-laomib-cache nil) +(make-variable-buffer-local 'c-laomib-cache) + +(defun c-laomib-get-cache (containing-sexp) + ;; Get an element from `c-laomib-cache' matching CONTAINING-SEXP. + ;; Return that element or nil if one wasn't found. + (let ((elt (assq containing-sexp c-laomib-cache))) + (when elt + ;; Move the fetched `elt' to the front of the cache. + (setq c-laomib-cache (delq elt c-laomib-cache)) + (push elt c-laomib-cache) + elt))) + +(defun c-laomib-put-cache (lim start end result) + ;; Insert a new element into `c-laomib-cache', removing another element to + ;; make room, if necessary. The four parameters LIM, START, END, RESULT are + ;; the components of the new element (see comment for `c-laomib-cache'). + ;; The return value is of no significance. + (when lim + (let ((old-elt (assq lim c-laomib-cache)) + ;; (elt (cons containing-sexp (cons start nil))) + (new-elt (list lim start end result)) + big-ptr + (cur-ptr c-laomib-cache) + togo togo-ptr (size 0) cur-size + ) + (if old-elt (setq c-laomib-cache (delq old-elt c-laomib-cache))) + + (while (>= (length c-laomib-cache) 4) + ;; We delete the least recently used elt which doesn't enclose START, + ;; or.. + (dolist (elt c-laomib-cache) + (if (or (<= start (cadr elt)) + (> start (car (cddr elt)))) + (setq togo elt))) + + ;; ... delete the least recently used elt which isn't the biggest. + (when (not togo) + (while (cdr cur-ptr) + (setq cur-size (- (nth 2 (cadr cur-ptr)) (car (cadr cur-ptr)))) + (when (> cur-size size) + (setq size cur-size + big-ptr cur-ptr)) + (setq cur-ptr (cdr cur-ptr))) + (setq togo (if (cddr big-ptr) + (car (last big-ptr)) + (car big-ptr)))) + + (setq c-laomib-cache (delq togo c-laomib-cache))) + + (push new-elt c-laomib-cache)))) + +(defun c-laomib-fix-elt (lwm elt paren-state) + ;; Correct a c-laomib-cache entry ELT with respect to buffer changes, either + ;; doing nothing, signalling it is to be deleted, or replacing its start + ;; point with one lower in the buffer than LWM. PAREN-STATE is the paren + ;; state at LWM. Return the corrected entry, or nil (if it needs deleting). + ;; Note that corrections are made by `setcar'ing the original structure, + ;; which thus remains intact. + (cond + ((or (not lwm) (> lwm (cadr elt))) + elt) + ((<= lwm (nth 2 elt)) + nil) + (t + (let (cur-brace) + ;; Search for the last brace in `paren-state' before (car `lim'). This + ;; brace will become our new 2nd element of `elt'. + (while + ;; Search one brace level per iteration. + (and paren-state + (progn + ;; (setq cur-brace (c-laomib-next-BRACE paren-state)) + (while + ;; Go past non-brace levels, one per iteration. + (and paren-state + (not (eq (char-after + (c-state-cache-top-lparen paren-state)) + ?{))) + (setq paren-state (cdr paren-state))) + (cadr paren-state)) + (> (c-state-cache-top-lparen (cdr paren-state)) (car elt))) + (setq paren-state (cdr paren-state))) + (when (cadr paren-state) + (setcar (cdr elt) (c-state-cache-top-lparen paren-state)) + elt))))) + +(defun c-laomib-invalidate-cache (beg _end) + ;; Called from late in c-before-change. Amend `c-laomib-cache' to remove + ;; details pertaining to the buffer after position BEG. + (save-excursion + (goto-char beg) + (let ((paren-state (c-parse-state))) + (dolist (elt c-laomib-cache) + (when (not (c-laomib-fix-elt beg elt paren-state)) + (setq c-laomib-cache (delq elt c-laomib-cache))))))) + (defun c-looking-at-or-maybe-in-bracelist (&optional containing-sexp lim) ;; Point is at an open brace. If this starts a brace list, return a list ;; whose car is the buffer position of the start of the construct which @@ -11635,14 +11828,10 @@ comment at the start of cc-engine.el for more info." ;; Here, "brace list" does not include the body of an enum. (save-excursion (let ((start (point)) - (class-key - ;; Pike can have class definitions anywhere, so we must - ;; check for the class key here. - (and (c-major-mode-is 'pike-mode) - c-decl-block-key)) (braceassignp 'dontknow) inexpr-brace-list bufpos macro-start res pos after-type-id-pos - in-paren parens-before-brace) + in-paren parens-before-brace + paren-state paren-pos) (setq res (c-backward-token-2 1 t lim)) ;; Checks to do only on the first sexp before the brace. @@ -11651,8 +11840,10 @@ comment at the start of cc-engine.el for more info." (cond ((and (or (not (eq res 0)) (eq (char-after) ?,)) - (c-go-up-list-backward nil lim) ; FIXME!!! Check ; `lim' 2016-07-12. - (eq (char-after) ?\()) + (setq paren-state (c-parse-state)) + (setq paren-pos (c-pull-open-brace paren-state)) + (eq (char-after paren-pos) ?\()) + (goto-char paren-pos) (setq braceassignp 'c++-noassign in-paren 'in-paren)) ((looking-at c-pre-id-bracelist-key) @@ -11669,9 +11860,11 @@ comment at the start of cc-engine.el for more info." (cond ((or (not (eq res 0)) (eq (char-after) ?,)) - (and (c-go-up-list-backward nil lim) ; FIXME!!! Check `lim' 2016-07-12. - (eq (char-after) ?\() - (setq in-paren 'in-paren))) + (and (setq paren-state (c-parse-state)) + (setq paren-pos (c-pull-open-brace paren-state)) + (eq (char-after paren-pos) ?\() + (setq in-paren 'in-paren) + (goto-char paren-pos))) ((looking-at c-pre-id-bracelist-key)) ((looking-at c-return-key)) (t (setq after-type-id-pos (point)) @@ -11724,79 +11917,36 @@ comment at the start of cc-engine.el for more info." (t (goto-char pos) - ;; Checks to do on all sexps before the brace, up to the - ;; beginning of the statement. - (while (eq braceassignp 'dontknow) - (cond ((eq (char-after) ?\;) - (setq braceassignp nil)) - ((and class-key - (looking-at class-key)) - (setq braceassignp nil)) - ((and c-has-compound-literals - (looking-at c-return-key)) - (setq braceassignp t) - nil) - ((eq (char-after) ?=) - ;; We've seen a =, but must check earlier tokens so - ;; that it isn't something that should be ignored. - (setq braceassignp 'maybe) - (while (and (eq braceassignp 'maybe) - (zerop (c-backward-token-2 1 t lim))) - (setq braceassignp - (cond - ;; Check for operator = - ((and c-opt-op-identifier-prefix - (looking-at c-opt-op-identifier-prefix)) - nil) - ;; Check for `= in Pike. - ((and (c-major-mode-is 'pike-mode) - (or (eq (char-after) ?`) - ;; Special case for Pikes - ;; `[]=, since '[' is not in - ;; the punctuation class. - (and (eq (char-after) ?\[) - (eq (char-before) ?`)))) - nil) - ((looking-at "\\s.") 'maybe) - ;; make sure we're not in a C++ template - ;; argument assignment - ((and - (c-major-mode-is 'c++-mode) - (save-excursion - (let ((here (point)) - (pos< (progn - (skip-chars-backward "^<>") - (point)))) - (and (eq (char-before) ?<) - (not (c-crosses-statement-barrier-p - pos< here)) - (not (c-in-literal)) - )))) - nil) - (t t))))) - ((and - (c-major-mode-is 'c++-mode) - (eq (char-after) ?\[) - ;; Be careful of "operator []" - (not (save-excursion - (c-backward-token-2 1 nil lim) - (looking-at c-opt-op-identifier-prefix)))) - (setq braceassignp t) - nil)) - (when (eq braceassignp 'dontknow) - (cond ((and - (not (eq (char-after) ?,)) - (save-excursion - (c-backward-syntactic-ws) - (eq (char-before) ?}))) - (setq braceassignp nil)) - ((/= (c-backward-token-2 1 t lim) 0) - (if (save-excursion - (and c-has-compound-literals - (eq (c-backward-token-2 1 nil lim) 0) - (eq (char-after) ?\())) - (setq braceassignp t) - (setq braceassignp nil)))))) + (when (eq braceassignp 'dontknow) + (let* ((cache-entry (and containing-sexp + (c-laomib-get-cache containing-sexp))) + (lim2 (or (cadr cache-entry) lim)) + sub-bassign-p) + (if cache-entry + (cond + ((<= (point) (cadr cache-entry)) + ;; We're inside the region we've already scanned over, so + ;; just go to that scan's end position. + (goto-char (nth 2 cache-entry)) + (setq braceassignp (nth 3 cache-entry))) + ((> (point) (cadr cache-entry)) + ;; We're beyond the previous scan region, so just scan as + ;; far as the end of that region. + (setq sub-bassign-p (c-laomib-loop lim2)) + (if (<= (point) (cadr cache-entry)) + (progn + (c-laomib-put-cache containing-sexp + start (nth 2 cache-entry) + (nth 3 cache-entry) ;; sub-bassign-p + ) + (setq braceassignp (nth 3 cache-entry)) + (goto-char (nth 2 cache-entry))) + (setq braceassignp sub-bassign-p))) + (t)) + + (setq braceassignp (c-laomib-loop lim)) + (when lim + (c-laomib-put-cache lim start (point) braceassignp))))) (cond (braceassignp diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 7a111017074..f6d36f5670c 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -639,6 +639,8 @@ that requires a literal mode spec at compile time." ;; doesn't work with filladapt but it's better than nothing. (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph) + ;; Initialize the cache for `c-looking-at-or-maybe-in-bracelist'. + (setq c-laomib-cache nil) ;; Initialize the three literal sub-caches. (c-truncate-lit-pos-cache 1) ;; Initialize the cache of brace pairs, and opening braces/brackets/parens. @@ -2054,7 +2056,9 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") (if c-get-state-before-change-functions (mapc (lambda (fn) (funcall fn beg end)) - c-get-state-before-change-functions)))) + c-get-state-before-change-functions)) + + (c-laomib-invalidate-cache beg end))) (c-clear-string-fences)))) (c-truncate-lit-pos-cache beg) ;; The following must be done here rather than in `c-after-change' @@ -2205,7 +2209,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") old-pos (new-pos pos) capture-opener - bod-lim bo-decl) + bod-lim bo-decl + paren-state containing-brace) (goto-char (c-point 'bol new-pos)) (unless lit-start (setq bod-lim (c-determine-limit 500)) @@ -2224,12 +2229,16 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") (setq old-pos (point)) (let (pseudo) (while - (progn - (c-syntactic-skip-backward "^;{}" bod-lim t) - (and (eq (char-before) ?}) - (save-excursion - (backward-char) - (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state)))))) + (and + ;; N.B. `c-syntactic-skip-backward' doesn't check (> (point) + ;; lim) and can loop if that's not the case. + (> (point) bod-lim) + (progn + (c-syntactic-skip-backward "^;{}" bod-lim t) + (and (eq (char-before) ?}) + (save-excursion + (backward-char) + (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state))))))) (goto-char pseudo)) t) (> (point) bod-lim) @@ -2262,7 +2271,14 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") (and (eq (char-before) ?{) (save-excursion (backward-char) - (consp (c-looking-at-or-maybe-in-bracelist)))) + (setq paren-state (c-parse-state)) + (while + (and + (setq containing-brace + (c-pull-open-brace paren-state)) + (not (eq (char-after containing-brace) ?{)))) + (consp (c-looking-at-or-maybe-in-bracelist + containing-brace containing-brace)))) ))) (not (bobp))) (backward-char)) ; back over (, [, <. -- cgit v1.2.1 From bf7041a6f6ea2d57f842b9b2915cc58a90b01406 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 24 Dec 2020 15:27:45 +0100 Subject: Centralize subprocess creation in a single function. Getting the vfork + execve combination right isn't easy, and the code was partially duplicated between callproc.c and process.c. Centralize the spawn operation in a single function that deals with the nasty details. Going forward, we should be able to use posix_spawn from either libc or Gnulib (or CreateProcessW on Windows) in the non-pty case. * src/callproc.c (emacs_spawn): New function to start an asynchronous subprocess. Merge code from 'call_process' and 'create_process' into this function. (call_process): Use new 'emacs_spawn' function. (child_setup): Make static, since there are no users outside this compilation unit left. (CHILD_SETUP_TYPE): Move from header file, since there are no users outside this compilation unit left. * src/process.c (create_process): Use new 'emacs_spawn' function. --- src/callproc.c | 270 +++++++++++++++++++++++++++++++++++++++++---------------- src/lisp.h | 6 +- src/process.c | 149 ++----------------------------- 3 files changed, 202 insertions(+), 223 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index c7f560ac3da..8603382f0c3 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -100,6 +100,15 @@ enum }; static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int, ptrdiff_t); + +#ifdef DOS_NT +# define CHILD_SETUP_TYPE int +#else +# define CHILD_SETUP_TYPE _Noreturn void +#endif + +static CHILD_SETUP_TYPE child_setup (int, int, int, char *const *, + char *const *, const char *); /* Return the current buffer's working directory, or the home directory if it's unreachable, as a string suitable for a system call. @@ -300,8 +309,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ char *tempfile = NULL; #else - sigset_t oldset; - pid_t pid; + pid_t pid = -1; #endif int child_errno; int fd_output, fd_error; @@ -588,77 +596,10 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, #ifndef MSDOS - block_input (); - block_child_signal (&oldset); - -#ifdef WINDOWSNT - pid = child_setup (filefd, fd_output, fd_error, new_argv, env, - SSDATA (current_dir)); -#else /* not WINDOWSNT */ - - /* vfork, and prevent local vars from being clobbered by the vfork. */ - { - Lisp_Object volatile buffer_volatile = buffer; - Lisp_Object volatile coding_systems_volatile = coding_systems; - Lisp_Object volatile current_dir_volatile = current_dir; - bool volatile display_p_volatile = display_p; - int volatile fd_error_volatile = fd_error; - int volatile filefd_volatile = filefd; - ptrdiff_t volatile count_volatile = count; - ptrdiff_t volatile sa_avail_volatile = sa_avail; - ptrdiff_t volatile sa_count_volatile = sa_count; - char **volatile new_argv_volatile = new_argv; - char *const *volatile env_volatile = env; - int volatile callproc_fd_volatile[CALLPROC_FDS]; - for (i = 0; i < CALLPROC_FDS; i++) - callproc_fd_volatile[i] = callproc_fd[i]; - - pid = vfork (); - - buffer = buffer_volatile; - coding_systems = coding_systems_volatile; - current_dir = current_dir_volatile; - display_p = display_p_volatile; - fd_error = fd_error_volatile; - filefd = filefd_volatile; - count = count_volatile; - sa_avail = sa_avail_volatile; - sa_count = sa_count_volatile; - new_argv = new_argv_volatile; - env = env_volatile; - - for (i = 0; i < CALLPROC_FDS; i++) - callproc_fd[i] = callproc_fd_volatile[i]; - fd_output = callproc_fd[CALLPROC_STDOUT]; - } - - if (pid == 0) - { -#ifdef DARWIN_OS - /* Work around a macOS bug, where SIGCHLD is apparently - delivered to a vforked child instead of to its parent. See: - https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html - */ - signal (SIGCHLD, SIG_DFL); -#endif - - unblock_child_signal (&oldset); - dissociate_controlling_tty (); - - /* Emacs ignores SIGPIPE, but the child should not. */ - signal (SIGPIPE, SIG_DFL); - /* Likewise for SIGPROF. */ -#ifdef SIGPROF - signal (SIGPROF, SIG_DFL); -#endif - - child_setup (filefd, fd_output, fd_error, new_argv, env, - SSDATA (current_dir)); - } - -#endif /* not WINDOWSNT */ - - child_errno = errno; + child_errno + = emacs_spawn (&pid, filefd, fd_output, fd_error, new_argv, env, + SSDATA (current_dir), NULL); + eassert ((child_errno == 0) == (0 < pid)); if (pid > 0) { @@ -678,9 +619,6 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, } } - unblock_child_signal (&oldset); - unblock_input (); - if (pid < 0) report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, child_errno); @@ -1221,7 +1159,7 @@ exec_failed (char const *name, int err) On MS-Windows, either return a pid or return -1 and set errno. On MS-DOS, either return an exit status or signal an error. */ -CHILD_SETUP_TYPE +static CHILD_SETUP_TYPE child_setup (int in, int out, int err, char *const *new_argv, char *const *env, const char *current_dir) { @@ -1287,6 +1225,184 @@ child_setup (int in, int out, int err, char *const *new_argv, #endif /* not WINDOWSNT */ } +/* Start a new asynchronous subprocess. If successful, return zero + and store the process identifier of the new process in *NEWPID. + Use STDIN, STDOUT, and STDERR as standard streams for the new + process. Use ARGV as argument vector for the new process; use + process image file ARGV[0]. Use ENVP for the environment block for + the new process. Use CWD as working directory for the new process. + If PTY is not NULL, it must be a pseudoterminal device. If PTY is + NULL, don't perform any terminal setup. */ + +int +emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, + char *const *argv, char *const *envp, const char *cwd, + const char *pty) +{ + sigset_t oldset; + int pid; + + block_input (); + block_child_signal (&oldset); + +#ifndef WINDOWSNT + /* vfork, and prevent local vars from being clobbered by the vfork. */ + pid_t *volatile newpid_volatile = newpid; + const char *volatile cwd_volatile = cwd; + const char *volatile pty_volatile = pty; + char *const *volatile argv_volatile = argv; + int volatile stdin_volatile = stdin; + int volatile stdout_volatile = stdout; + int volatile stderr_volatile = stderr; + char *const *volatile envp_volatile = envp; + +#ifdef DARWIN_OS + /* Darwin doesn't let us run setsid after a vfork, so use fork when + necessary. Below, we reset SIGCHLD handling after a vfork, as + apparently macOS can mistakenly deliver SIGCHLD to the child. */ + if (pty != NULL) + pid = fork (); + else + pid = vfork (); +#else + pid = vfork (); +#endif + + newpid = newpid_volatile; + cwd = cwd_volatile; + pty = pty_volatile; + argv = argv_volatile; + stdin = stdin_volatile; + stdout = stdout_volatile; + stderr = stderr_volatile; + envp = envp_volatile; + + if (pid == 0) +#endif /* not WINDOWSNT */ + { + bool pty_flag = pty != NULL; + /* Make the pty be the controlling terminal of the process. */ +#ifdef HAVE_PTYS + dissociate_controlling_tty (); + + /* Make the pty's terminal the controlling terminal. */ + if (pty_flag && stdin >= 0) + { +#ifdef TIOCSCTTY + /* We ignore the return value + because faith@cs.unc.edu says that is necessary on Linux. */ + ioctl (stdin, TIOCSCTTY, 0); +#endif + } +#if defined (LDISC1) + if (pty_flag && stdin >= 0) + { + struct termios t; + tcgetattr (stdin, &t); + t.c_lflag = LDISC1; + if (tcsetattr (stdin, TCSANOW, &t) < 0) + emacs_perror ("create_process/tcsetattr LDISC1"); + } +#else +#if defined (NTTYDISC) && defined (TIOCSETD) + if (pty_flag && stdin >= 0) + { + /* Use new line discipline. */ + int ldisc = NTTYDISC; + ioctl (stdin, TIOCSETD, &ldisc); + } +#endif +#endif + +#if !defined (DONT_REOPEN_PTY) +/*** There is a suggestion that this ought to be a + conditional on TIOCSPGRP, or !defined TIOCSCTTY. + Trying the latter gave the wrong results on Debian GNU/Linux 1.1; + that system does seem to need this code, even though + both TIOCSCTTY is defined. */ + /* Now close the pty (if we had it open) and reopen it. + This makes the pty the controlling terminal of the subprocess. */ + if (pty_flag) + { + + /* I wonder if emacs_close (emacs_open (pty, ...)) + would work? */ + if (stdin >= 0) + emacs_close (stdin); + stdout = stdin = emacs_open (pty, O_RDWR, 0); + + if (stdin < 0) + { + emacs_perror (pty); + _exit (EXIT_CANCELED); + } + + } +#endif /* not DONT_REOPEN_PTY */ + +#ifdef SETUP_SLAVE_PTY + if (pty_flag) + { + SETUP_SLAVE_PTY; + } +#endif /* SETUP_SLAVE_PTY */ +#endif /* HAVE_PTYS */ + +#ifdef DARWIN_OS + /* Work around a macOS bug, where SIGCHLD is apparently + delivered to a vforked child instead of to its parent. See: + https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html + */ + signal (SIGCHLD, SIG_DFL); +#endif + + signal (SIGINT, SIG_DFL); + signal (SIGQUIT, SIG_DFL); +#ifdef SIGPROF + signal (SIGPROF, SIG_DFL); +#endif + + /* Emacs ignores SIGPIPE, but the child should not. */ + signal (SIGPIPE, SIG_DFL); + /* Likewise for SIGPROF. */ +#ifdef SIGPROF + signal (SIGPROF, SIG_DFL); +#endif + + /* Stop blocking SIGCHLD in the child. */ + unblock_child_signal (&oldset); + + if (pty_flag) + child_setup_tty (stdout); + + if (stderr < 0) + stderr = stdout; +#ifdef WINDOWSNT + pid = child_setup (stdin, stdout, stderr, argv, envp, cwd); +#else /* not WINDOWSNT */ + child_setup (stdin, stdout, stderr, argv, envp, cwd); +#endif /* not WINDOWSNT */ + } + + /* Back in the parent process. */ + + int vfork_error = pid < 0 ? errno : 0; + + /* Stop blocking in the parent. */ + unblock_child_signal (&oldset); + unblock_input (); + + if (pid < 0) + { + eassert (0 < vfork_error); + return vfork_error; + } + + eassert (0 < pid); + *newpid = pid; + return 0; +} + static bool getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value, ptrdiff_t *valuelen, Lisp_Object env) diff --git a/src/lisp.h b/src/lisp.h index 1a214a3cbf6..c7188b171f8 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4493,15 +4493,13 @@ extern void setup_process_coding_systems (Lisp_Object); /* Defined in callproc.c. */ #ifdef DOS_NT -# define CHILD_SETUP_TYPE int # define CHILD_SETUP_ERROR_DESC "Spawning child process" #else -# define CHILD_SETUP_TYPE _Noreturn void # define CHILD_SETUP_ERROR_DESC "Doing vfork" #endif -extern CHILD_SETUP_TYPE child_setup (int, int, int, char *const *, - char *const *, const char *); +extern int emacs_spawn (pid_t *, int, int, int, char *const *, + char *const *, const char *, const char *); extern char *const *make_environment_block (Lisp_Object); extern void init_callproc_1 (void); extern void init_callproc (void); diff --git a/src/process.c b/src/process.c index 15b4a23784e..f3de9251b7a 100644 --- a/src/process.c +++ b/src/process.c @@ -2047,13 +2047,12 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) { struct Lisp_Process *p = XPROCESS (process); int inchannel, outchannel; - pid_t pid; + pid_t pid = -1; int vfork_errno; int forkin, forkout, forkerr = -1; bool pty_flag = 0; char pty_name[PTY_NAME_SIZE]; Lisp_Object lisp_pty_name = Qnil; - sigset_t oldset; inchannel = outchannel = -1; @@ -2130,154 +2129,20 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) setup_process_coding_systems (process); char *const *env = make_environment_block (current_dir); - block_input (); - block_child_signal (&oldset); - -#ifndef WINDOWSNT - /* vfork, and prevent local vars from being clobbered by the vfork. */ - Lisp_Object volatile current_dir_volatile = current_dir; - Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name; - char **volatile new_argv_volatile = new_argv; - int volatile forkin_volatile = forkin; - int volatile forkout_volatile = forkout; - int volatile forkerr_volatile = forkerr; - struct Lisp_Process *p_volatile = p; - char *const *volatile env_volatile = env; - -#ifdef DARWIN_OS - /* Darwin doesn't let us run setsid after a vfork, so use fork when - necessary. Also, reset SIGCHLD handling after a vfork, as - apparently macOS can mistakenly deliver SIGCHLD to the child. */ - if (pty_flag) - pid = fork (); - else - { - pid = vfork (); - if (pid == 0) - signal (SIGCHLD, SIG_DFL); - } -#else - pid = vfork (); -#endif - - current_dir = current_dir_volatile; - lisp_pty_name = lisp_pty_name_volatile; - new_argv = new_argv_volatile; - forkin = forkin_volatile; - forkout = forkout_volatile; - forkerr = forkerr_volatile; - p = p_volatile; - env = env_volatile; - pty_flag = p->pty_flag; + eassert (pty_flag == ! NILP (lisp_pty_name)); - if (pid == 0) -#endif /* not WINDOWSNT */ - { - /* Make the pty be the controlling terminal of the process. */ -#ifdef HAVE_PTYS - dissociate_controlling_tty (); + vfork_errno + = emacs_spawn (&pid, forkin, forkout, forkerr, new_argv, env, + SSDATA (current_dir), + pty_flag ? SSDATA (lisp_pty_name) : NULL); - /* Make the pty's terminal the controlling terminal. */ - if (pty_flag && forkin >= 0) - { -#ifdef TIOCSCTTY - /* We ignore the return value - because faith@cs.unc.edu says that is necessary on Linux. */ - ioctl (forkin, TIOCSCTTY, 0); -#endif - } -#if defined (LDISC1) - if (pty_flag && forkin >= 0) - { - struct termios t; - tcgetattr (forkin, &t); - t.c_lflag = LDISC1; - if (tcsetattr (forkin, TCSANOW, &t) < 0) - emacs_perror ("create_process/tcsetattr LDISC1"); - } -#else -#if defined (NTTYDISC) && defined (TIOCSETD) - if (pty_flag && forkin >= 0) - { - /* Use new line discipline. */ - int ldisc = NTTYDISC; - ioctl (forkin, TIOCSETD, &ldisc); - } -#endif -#endif + eassert ((vfork_errno == 0) == (0 < pid)); -#if !defined (DONT_REOPEN_PTY) -/*** There is a suggestion that this ought to be a - conditional on TIOCSPGRP, or !defined TIOCSCTTY. - Trying the latter gave the wrong results on Debian GNU/Linux 1.1; - that system does seem to need this code, even though - both TIOCSCTTY is defined. */ - /* Now close the pty (if we had it open) and reopen it. - This makes the pty the controlling terminal of the subprocess. */ - if (pty_flag) - { - - /* I wonder if emacs_close (emacs_open (SSDATA (lisp_pty_name), ...)) - would work? */ - if (forkin >= 0) - emacs_close (forkin); - forkout = forkin = emacs_open (SSDATA (lisp_pty_name), O_RDWR, 0); - - if (forkin < 0) - { - emacs_perror (SSDATA (lisp_pty_name)); - _exit (EXIT_CANCELED); - } - - } -#endif /* not DONT_REOPEN_PTY */ - -#ifdef SETUP_SLAVE_PTY - if (pty_flag) - { - SETUP_SLAVE_PTY; - } -#endif /* SETUP_SLAVE_PTY */ -#endif /* HAVE_PTYS */ - - signal (SIGINT, SIG_DFL); - signal (SIGQUIT, SIG_DFL); -#ifdef SIGPROF - signal (SIGPROF, SIG_DFL); -#endif - - /* Emacs ignores SIGPIPE, but the child should not. */ - signal (SIGPIPE, SIG_DFL); - - /* Stop blocking SIGCHLD in the child. */ - unblock_child_signal (&oldset); - - if (pty_flag) - child_setup_tty (forkout); - - if (forkerr < 0) - forkerr = forkout; -#ifdef WINDOWSNT - pid = child_setup (forkin, forkout, forkerr, new_argv, env, - SSDATA (current_dir)); -#else /* not WINDOWSNT */ - child_setup (forkin, forkout, forkerr, new_argv, env, - SSDATA (current_dir)); -#endif /* not WINDOWSNT */ - } - - /* Back in the parent process. */ - - vfork_errno = errno; p->pid = pid; if (pid >= 0) p->alive = 1; - /* Stop blocking in the parent. */ - unblock_child_signal (&oldset); - unblock_input (); - /* Environment block no longer needed. */ unbind_to (count, Qnil); -- cgit v1.2.1 From 26b8b30ff42568ff3e3f8599a20328a1efe93d2a Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 24 Dec 2020 16:30:53 +0100 Subject: Ensure that Gnulib objects in subdirectories are built correctly. * lib/Makefile.in (.c.o): Add missing -o option. --- lib/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile.in b/lib/Makefile.in index 06d8e56421b..d68ec131dd3 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -92,7 +92,7 @@ libegnu_a_OBJECTS = $(patsubst %.o,e-%.o,$(for_emacs_OBJECTS)) $(libegnu_a_OBJECTS) $(libgnu_a_OBJECTS): $(BUILT_SOURCES) .c.o: - $(AM_V_CC)$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $< + $(AM_V_CC)$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $< e-%.o: %.c $(AM_V_CC)$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -Demacs -o $@ $< -- cgit v1.2.1 From 29064d02c31b08ae41d41a93fd1439718373b196 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Thu, 24 Dec 2020 16:48:40 +0100 Subject: Update Gnulib. All changes in this commit are autogenerated by running admin/merge-gnulib. --- build-aux/config.guess | 221 +++++++++-------- build-aux/config.sub | 60 ++--- build-aux/install-sh | 35 ++- doc/misc/texinfo.tex | 65 ++++- lib/attribute.h | 23 +- lib/c++defs.h | 8 + lib/canonicalize-lgpl.c | 381 +++++++++++++--------------- lib/careadlinkat.c | 22 +- lib/cdefs.h | 4 +- lib/fcntl.c | 4 +- lib/fcntl.in.h | 37 ++- lib/filemode.c | 14 -- lib/fpending.c | 7 +- lib/free.c | 33 +++ lib/gnulib.mk.in | 93 +++++-- lib/idx.h | 113 +++++++++ lib/intprops.h | 50 +++- lib/malloc/scratch_buffer.h | 135 ++++++++++ lib/malloc/scratch_buffer_grow.c | 56 +++++ lib/malloc/scratch_buffer_grow_preserve.c | 67 +++++ lib/malloc/scratch_buffer_set_array_size.c | 64 +++++ lib/rawmemchr.c | 136 ++++++++++ lib/rawmemchr.valgrind | 28 +++ lib/readlink.c | 48 +++- lib/readlinkat.c | 47 +++- lib/regex_internal.c | 19 +- lib/regex_internal.h | 8 + lib/scratch_buffer.h | 29 +++ lib/signal.in.h | 6 +- lib/stdint.in.h | 5 - lib/stdio-impl.h | 2 +- lib/stdio.in.h | 183 ++++++++++---- lib/stdlib.in.h | 169 ++++++++++++- lib/string.in.h | 36 ++- lib/sys_select.in.h | 9 +- lib/sys_stat.in.h | 32 ++- lib/tempname.c | 49 ++-- lib/time.in.h | 23 +- lib/time_rz.c | 16 +- lib/unistd.in.h | 386 +++++++++++++++++++++++------ lib/xalloc-oversized.h | 2 +- m4/alloca.m4 | 4 +- m4/extensions.m4 | 160 +++++++----- m4/fcntl.m4 | 52 ++-- m4/filemode.m4 | 3 +- m4/free.m4 | 49 ++++ m4/fsusage.m4 | 3 +- m4/gnulib-common.m4 | 63 ++--- m4/gnulib-comp.m4 | 92 +++++-- m4/largefile.m4 | 2 +- m4/mbstate_t.m4 | 11 +- m4/pid_t.m4 | 38 +++ m4/rawmemchr.m4 | 20 ++ m4/readlink.m4 | 61 ++++- m4/readlinkat.m4 | 13 +- m4/std-gnu11.m4 | 5 + m4/stdint.m4 | 10 +- m4/stdio_h.m4 | 8 +- m4/stdlib_h.m4 | 36 ++- m4/sys_types_h.m4 | 22 +- m4/unistd_h.m4 | 11 +- m4/vararrays.m4 | 14 +- 62 files changed, 2547 insertions(+), 855 deletions(-) create mode 100644 lib/free.c create mode 100644 lib/idx.h create mode 100644 lib/malloc/scratch_buffer.h create mode 100644 lib/malloc/scratch_buffer_grow.c create mode 100644 lib/malloc/scratch_buffer_grow_preserve.c create mode 100644 lib/malloc/scratch_buffer_set_array_size.c create mode 100644 lib/rawmemchr.c create mode 100644 lib/rawmemchr.valgrind create mode 100644 lib/scratch_buffer.h create mode 100644 m4/free.m4 create mode 100644 m4/pid_t.m4 create mode 100644 m4/rawmemchr.m4 diff --git a/build-aux/config.guess b/build-aux/config.guess index 9aff91cfd03..699b3a10b21 100755 --- a/build-aux/config.guess +++ b/build-aux/config.guess @@ -2,7 +2,7 @@ # Attempt to guess a canonical system name. # Copyright 1992-2020 Free Software Foundation, Inc. -timestamp='2020-08-17' +timestamp='2020-11-19' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -27,12 +27,12 @@ timestamp='2020-08-17' # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] @@ -103,7 +103,7 @@ set_cc_for_build() { test "$tmp" && return 0 : "${TMPDIR=/tmp}" # shellcheck disable=SC2039 - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { tmp=$( (umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null) && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } @@ -131,16 +131,14 @@ if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown +UNAME_MACHINE=$( (uname -m) 2>/dev/null) || UNAME_MACHINE=unknown +UNAME_RELEASE=$( (uname -r) 2>/dev/null) || UNAME_RELEASE=unknown +UNAME_SYSTEM=$( (uname -s) 2>/dev/null) || UNAME_SYSTEM=unknown +UNAME_VERSION=$( (uname -v) 2>/dev/null) || UNAME_VERSION=unknown case "$UNAME_SYSTEM" in Linux|GNU|GNU/*) - # If the system lacks a compiler, then just pick glibc. - # We could probably try harder. - LIBC=gnu + LIBC=unknown set_cc_for_build cat <<-EOF > "$dummy.c" @@ -149,17 +147,29 @@ Linux|GNU|GNU/*) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc - #else + #elif defined(__GLIBC__) LIBC=gnu + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif #endif EOF - eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`" + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')" - # If ldd exists, use it to detect musl libc. - if command -v ldd >/dev/null && \ - ldd --version 2>&1 | grep -q ^musl - then - LIBC=musl + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu fi ;; esac @@ -179,19 +189,20 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \ "/sbin/$sysctl" 2>/dev/null || \ "/usr/sbin/$sysctl" 2>/dev/null || \ - echo unknown)` + echo unknown)) case "$UNAME_MACHINE_ARCH" in + aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) - arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,') + endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p') machine="${arch}${endian}"-unknown ;; *) machine="$UNAME_MACHINE_ARCH"-unknown ;; @@ -222,7 +233,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in case "$UNAME_MACHINE_ARCH" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` + abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr") ;; esac # The OS release @@ -235,7 +246,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in release='-gnu' ;; *) - release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` + release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2) ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: @@ -244,15 +255,15 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in echo "$machine-${os}${release}${abi-}" exit ;; *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + UNAME_MACHINE_ARCH=$(arch | sed 's/Bitrig.//') echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" exit ;; *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//') echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" exit ;; *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//') echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" exit ;; *:MidnightBSD:*:*) @@ -288,17 +299,17 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}') ;; *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $4}') ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + ALPHA_CPU_TYPE=$(/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1) case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE=alpha ;; @@ -336,7 +347,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`" + echo "$UNAME_MACHINE"-dec-osf"$(echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)" # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 @@ -370,7 +381,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then + if test "$( (/bin/universe) 2>/dev/null)" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd @@ -383,17 +394,17 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in + case $(/usr/bin/uname -p) in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) - echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" + echo "$UNAME_MACHINE"-ibm-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" + echo sparc-hal-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" + echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux"$UNAME_RELEASE" @@ -412,30 +423,30 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in SUN_ARCH=x86_64 fi fi - echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" + echo "$SUN_ARCH"-pc-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" + echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in + case "$(/usr/bin/arch -k)" in Series*|S4*) - UNAME_RELEASE=`uname -v` + UNAME_RELEASE=$(uname -v) ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`" + echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')" exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos"$UNAME_RELEASE" exit ;; sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + UNAME_RELEASE=$( (sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null) test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 - case "`/bin/arch`" in + case "$(/bin/arch)" in sun3) echo m68k-sun-sunos"$UNAME_RELEASE" ;; @@ -515,8 +526,8 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && - dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`"$dummy" "$dummyarg"` && + dummyarg=$(echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p') && + SYSTEM_NAME=$("$dummy" "$dummyarg") && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos"$UNAME_RELEASE" exit ;; @@ -543,7 +554,7 @@ EOF exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` + UNAME_PROCESSOR=$(/usr/bin/uname -p) if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ @@ -571,17 +582,17 @@ EOF echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) - echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`" + echo mips-sgi-irix"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/g')" exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + exit ;; # Note that: echo "'$(uname -s)'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if test -x /usr/bin/oslevel ; then - IBM_REV=`/usr/bin/oslevel` + IBM_REV=$(/usr/bin/oslevel) else IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi @@ -601,7 +612,7 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") then echo "$SYSTEM_NAME" else @@ -614,15 +625,15 @@ EOF fi exit ;; *:AIX:*:[4567]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + IBM_CPU_ID=$(/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }') if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if test -x /usr/bin/lslpp ; then - IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | - awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + IBM_REV=$(/usr/bin/lslpp -Lqc bos.rte.libc | + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/) else IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi @@ -650,14 +661,14 @@ EOF echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` + HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') case "$UNAME_MACHINE" in 9000/31?) HP_ARCH=m68000 ;; 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if test -x /usr/bin/getconf; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + sc_cpu_version=$(/usr/bin/getconf SC_CPU_VERSION 2>/dev/null) + sc_kernel_bits=$(/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null) case "$sc_cpu_version" in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 @@ -704,7 +715,7 @@ EOF exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=$("$dummy") test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac @@ -732,7 +743,7 @@ EOF echo "$HP_ARCH"-hp-hpux"$HPUX_REV" exit ;; ia64:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` + HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') echo ia64-hp-hpux"$HPUX_REV" exit ;; 3050*:HI-UX:*:*) @@ -762,7 +773,7 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; @@ -831,14 +842,14 @@ EOF echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` + FUJITSU_PROC=$(uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz) + FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') + FUJITSU_REL=$(echo "$UNAME_RELEASE" | sed -e 's/ /_/') echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') + FUJITSU_REL=$(echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/') echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) @@ -851,25 +862,25 @@ EOF echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" exit ;; arm:FreeBSD:*:*) - UNAME_PROCESSOR=`uname -p` + UNAME_PROCESSOR=$(uname -p) set_cc_for_build if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi else - echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf fi exit ;; *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` + UNAME_PROCESSOR=$(/usr/bin/uname -p) case "$UNAME_PROCESSOR" in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac - echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" + echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; i*:CYGWIN*:*) echo "$UNAME_MACHINE"-pc-cygwin @@ -905,15 +916,15 @@ EOF echo x86_64-pc-cygwin exit ;; prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" + echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; *:GNU:*:*) # the GNU system - echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`" + echo "$(echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,')-unknown-$LIBC$(echo "$UNAME_RELEASE"|sed -e 's,/.*$,,')" exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC" + echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC" exit ;; *:Minix:*:*) echo "$UNAME_MACHINE"-unknown-minix @@ -926,7 +937,7 @@ EOF echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in + case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -1035,7 +1046,7 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`" + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')" test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) @@ -1055,7 +1066,7 @@ EOF exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + case $(grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2) in PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; *) echo hppa-unknown-linux-"$LIBC" ;; @@ -1145,7 +1156,7 @@ EOF echo "$UNAME_MACHINE"-pc-msdosdjgpp exit ;; i*86:*:4.*:*) - UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` + UNAME_REL=$(echo "$UNAME_RELEASE" | sed 's/\/MP$//') if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" else @@ -1154,7 +1165,7 @@ EOF exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in + case $(/bin/uname -X | grep "^Machine") in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; @@ -1163,10 +1174,10 @@ EOF exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + UNAME_REL=$( (/bin/uname -X|grep Release|sed -e 's/.*= //')) (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 @@ -1216,7 +1227,7 @@ EOF 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ @@ -1227,7 +1238,7 @@ EOF NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ @@ -1260,7 +1271,7 @@ EOF exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` + UNAME_MACHINE=$( (uname -p) 2>/dev/null) echo "$UNAME_MACHINE"-sni-sysv4 else echo ns32k-sni-sysv @@ -1346,7 +1357,7 @@ EOF echo aarch64-apple-darwin"$UNAME_RELEASE" exit ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` + UNAME_PROCESSOR=$(uname -p) case $UNAME_PROCESSOR in unknown) UNAME_PROCESSOR=powerpc ;; esac @@ -1383,7 +1394,7 @@ EOF echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` + UNAME_PROCESSOR=$(uname -p) if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc @@ -1451,10 +1462,10 @@ EOF echo mips-sei-seiux"$UNAME_RELEASE" exit ;; *:DragonFly:*:*) - echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" + echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` + UNAME_MACHINE=$( (uname -p) 2>/dev/null) case "$UNAME_MACHINE" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; @@ -1464,7 +1475,7 @@ EOF echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`" + echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')" exit ;; i*86:rdos:*:*) echo "$UNAME_MACHINE"-pc-rdos @@ -1522,7 +1533,7 @@ main () #define __ARCHITECTURE__ "m68k" #endif int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null); if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else @@ -1614,7 +1625,7 @@ main () } EOF -$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` && +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. @@ -1639,14 +1650,14 @@ This script (version $timestamp), has failed to recognize the operating system you are using. If your script is old, overwrite *all* copies of config.guess and config.sub with the latest versions from: - https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess + https://git.savannah.gnu.org/cgit/config.git/plain/config.guess and - https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub + https://git.savannah.gnu.org/cgit/config.git/plain/config.sub EOF -year=`echo $timestamp | sed 's,-.*,,'` +year=$(echo $timestamp | sed 's,-.*,,') # shellcheck disable=SC2003 -if test "`expr "\`date +%Y\`" - "$year"`" -lt 3 ; then +if test "$(expr "$(date +%Y)" - "$year")" -lt 3 ; then cat >&2 </dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` +uname -m = $( (uname -m) 2>/dev/null || echo unknown) +uname -r = $( (uname -r) 2>/dev/null || echo unknown) +uname -s = $( (uname -s) 2>/dev/null || echo unknown) +uname -v = $( (uname -v) 2>/dev/null || echo unknown) -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` +/usr/bin/uname -p = $( (/usr/bin/uname -p) 2>/dev/null) +/bin/uname -X = $( (/bin/uname -X) 2>/dev/null) -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` +hostinfo = $( (hostinfo) 2>/dev/null) +/bin/universe = $( (/bin/universe) 2>/dev/null) +/usr/bin/arch -k = $( (/usr/bin/arch -k) 2>/dev/null) +/bin/arch = $( (/bin/arch) 2>/dev/null) +/usr/bin/oslevel = $( (/usr/bin/oslevel) 2>/dev/null) +/usr/convex/getsysinfo = $( (/usr/convex/getsysinfo) 2>/dev/null) UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" diff --git a/build-aux/config.sub b/build-aux/config.sub index 0753e308458..90bb8aeda63 100755 --- a/build-aux/config.sub +++ b/build-aux/config.sub @@ -2,7 +2,7 @@ # Configuration validation subroutine script. # Copyright 1992-2020 Free Software Foundation, Inc. -timestamp='2020-08-17' +timestamp='2020-12-22' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ timestamp='2020-08-17' # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -50,7 +50,7 @@ timestamp='2020-08-17' # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS @@ -769,22 +769,22 @@ case $basic_machine in vendor=hp ;; i*86v32) - cpu=`echo "$1" | sed -e 's/86.*/86/'` + cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv32 ;; i*86v4*) - cpu=`echo "$1" | sed -e 's/86.*/86/'` + cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv4 ;; i*86v) - cpu=`echo "$1" | sed -e 's/86.*/86/'` + cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv ;; i*86sol2) - cpu=`echo "$1" | sed -e 's/86.*/86/'` + cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=solaris2 ;; @@ -917,7 +917,7 @@ case $basic_machine in ;; leon-*|leon[3-9]-*) cpu=sparc - vendor=`echo "$basic_machine" | sed 's/-.*//'` + vendor=$(echo "$basic_machine" | sed 's/-.*//') ;; *-*) @@ -1084,7 +1084,7 @@ case $cpu-$vendor in cpu=mipsisa64sb1el ;; sh5e[lb]-*) - cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'` + cpu=$(echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/') ;; spur-*) cpu=spur @@ -1102,7 +1102,7 @@ case $cpu-$vendor in cpu=x86_64 ;; xscale-* | xscalee[bl]-*) - cpu=`echo "$cpu" | sed 's/^xscale/arm/'` + cpu=$(echo "$cpu" | sed 's/^xscale/arm/') ;; arm64-*) cpu=aarch64 @@ -1185,6 +1185,7 @@ case $cpu-$vendor in | k1om \ | le32 | le64 \ | lm32 \ + | loongarch32 | loongarch64 | loongarchx32 \ | m32c | m32r | m32rle \ | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ @@ -1241,6 +1242,7 @@ case $cpu-$vendor in | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \ | spu \ | tahoe \ + | thumbv7* \ | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \ | tron \ | ubicom32 \ @@ -1286,11 +1288,15 @@ then case $basic_os in gnu/linux*) kernel=linux - os=`echo $basic_os | sed -e 's|gnu/linux|gnu|'` + os=$(echo $basic_os | sed -e 's|gnu/linux|gnu|') + ;; + os2-emx) + kernel=os2 + os=$(echo $basic_os | sed -e 's|os2-emx|emx|') ;; nto-qnx*) kernel=nto - os=`echo $basic_os | sed -e 's|nto-qnx|qnx|'` + os=$(echo $basic_os | sed -e 's|nto-qnx|qnx|') ;; *-*) # shellcheck disable=SC2162 @@ -1301,11 +1307,11 @@ EOF # Default OS when just kernel was specified nto*) kernel=nto - os=`echo $basic_os | sed -e 's|nto|qnx|'` + os=$(echo $basic_os | sed -e 's|nto|qnx|') ;; linux*) kernel=linux - os=`echo $basic_os | sed -e 's|linux|gnu|'` + os=$(echo $basic_os | sed -e 's|linux|gnu|') ;; *) kernel= @@ -1326,7 +1332,7 @@ case $os in os=cnk ;; solaris1 | solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` + os=$(echo $os | sed -e 's|solaris1|sunos4|') ;; solaris) os=solaris2 @@ -1355,7 +1361,7 @@ case $os in os=sco3.2v4 ;; sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + os=$(echo $os | sed -e 's/sco3.2./sco3.2v/') ;; sco*v* | scout) # Don't match below @@ -1367,13 +1373,7 @@ case $os in os=psos ;; qnx*) - case $cpu in - x86 | i*86) - ;; - *) - os=nto-$os - ;; - esac + os=qnx ;; hiux*) os=hiuxwe2 @@ -1391,7 +1391,7 @@ case $os in os=lynxos ;; mac[0-9]*) - os=`echo "$os" | sed -e 's|mac|macos|'` + os=$(echo "$os" | sed -e 's|mac|macos|') ;; opened*) os=openedition @@ -1400,10 +1400,10 @@ case $os in os=os400 ;; sunos5*) - os=`echo "$os" | sed -e 's|sunos5|solaris2|'` + os=$(echo "$os" | sed -e 's|sunos5|solaris2|') ;; sunos6*) - os=`echo "$os" | sed -e 's|sunos6|solaris3|'` + os=$(echo "$os" | sed -e 's|sunos6|solaris3|') ;; wince*) os=wince @@ -1437,7 +1437,7 @@ case $os in ;; # Preserve the version number of sinix5. sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` + os=$(echo $os | sed -e 's|sinix|sysv|') ;; sinix*) os=sysv4 @@ -1722,7 +1722,7 @@ case $os in | skyos* | haiku* | rdos* | toppers* | drops* | es* \ | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ - | nsk* | powerunix* | genode* | zvmoe* ) + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*) ;; # This one is extra strict with allowed versions sco3.2v2 | sco3.2v[4-9]* | sco5v6*) @@ -1741,6 +1741,8 @@ esac case $kernel-$os in linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) ;; + uclinux-uclibc* ) + ;; -dietlibc* | -newlib* | -musl* | -uclibc* ) # These are just libc implementations, not actual OSes, and thus # require a kernel. @@ -1751,6 +1753,8 @@ case $kernel-$os in ;; nto-qnx*) ;; + os2-emx) + ;; *-eabi* | *-gnueabi*) ;; -*) diff --git a/build-aux/install-sh b/build-aux/install-sh index b34a8fc5ab9..ec298b53740 100755 --- a/build-aux/install-sh +++ b/build-aux/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2020-07-26.22; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -73,6 +73,7 @@ mode=0755 # This is like GNU 'install' as of coreutils 8.32 (2020). mkdir_umask=22 +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -103,18 +104,28 @@ Options: --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -141,8 +152,13 @@ while test $# -ne 0; do -o) chowncmd="$chownprog $2" shift;; + -p) cpprog="$cpprog -p";; + -s) stripcmd=$stripprog;; + -S) backupsuffix="$2" + shift;; + -t) is_target_a_directory=always dst_arg=$2 @@ -259,6 +275,10 @@ do dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -473,6 +493,13 @@ do then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -487,9 +514,9 @@ do # file should still install successfully. { test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || + $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 diff --git a/doc/misc/texinfo.tex b/doc/misc/texinfo.tex index 0a26e9f702c..3c7051d1c74 100644 --- a/doc/misc/texinfo.tex +++ b/doc/misc/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2020-06-25.17} +\def\texinfoversion{2020-10-24.12} % % Copyright 1985, 1986, 1988, 1990-2020 Free Software Foundation, Inc. % @@ -1088,7 +1088,7 @@ where each line of input produces a line of output.} } % The -2 in the arguments here gives all the input to TeX catcode 12 % (other) or 10 (space), preventing undefined control sequence errors. See - % https://lists.gnu.org/r/bug-texinfo/2019-08/msg00031.html + % https://lists.gnu.org/archive/html/bug-texinfo/2019-08/msg00031.html % \endgroup \def\pdfescapestring#1{\directlua{PDFescstr('\luaescapestring{#1}')}} @@ -3038,10 +3038,18 @@ end % arg (if given), and not the url (which is then just the link target). \newif\ifurefurlonlylink +% The default \pretolerance setting stops the penalty inserted in +% \urefallowbreak being a discouragement to line breaking. Set it to +% a negative value for this paragraph only. Hopefully this does not +% conflict with redefinitions of \par done elsewhere. +\def\nopretolerance{% +\pretolerance=-1 +\def\par{\endgraf\pretolerance=100 \let\par\endgraf}% +} + % The main macro is \urefbreak, which allows breaking at expected -% places within the url. (There used to be another version, which -% didn't support automatic breaking.) -\def\urefbreak{\begingroup \urefcatcodes \dourefbreak} +% places within the url. +\def\urefbreak{\nopretolerance \begingroup \urefcatcodes \dourefbreak} \let\uref=\urefbreak % \def\dourefbreak#1{\urefbreakfinish #1,,,\finish} @@ -3152,14 +3160,14 @@ end % Allow a ragged right output to aid breaking long URL's. There can % be a break at the \allowbreak with no extra glue (if the existing stretch in -% the line is sufficient), a break at the \penalty100 with extra glue added +% the line is sufficient), a break at the \penalty with extra glue added % at the end of the line, or no break at all here. % Changing the value of the penalty and/or the amount of stretch affects how % preferable one choice is over the other. \def\urefallowbreak{% - \allowbreak + \penalty0\relax \hskip 0pt plus 2 em\relax - \penalty300 + \penalty1000\relax \hskip 0pt plus -2 em\relax } @@ -3356,6 +3364,25 @@ end \def\sup{\ifmmode \expandafter\ptexsp \else \expandafter\finishsup\fi} \def\finishsup#1{$\ptexsp{\hbox{\switchtolllsize #1}}$}% +% provide this command from LaTeX as it is very common +\def\frac#1#2{{{#1}\over{#2}}} + +% @displaymath. +% \globaldefs is needed to recognize the end lines in \tex and +% \end tex. Set \thisenv as @end displaymath is seen before @end tex. +{\obeylines +\globaldefs=1 +\envdef\displaymath{% +\tex +\def\thisenv{\displaymath}% +$$% +} + +\def\Edisplaymath{$$ +\def\thisenv{\tex}% +\end tex +}} + % @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}. % Ignore unless FMTNAME == tex; then it is like @iftex and @tex, % except specified as a normal braced arg, so no newlines to worry about. @@ -7639,7 +7666,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \endgroup % \envdef\verbatim{% - \setupverbatim\doverbatim + \setnormaldispenv\setupverbatim\doverbatim } \let\Everbatim = \afterenvbreak @@ -11459,6 +11486,18 @@ directory should work if nowhere else does.} \globaldefs = 0 }} +\def\bsixpaper{{\globaldefs = 1 + \afourpaper + \internalpagesizes{140mm}{100mm}% + {-6.35mm}{-12.7mm}% + {\bindingoffset}{14pt}% + {176mm}{125mm}% + \let\SETdispenvsize=\smallword + \lispnarrowing = 0.2in + \globaldefs = 0 +}} + + % @pagesizes TEXTHEIGHT[,TEXTWIDTH] % Perhaps we should allow setting the margins, \topskip, \parskip, % and/or leading, also. Or perhaps we should compute them somehow. @@ -11472,12 +11511,12 @@ directory should work if nowhere else does.} \setleading{\textleading}% % \dimen0 = #1\relax - \advance\dimen0 by \voffset - \advance\dimen0 by 1in % reference point for DVI is 1 inch from top of page + \advance\dimen0 by 2.5in % default 1in margin above heading line + % and 1.5in to include heading, footing and + % bottom margin % \dimen2 = \hsize - \advance\dimen2 by \normaloffset - \advance\dimen2 by 1in % reference point is 1 inch from left edge of page + \advance\dimen2 by 2in % default to 1 inch margin on each side % \internalpagesizes{#1}{\hsize}% {\voffset}{\normaloffset}% diff --git a/lib/attribute.h b/lib/attribute.h index 2836b99dad0..5afcb8e81f2 100644 --- a/lib/attribute.h +++ b/lib/attribute.h @@ -80,7 +80,7 @@ /* Attributes for variadic functions. */ /* The variadic function expects a trailing NULL argument. - ATTRIBUTE_SENTINEL () - The last argument is NULL. + ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99). ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */ /* Applies to: functions. */ #define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos) @@ -170,18 +170,21 @@ /* Applies to: function. */ #define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE -/* The function does not affect observable state, and always returns a value. - Compilers can omit duplicate calls with the same arguments if - observable state is not changed between calls. (This attribute is - looser than ATTRIBUTE_CONST.) */ +/* It is OK for a compiler to omit duplicate calls with the same arguments. + This attribute is safe for a function that neither depends on + nor affects observable state, and always returns exactly once - + e.g., does not loop forever, and does not call longjmp. + (This attribute is stricter than ATTRIBUTE_PURE.) */ /* Applies to: functions. */ -#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE +#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST -/* The function neither depends on nor affects observable state, - and always returns a value. Compilers can omit duplicate calls with - the same arguments. (This attribute is stricter than ATTRIBUTE_PURE.) */ +/* It is OK for a compiler to omit duplicate calls with the same + arguments if observable state is not changed between calls. + This attribute is safe for a function that does not affect + observable state, and always returns exactly once. + (This attribute is looser than ATTRIBUTE_CONST.) */ /* Applies to: functions. */ -#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST +#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE /* The function is rarely executed. */ /* Applies to: functions. */ diff --git a/lib/c++defs.h b/lib/c++defs.h index 6a9bf295eb5..01ef8140cad 100644 --- a/lib/c++defs.h +++ b/lib/c++defs.h @@ -181,6 +181,14 @@ _GL_EXTERN_C int _gl_cxxalias_dummy #endif +/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters); + is like _GL_CXXALIAS_MDA (func, rettype, parameters); + except that the C function func may have a slightly different declaration. + A cast is used to silence the "invalid conversion" error that would + otherwise occur. */ +#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \ + _GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters) + /* _GL_CXXALIAS_SYS (func, rettype, parameters); declares a C++ alias called GNULIB_NAMESPACE::func that redirects to the system provided function func, if GNULIB_NAMESPACE diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 0b89d2a1842..584fce1cfa4 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -2,18 +2,19 @@ Copyright (C) 1996-2020 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. + 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. - This program is distributed in the hope that it will be useful, + 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. + 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 . */ + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ #ifndef _LIBC /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc @@ -21,36 +22,36 @@ # define _GL_ARG_NONNULL(params) # define _GL_USE_STDLIB_ALLOC 1 -# include +# include #endif -#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC - /* Specification. */ #include -#include -#include -#include -#include -#if HAVE_SYS_PARAM_H || defined _LIBC -# include -#endif -#include #include +#include +#include #include +#include +#include +#include + +#include #ifdef _LIBC +# include # include +typedef ptrdiff_t idx_t; +# define IDX_MAX PTRDIFF_MAX +# define FILE_SYSTEM_PREFIX_LEN(name) 0 +# define IS_ABSOLUTE_FILE_NAME(name) ISSLASH(*(name)) +# define ISSLASH(c) ((c) == '/') +# define freea(p) ((void) (p)) #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 "idx.h" # include "pathmax.h" -# include "malloca.h" # include "filename.h" # if defined _WIN32 && !defined __CYGWIN__ # define __getcwd _getcwd @@ -72,8 +73,10 @@ # else # define __getcwd(buf, max) getwd (buf) # endif +# define __mempcpy mempcpy +# define __pathconf pathconf +# define __rawmemchr rawmemchr # define __readlink readlink -# define __set_errno(e) errno = (e) # ifndef MAXSYMLINKS # ifdef SYMLOOP_MAX # define MAXSYMLINKS SYMLOOP_MAX @@ -81,48 +84,51 @@ # define MAXSYMLINKS 20 # endif # endif +# define __eloop_threshold() MAXSYMLINKS #endif #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 #endif -/* Define this independently so that stdint.h is not a prerequisite. */ -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - #if !FUNC_REALPATH_WORKS || defined _LIBC -static void -alloc_failed (void) +static idx_t +get_path_max (void) { -#if defined _WIN32 && ! defined __CYGWIN__ - /* Avoid errno problem without using the malloc or realloc modules; see: - https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */ - errno = ENOMEM; -#endif +# ifdef PATH_MAX + long int path_max = PATH_MAX; +# else + /* The caller invoked realpath with a null RESOLVED, even though + PATH_MAX is not defined as a constant. The glibc manual says + programs should not do this, and POSIX says the behavior is undefined. + Historically, glibc here used the result of pathconf, or 1024 if that + failed; stay consistent with this (dubious) historical practice. */ + int err = errno; + long int path_max = __pathconf ("/", _PC_PATH_MAX); + __set_errno (err); +# endif + return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX; } /* 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 + does not contain any ".", ".." components nor any repeated file name + separators ('/') or symlinks. All file name 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 + RESOLVED is non-NULL, it contains the name of the first component + that cannot be resolved. If the name 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; + char *dest; + char const *start; + char const *end; int num_links = 0; - size_t prefix_len; if (name == NULL) { @@ -142,205 +148,151 @@ __realpath (const char *name, char *resolved) 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) - { - alloc_failed (); - return NULL; - } - } - else - rpath = resolved; - rpath_limit = rpath + path_max; + struct scratch_buffer extra_buffer, link_buffer; + struct scratch_buffer rname_buffer; + struct scratch_buffer *rname_buf = &rname_buffer; + scratch_buffer_init (&extra_buffer); + scratch_buffer_init (&link_buffer); + scratch_buffer_init (rname_buf); + char *rname_on_stack = rname_buf->data; + char *rname = rname_on_stack; + bool end_in_extra_buffer = false; + bool failed = true; /* 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); + idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); if (!IS_ABSOLUTE_FILE_NAME (name)) { - if (!__getcwd (rpath, path_max)) + while (!__getcwd (rname, rname_buf->length)) { - rpath[0] = '\0'; - goto error; + if (errno != ERANGE) + { + dest = rname; + goto error; + } + if (!scratch_buffer_grow (rname_buf)) + goto error_nomem; + rname = rname_buf->data; } - dest = strchr (rpath, '\0'); + dest = __rawmemchr (rname, '\0'); start = name; - prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath); + prefix_len = FILE_SYSTEM_PREFIX_LEN (rname); } else { - dest = rpath; - if (prefix_len) - { - memcpy (rpath, name, prefix_len); - dest += prefix_len; - } + dest = __mempcpy (rname, name, prefix_len); *dest++ = '/'; if (DOUBLE_SLASH_IS_DISTINCT_ROOT) { - if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len) + if (prefix_len == 0 /* implies ISSLASH (name[0]) */ + && ISSLASH (name[1]) && !ISSLASH (name[2])) *dest++ = '/'; *dest = '\0'; } start = name + prefix_len; } - for (end = start; *start; start = end) + for ( ; *start; start = end) { -#ifdef _LIBC - struct stat64 st; -#else - struct stat st; -#endif - - /* Skip sequence of multiple path-separators. */ + /* Skip sequence of multiple file name separators. */ while (ISSLASH (*start)) ++start; - /* Find end of path component. */ + /* Find end of component. */ for (end = start; *end && !ISSLASH (*end); ++end) /* Nothing. */; - if (end - start == 0) - break; - else if (end - start == 1 && start[0] == '.') + /* Length of this file name component; it can be zero if a file + name ends in '/'. */ + idx_t startlen = end - start; + + if (startlen == 1 && start[0] == '.') /* nothing */; - else if (end - start == 2 && start[0] == '.' && start[1] == '.') + else if (startlen == 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) + if (dest > rname + prefix_len + 1) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) continue; if (DOUBLE_SLASH_IS_DISTINCT_ROOT - && dest == rpath + 1 && !prefix_len + && dest == rname + 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) + while (rname + rname_buf->length - dest <= startlen) { - 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) - { - alloc_failed (); - goto error; - } - rpath = new_rpath; - rpath_limit = rpath + new_size; - - dest = rpath + dest_offset; + idx_t dest_offset = dest - rname; + if (!scratch_buffer_grow_preserve (rname_buf)) + goto error_nomem; + rname = rname_buf->data; + dest = rname + dest_offset; } -#ifdef _LIBC - dest = __mempcpy (dest, start, end - start); -#else - memcpy (dest, start, end - start); - dest += end - start; -#endif + dest = __mempcpy (dest, start, startlen); *dest = '\0'; - /* FIXME: if lstat fails with errno == EOVERFLOW, - the entry exists. */ -#ifdef _LIBC - if (__lxstat64 (_STAT_VER, rpath, &st) < 0) -#else - if (lstat (rpath, &st) < 0) -#endif - goto error; - - if (S_ISLNK (st.st_mode)) + /* If STARTLEN == 0, RNAME ends in '/'; use stat rather than + readlink, because readlink might fail with EINVAL without + checking whether RNAME sans '/' is valid. */ + struct stat st; + char *buf = NULL; + ssize_t n; + if (startlen != 0) { - char *buf; - size_t len; - ssize_t n; - - if (++num_links > MAXSYMLINKS) - { - __set_errno (ELOOP); - goto error; - } - - buf = malloca (path_max); - if (!buf) + while (true) { - __set_errno (ENOMEM); - goto error; + buf = link_buffer.data; + idx_t bufsize = link_buffer.length; + n = __readlink (rname, buf, bufsize - 1); + if (n < bufsize - 1) + break; + if (!scratch_buffer_grow (&link_buffer)) + goto error_nomem; } - - n = __readlink (rpath, buf, path_max - 1); if (n < 0) + buf = NULL; + } + if (buf) + { + if (++num_links > __eloop_threshold ()) { - int saved_errno = errno; - freea (buf); - __set_errno (saved_errno); + __set_errno (ELOOP); goto error; } - buf[n] = '\0'; - if (!extra_buf) - { - extra_buf = malloca (path_max); - if (!extra_buf) - { - freea (buf); - __set_errno (ENOMEM); - goto error; - } - } + buf[n] = '\0'; - len = strlen (end); - /* Check that n + len + 1 doesn't overflow and is <= path_max. */ - if (n >= SIZE_MAX - len || n + len >= path_max) + char *extra_buf = extra_buffer.data; + idx_t end_idx; + if (end_in_extra_buffer) + end_idx = end - extra_buf; + idx_t len = strlen (end); + while (extra_buffer.length <= len + n) { - freea (buf); - __set_errno (ENAMETOOLONG); - goto error; + if (!scratch_buffer_grow_preserve (&extra_buffer)) + goto error_nomem; + extra_buf = extra_buffer.data; } + if (end_in_extra_buffer) + end = extra_buf + end_idx; /* Careful here, end may be a pointer into extra_buf... */ memmove (&extra_buf[n], end, len + 1); name = end = memcpy (extra_buf, buf, n); + end_in_extra_buffer = true; if (IS_ABSOLUTE_FILE_NAME (buf)) { - size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf); + idx_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf); - if (pfxlen) - memcpy (rpath, buf, pfxlen); - dest = rpath + pfxlen; + dest = __mempcpy (rname, buf, pfxlen); *dest++ = '/'; /* It's an absolute symlink */ if (DOUBLE_SLASH_IS_DISTINCT_ROOT) { @@ -355,44 +307,55 @@ __realpath (const char *name, char *resolved) { /* Back up to previous component, ignore if at root already: */ - if (dest > rpath + prefix_len + 1) - for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest) + if (dest > rname + prefix_len + 1) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) continue; - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len) dest++; } } - else if (!S_ISDIR (st.st_mode) && *end != '\0') - { - __set_errno (ENOTDIR); - goto error; - } + else if (! (startlen == 0 + ? stat (rname, &st) == 0 || errno == EOVERFLOW + : errno == EINVAL)) + goto error; } } - if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1])) + if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1])) --dest; - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len && ISSLASH (*dest) && !ISSLASH (dest[1])) dest++; - *dest = '\0'; - - if (extra_buf) - freea (extra_buf); - - return rpath; + failed = false; error: - { - int saved_errno = errno; - if (extra_buf) - freea (extra_buf); - if (resolved == NULL) - free (rpath); - __set_errno (saved_errno); - } - return NULL; + *dest++ = '\0'; + if (resolved != NULL && dest - rname <= get_path_max ()) + rname = strcpy (resolved, rname); + +error_nomem: + scratch_buffer_free (&extra_buffer); + scratch_buffer_free (&link_buffer); + if (failed || rname == resolved) + scratch_buffer_free (rname_buf); + + if (failed) + return NULL; + + if (rname == resolved) + return rname; + idx_t rname_size = dest - rname; + if (rname == rname_on_stack) + { + rname = malloc (rname_size); + if (rname == NULL) + return NULL; + return memcpy (rname, rname_on_stack, rname_size); + } + char *result = realloc (rname, rname_size); + return result != NULL ? result : rname; } +libc_hidden_def (__realpath) versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); #endif /* !FUNC_REALPATH_WORKS || defined _LIBC */ @@ -420,11 +383,3 @@ __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/lib/careadlinkat.c b/lib/careadlinkat.c index e43aa42d5c4..26fe84df55e 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c @@ -51,8 +51,13 @@ enum { STACK_BUF_SIZE = 1024 }; to pacify GCC is known; even an explicit #pragma does not pacify GCC. When the GCC bug is fixed this workaround should be limited to the broken GCC versions. */ -#if (defined GCC_LINT || defined lint) && _GL_GNUC_PREREQ (10, 1) +#if _GL_GNUC_PREREQ (10, 1) +# if defined GCC_LINT || defined lint __attribute__ ((__noinline__)) +# elif __OPTIMIZE__ && !__NO_INLINE__ +# warning "GCC might issue a bogus -Wreturn-local-addr warning here." +# warning "See ." +# endif #endif static char * readlink_stk (int fd, char const *filename, @@ -85,18 +90,13 @@ readlink_stk (int fd, char const *filename, size_t link_size; if (link_length < 0) { - /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1 - with errno == ERANGE if the buffer is too small. */ - int readlinkat_errno = errno; - if (readlinkat_errno != ERANGE) + if (buf != buffer) { - if (buf != buffer) - { - alloc->free (buf); - errno = readlinkat_errno; - } - return NULL; + int readlinkat_errno = errno; + alloc->free (buf); + errno = readlinkat_errno; } + return NULL; } link_size = link_length; diff --git a/lib/cdefs.h b/lib/cdefs.h index ff7c628a264..1a2805d7259 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h @@ -75,11 +75,11 @@ /* GCC can always grok prototypes. For C++ programs we add throw() to help it optimize the function calls. But this works only with - gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions + gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions as non-throwing using a function attribute since programs can use the -fexceptions options for C code as well. */ # if !defined __cplusplus \ - && (__GNUC_PREREQ (3, 3) || __glibc_clang_has_attribute (__nothrow__)) + && (__GNUC_PREREQ (3, 4) || __glibc_clang_has_attribute (__nothrow__)) # define __THROW __attribute__ ((__nothrow__ __LEAF)) # define __THROWNL __attribute__ ((__nothrow__)) # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct diff --git a/lib/fcntl.c b/lib/fcntl.c index 8cd1531527d..59bb3ca91ea 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -491,7 +491,9 @@ rpl_fcntl_DUPFD_CLOEXEC (int fd, int target) #if !HAVE_FCNTL result = dupfd (fd, target, O_CLOEXEC); #else /* HAVE_FCNTL */ -# if defined __HAIKU__ +# if defined __NetBSD__ || defined __HAIKU__ + /* On NetBSD 9.0, the system fcntl (fd, F_DUPFD_CLOEXEC, target) + has only the same effect as fcntl (fd, F_DUPFD, target). */ /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets the FD_CLOEXEC flag on fd, not on target. Therefore avoid the system fcntl in this case. */ diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index 6f16bc66921..11c9aae9bcc 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -112,9 +112,21 @@ _GL_CXXALIASWARN (creat); /* Assume creat is always declared. */ _GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - " "use gnulib module creat for portability"); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef creat -# define creat _creat +#else +/* On native Windows, map 'creat' to '_creat', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::creat always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef creat +# define creat _creat +# endif +/* Need to cast, because in mingw the last argument is 'int mode'. */ +_GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode)); +# else +_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode)); +# endif +_GL_CXXALIASWARN (creat); #endif #if @GNULIB_FCNTL@ @@ -174,9 +186,22 @@ _GL_CXXALIASWARN (open); /* Assume open is always declared. */ _GL_WARN_ON_USE (open, "open is not always POSIX compliant - " "use gnulib module open for portability"); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef open -# define open _open +#else +/* On native Windows, map 'open' to '_open', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::open always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef open +# define open _open +# endif +_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...)); +# else +_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); +# endif +# if !defined __hpux +_GL_CXXALIASWARN (open); +# endif #endif #if @GNULIB_OPENAT@ diff --git a/lib/filemode.c b/lib/filemode.c index e1b069093f8..15e3551368b 100644 --- a/lib/filemode.c +++ b/lib/filemode.c @@ -20,17 +20,6 @@ #include "filemode.h" -/* The following is for Cray DMF (Data Migration Facility), which is a - HSM file system. A migrated file has a 'st_dm_mode' that is - different from the normal 'st_mode', so any tests for migrated - files should use the former. */ -#if HAVE_ST_DM_MODE -# define IS_MIGRATED_FILE(statp) \ - (S_ISOFD (statp->st_dm_mode) || S_ISOFL (statp->st_dm_mode)) -#else -# define IS_MIGRATED_FILE(statp) 0 -#endif - #if ! HAVE_DECL_STRMODE /* Return a character indicating the type of file described by @@ -126,7 +115,6 @@ strmode (mode_t mode, char *str) for files whose type cannot be determined solely from st_mode: 'F' semaphore - 'M' migrated file (Cray DMF) 'Q' message queue 'S' shared memory object 'T' typed memory object @@ -169,8 +157,6 @@ filemodestring (struct stat const *statp, char *str) if (S_TYPEISSEM (statp)) str[0] = 'F'; - else if (IS_MIGRATED_FILE (statp)) - str[0] = 'M'; else if (S_TYPEISMQ (statp)) str[0] = 'Q'; else if (S_TYPEISSHM (statp)) diff --git a/lib/fpending.c b/lib/fpending.c index 802ebcba654..836a3a988bf 100644 --- a/lib/fpending.c +++ b/lib/fpending.c @@ -25,7 +25,8 @@ #include "stdio-impl.h" /* This file is not used on systems that already have the __fpending function, - namely glibc >= 2.2, Solaris >= 7, Android API >= 23. */ + namely glibc >= 2.2, Solaris >= 7, UnixWare >= 7.1.4.MP4, Cygwin >= 1.7.34, + Android API >= 23. */ /* Return the number of pending (aka buffered, unflushed) bytes on the stream, FP, that is open for writing. */ @@ -39,13 +40,13 @@ __fpending (FILE *fp) /* GNU libc, BeOS, Haiku, Linux libc5 */ return fp->_IO_write_ptr - fp->_IO_write_base; #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__ - /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */ + /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin < 1.7.34, Minix 3, Android */ return fp->_p - fp->_bf._base; #elif defined __EMX__ /* emx+gcc */ return fp->_ptr - fp->_buffer; #elif defined __minix /* Minix */ return fp_->_ptr - fp_->_buf; -#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS */ +#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, UnixWare, mingw, MSVC, NonStop Kernel, OpenVMS */ return (fp_->_ptr ? fp_->_ptr - fp_->_base : 0); #elif defined __UCLIBC__ /* uClibc */ return (fp->__modeflags & __FLAG_WRITING ? fp->__bufpos - fp->__bufstart : 0); diff --git a/lib/free.c b/lib/free.c new file mode 100644 index 00000000000..2f689a7ea32 --- /dev/null +++ b/lib/free.c @@ -0,0 +1,33 @@ +/* Make free() preserve errno. + + Copyright (C) 2003, 2006, 2009-2020 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 . */ + +/* written by Paul Eggert */ + +#include + +#include + +#include + +void +rpl_free (void *p) +#undef free +{ + int err = errno; + free (p); + errno = err; +} diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 9953198fb31..df533fa6740 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -257,6 +257,7 @@ GL_GENERATE_STDINT_H = @GL_GENERATE_STDINT_H@ GMALLOC_OBJ = @GMALLOC_OBJ@ GMP_H = @GMP_H@ GNULIB_ACCESS = @GNULIB_ACCESS@ +GNULIB_ALIGNED_ALLOC = @GNULIB_ALIGNED_ALLOC@ GNULIB_ALPHASORT = @GNULIB_ALPHASORT@ GNULIB_ATOLL = @GNULIB_ATOLL@ GNULIB_CALLOC_POSIX = @GNULIB_CALLOC_POSIX@ @@ -297,6 +298,7 @@ GNULIB_FPURGE = @GNULIB_FPURGE@ GNULIB_FPUTC = @GNULIB_FPUTC@ GNULIB_FPUTS = @GNULIB_FPUTS@ GNULIB_FREAD = @GNULIB_FREAD@ +GNULIB_FREE_POSIX = @GNULIB_FREE_POSIX@ GNULIB_FREOPEN = @GNULIB_FREOPEN@ GNULIB_FSCANF = @GNULIB_FSCANF@ GNULIB_FSEEK = @GNULIB_FSEEK@ @@ -388,6 +390,7 @@ GNULIB_PERROR = @GNULIB_PERROR@ GNULIB_PIPE = @GNULIB_PIPE@ GNULIB_PIPE2 = @GNULIB_PIPE2@ GNULIB_POPEN = @GNULIB_POPEN@ +GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@ GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@ GNULIB_PREAD = @GNULIB_PREAD@ GNULIB_PRINTF = @GNULIB_PRINTF@ @@ -506,6 +509,7 @@ GTK_OBJ = @GTK_OBJ@ GZIP_PROG = @GZIP_PROG@ HARFBUZZ_CFLAGS = @HARFBUZZ_CFLAGS@ HARFBUZZ_LIBS = @HARFBUZZ_LIBS@ +HAVE_ALIGNED_ALLOC = @HAVE_ALIGNED_ALLOC@ HAVE_ALLOCA_H = @HAVE_ALLOCA_H@ HAVE_ALPHASORT = @HAVE_ALPHASORT@ HAVE_ATOLL = @HAVE_ATOLL@ @@ -515,13 +519,18 @@ HAVE_CHOWN = @HAVE_CHOWN@ HAVE_CLOSEDIR = @HAVE_CLOSEDIR@ HAVE_COPY_FILE_RANGE = @HAVE_COPY_FILE_RANGE@ HAVE_DECL_DIRFD = @HAVE_DECL_DIRFD@ +HAVE_DECL_ECVT = @HAVE_DECL_ECVT@ HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@ +HAVE_DECL_EXECVPE = @HAVE_DECL_EXECVPE@ HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@ +HAVE_DECL_FCLOSEALL = @HAVE_DECL_FCLOSEALL@ +HAVE_DECL_FCVT = @HAVE_DECL_FCVT@ HAVE_DECL_FDATASYNC = @HAVE_DECL_FDATASYNC@ HAVE_DECL_FDOPENDIR = @HAVE_DECL_FDOPENDIR@ HAVE_DECL_FPURGE = @HAVE_DECL_FPURGE@ HAVE_DECL_FSEEKO = @HAVE_DECL_FSEEKO@ HAVE_DECL_FTELLO = @HAVE_DECL_FTELLO@ +HAVE_DECL_GCVT = @HAVE_DECL_GCVT@ HAVE_DECL_GETDELIM = @HAVE_DECL_GETDELIM@ HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@ HAVE_DECL_GETLINE = @HAVE_DECL_GETLINE@ @@ -621,6 +630,7 @@ HAVE_PDUMPER = @HAVE_PDUMPER@ HAVE_PIPE = @HAVE_PIPE@ HAVE_PIPE2 = @HAVE_PIPE2@ HAVE_POPEN = @HAVE_POPEN@ +HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ HAVE_PREAD = @HAVE_PREAD@ @@ -863,6 +873,7 @@ PTRDIFF_T_SUFFIX = @PTRDIFF_T_SUFFIX@ RALLOC_OBJ = @RALLOC_OBJ@ RANLIB = @RANLIB@ REPLACE_ACCESS = @REPLACE_ACCESS@ +REPLACE_ALIGNED_ALLOC = @REPLACE_ALIGNED_ALLOC@ REPLACE_CALLOC = @REPLACE_CALLOC@ REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@ REPLACE_CHOWN = @REPLACE_CHOWN@ @@ -885,6 +896,7 @@ REPLACE_FFLUSH = @REPLACE_FFLUSH@ REPLACE_FOPEN = @REPLACE_FOPEN@ REPLACE_FPRINTF = @REPLACE_FPRINTF@ REPLACE_FPURGE = @REPLACE_FPURGE@ +REPLACE_FREE = @REPLACE_FREE@ REPLACE_FREOPEN = @REPLACE_FREOPEN@ REPLACE_FSEEK = @REPLACE_FSEEK@ REPLACE_FSEEKO = @REPLACE_FSEEKO@ @@ -932,6 +944,7 @@ REPLACE_OPENAT = @REPLACE_OPENAT@ REPLACE_OPENDIR = @REPLACE_OPENDIR@ REPLACE_PERROR = @REPLACE_PERROR@ REPLACE_POPEN = @REPLACE_POPEN@ +REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PRINTF = @REPLACE_PRINTF@ REPLACE_PSELECT = @REPLACE_PSELECT@ @@ -1101,12 +1114,15 @@ gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850 gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@ gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@ gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@ +gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@ gl_GNULIB_ENABLED_euidaccess = @gl_GNULIB_ENABLED_euidaccess@ gl_GNULIB_ENABLED_getdtablesize = @gl_GNULIB_ENABLED_getdtablesize@ gl_GNULIB_ENABLED_getgroups = @gl_GNULIB_ENABLED_getgroups@ +gl_GNULIB_ENABLED_idx = @gl_GNULIB_ENABLED_idx@ gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@ -gl_GNULIB_ENABLED_malloca = @gl_GNULIB_ENABLED_malloca@ gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@ +gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@ +gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@ gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@ gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@ gl_LIBOBJS = @gl_LIBOBJS@ @@ -1731,6 +1747,19 @@ EXTRA_libgnu_a_SOURCES += fpending.c endif ## end gnulib module fpending +## begin gnulib module free-posix +ifeq (,$(OMIT_GNULIB_MODULE_free-posix)) + +ifneq (,$(gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955)) + +endif +EXTRA_DIST += free.c + +EXTRA_libgnu_a_SOURCES += free.c + +endif +## end gnulib module free-posix + ## begin gnulib module fstatat ifeq (,$(OMIT_GNULIB_MODULE_fstatat)) @@ -1912,6 +1941,16 @@ EXTRA_libgnu_a_SOURCES += group-member.c endif ## end gnulib module group-member +## begin gnulib module idx +ifeq (,$(OMIT_GNULIB_MODULE_idx)) + +ifneq (,$(gl_GNULIB_ENABLED_idx)) +libgnu_a_SOURCES += idx.h + +endif +endif +## end gnulib module idx + ## begin gnulib module ieee754-h ifeq (,$(OMIT_GNULIB_MODULE_ieee754-h)) @@ -2094,18 +2133,6 @@ EXTRA_libgnu_a_SOURCES += lstat.c endif ## end gnulib module lstat -## begin gnulib module malloca -ifeq (,$(OMIT_GNULIB_MODULE_malloca)) - -ifneq (,$(gl_GNULIB_ENABLED_malloca)) -libgnu_a_SOURCES += malloca.c - -endif -EXTRA_DIST += malloca.h - -endif -## end gnulib module malloca - ## begin gnulib module memmem-simple ifeq (,$(OMIT_GNULIB_MODULE_memmem-simple)) @@ -2263,6 +2290,19 @@ libgnu_a_SOURCES += qcopy-acl.c endif ## end gnulib module qcopy-acl +## begin gnulib module rawmemchr +ifeq (,$(OMIT_GNULIB_MODULE_rawmemchr)) + +ifneq (,$(gl_GNULIB_ENABLED_rawmemchr)) + +endif +EXTRA_DIST += rawmemchr.c rawmemchr.valgrind + +EXTRA_libgnu_a_SOURCES += rawmemchr.c + +endif +## end gnulib module rawmemchr + ## begin gnulib module readlink ifeq (,$(OMIT_GNULIB_MODULE_readlink)) @@ -2307,6 +2347,18 @@ EXTRA_DIST += root-uid.h endif ## end gnulib module root-uid +## begin gnulib module scratch_buffer +ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer)) + +ifneq (,$(gl_GNULIB_ENABLED_scratch_buffer)) +libgnu_a_SOURCES += malloc/scratch_buffer_grow.c malloc/scratch_buffer_grow_preserve.c malloc/scratch_buffer_set_array_size.c + +endif +EXTRA_DIST += malloc/scratch_buffer.h scratch_buffer.h + +endif +## end gnulib module scratch_buffer + ## begin gnulib module sig2str ifeq (,$(OMIT_GNULIB_MODULE_sig2str)) @@ -2618,7 +2670,8 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ < $(srcdir)/stdio.in.h | \ - sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ + sed -e 's|@''HAVE_DECL_FCLOSEALL''@|$(HAVE_DECL_FCLOSEALL)|g' \ + -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \ -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \ -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ @@ -2696,9 +2749,11 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \ + -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GNULIB_ALIGNED_ALLOC)/g' \ -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \ -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \ -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \ + -e 's/@''GNULIB_FREE_POSIX''@/$(GNULIB_FREE_POSIX)/g' \ -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ @@ -2709,6 +2764,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \ -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \ -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ + -e 's/@''GNULIB_POSIX_MEMALIGN''@/$(GNULIB_POSIX_MEMALIGN)/g' \ -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ @@ -2732,8 +2788,12 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \ < $(srcdir)/stdlib.in.h | \ sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ + -e 's|@''HAVE_ALIGNED_ALLOC''@|$(HAVE_ALIGNED_ALLOC)|g' \ -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''HAVE_DECL_ECVT''@|$(HAVE_DECL_ECVT)|g' \ + -e 's|@''HAVE_DECL_FCVT''@|$(HAVE_DECL_FCVT)|g' \ + -e 's|@''HAVE_DECL_GCVT''@|$(HAVE_DECL_GCVT)|g' \ -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ @@ -2745,6 +2805,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ + -e 's|@''HAVE_POSIX_MEMALIGN''@|$(HAVE_POSIX_MEMALIGN)|g' \ -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ @@ -2767,12 +2828,15 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \ + -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \ -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \ -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \ -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ + -e 's|@''REPLACE_POSIX_MEMALIGN''@|$(REPLACE_POSIX_MEMALIGN)|g' \ -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \ -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ @@ -3412,6 +3476,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ + -e 's|@''HAVE_DECL_EXECVPE''@|$(HAVE_DECL_EXECVPE)|g' \ -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \ -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \ -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \ diff --git a/lib/idx.h b/lib/idx.h new file mode 100644 index 00000000000..6a7739fa9c7 --- /dev/null +++ b/lib/idx.h @@ -0,0 +1,113 @@ +/* A type for indices and sizes. + + Copyright (C) 2020 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 . */ + +#ifndef _IDX_H +#define _IDX_H + +/* Get ptrdiff_t. */ +#include + +/* Get PTRDIFF_MAX. */ +#include + +/* The type 'idx_t' holds an (array) index or an (object) size. + Its implementation promotes to a signed integer type, + which can hold the values + 0..2^63-1 (on 64-bit platforms) or + 0..2^31-1 (on 32-bit platforms). + + Why a signed integer type? + + * Security: Signed types can be checked for overflow via + '-fsanitize=undefined', but unsigned types cannot. + + * Comparisons without surprises: ISO C99 § 6.3.1.8 specifies a few + surprising results for comparisons, such as + + (int) -3 < (unsigned long) 7 => false + (int) -3 < (unsigned int) 7 => false + and on 32-bit machines: + (long) -3 < (unsigned int) 7 => false + + This is surprising because the natural comparison order is by + value in the realm of infinite-precision signed integers (ℤ). + + The best way to get rid of such surprises is to use signed types + for numerical integer values, and use unsigned types only for + bit masks and enums. + + Why not use 'size_t' directly? + + * Because 'size_t' is an unsigned type, and a signed type is better. + See above. + + Why not use 'ptrdiff_t' directly? + + * Maintainability: When reading and modifying code, it helps to know that + a certain variable cannot have negative values. For example, when you + have a loop + + int n = ...; + for (int i = 0; i < n; i++) ... + + or + + ptrdiff_t n = ...; + for (ptrdiff_t i = 0; i < n; i++) ... + + you have to ask yourself "what if n < 0?". Whereas in + + idx_t n = ...; + for (idx_t i = 0; i < n; i++) ... + + you know that this case cannot happen. + + Similarly, when a programmer writes + + idx_t = ptr2 - ptr1; + + there is an implied assertion that ptr1 and ptr2 point into the same + object and that ptr1 <= ptr2. + + * Being future-proof: In the future, range types (integers which are + constrained to a certain range of values) may be added to C compilers + or to the C standard. Several programming languages (Ada, Haskell, + Common Lisp, Pascal) already have range types. Such range types may + help producing good code and good warnings. The type 'idx_t' could + then be typedef'ed to a range type that is signed after promotion. */ + +/* In the future, idx_t could be typedef'ed to a signed range type. + The clang "extended integer types", supported in Clang 11 or newer + , + are a special case of range types. However, these types don't support binary + operators with plain integer types (e.g. expressions such as x > 1). + Therefore, they don't behave like signed types (and not like unsigned types + either). So, we cannot use them here. */ + +/* Use the signed type 'ptrdiff_t'. */ +/* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same + size, but it is so on all platforms we have seen since 1990. */ +typedef ptrdiff_t idx_t; + +/* IDX_MAX is the maximum value of an idx_t. */ +#define IDX_MAX PTRDIFF_MAX + +/* So far no need has been found for an IDX_WIDTH macro. + Perhaps there should be another macro IDX_VALUE_BITS that does not + count the sign bit and is therefore one less than PTRDIFF_WIDTH. */ + +#endif /* _IDX_H */ diff --git a/lib/intprops.h b/lib/intprops.h index b27f2eea056..bc2107c9295 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -226,7 +226,9 @@ /* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow (A, B, P) work when P is non-null. */ -#if 5 <= __GNUC__ && !defined __ICC +/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x, + see . */ +#if 7 <= __GNUC__ && !defined __ICC # define _GL_HAS_BUILTIN_ADD_OVERFLOW 1 #elif defined __has_builtin # define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow) @@ -244,7 +246,17 @@ /* True if __builtin_add_overflow_p (A, B, C) works, and similarly for __builtin_sub_overflow_p and __builtin_mul_overflow_p. */ -#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) +#if defined __clang__ || defined __ICC +/* Clang 11 lacks __builtin_mul_overflow_p, and even if it did it + would presumably run afoul of Clang bug 16404. ICC 2021.1's + __builtin_add_overflow_p etc. are not treated as integral constant + expressions even when all arguments are. */ +# define _GL_HAS_BUILTIN_OVERFLOW_P 0 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p) +#else +# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) +#endif /* The _GL*_OVERFLOW macros have the same restrictions as the *_RANGE_OVERFLOW macros, except that they do not assume that operands @@ -377,8 +389,9 @@ _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW) #endif #if _GL_HAS_BUILTIN_MUL_OVERFLOW -# if (9 < __GNUC__ + (3 <= __GNUC_MINOR__) \ - || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) +# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \ + || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \ + && !defined __ICC) # define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r) # else /* Work around GCC bug 91450. */ @@ -585,4 +598,33 @@ : (tmin) / (a) < (b)) \ : (tmax) / (b) < (a))) +/* The following macros compute A + B, A - B, and A * B, respectively. + If no overflow occurs, they set *R to the result and return 1; + otherwise, they return 0 and may modify *R. + + Example usage: + + long int result; + if (INT_ADD_OK (a, b, &result)) + printf ("result is %ld\n", result); + else + printf ("overflow\n"); + + A, B, and *R should be integers; they need not be the same type, + and they need not be all signed or all unsigned. + + These macros work correctly on all known practical hosts, and do not rely + on undefined behavior due to signed arithmetic overflow. + + These macros are not constant expressions. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + These macros are tuned for B being a constant. */ + +#define INT_ADD_OK(a, b, r) ! INT_ADD_WRAPV (a, b, r) +#define INT_SUBTRACT_OK(a, b, r) ! INT_SUBTRACT_WRAPV (a, b, r) +#define INT_MULTIPLY_OK(a, b, r) ! INT_MULTIPLY_WRAPV (a, b, r) + #endif /* _GL_INTPROPS_H */ diff --git a/lib/malloc/scratch_buffer.h b/lib/malloc/scratch_buffer.h new file mode 100644 index 00000000000..b40478637c8 --- /dev/null +++ b/lib/malloc/scratch_buffer.h @@ -0,0 +1,135 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2015-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + . */ + +#ifndef _SCRATCH_BUFFER_H +#define _SCRATCH_BUFFER_H + +/* Scratch buffers with a default stack allocation and fallback to + heap allocation. It is expected that this function is used in this + way: + + struct scratch_buffer tmpbuf; + scratch_buffer_init (&tmpbuf); + + while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length)) + if (!scratch_buffer_grow (&tmpbuf)) + return -1; + + scratch_buffer_free (&tmpbuf); + return 0; + + The allocation functions (scratch_buffer_grow, + scratch_buffer_grow_preserve, scratch_buffer_set_array_size) make + sure that the heap allocation, if any, is freed, so that the code + above does not have a memory leak. The buffer still remains in a + state that can be deallocated using scratch_buffer_free, so a loop + like this is valid as well: + + struct scratch_buffer tmpbuf; + scratch_buffer_init (&tmpbuf); + + while (!function_that_uses_buffer (tmpbuf.data, tmpbuf.length)) + if (!scratch_buffer_grow (&tmpbuf)) + break; + + scratch_buffer_free (&tmpbuf); + + scratch_buffer_grow and scratch_buffer_grow_preserve are guaranteed + to grow the buffer by at least 512 bytes. This means that when + using the scratch buffer as a backing store for a non-character + array whose element size, in bytes, is 512 or smaller, the scratch + buffer only has to grow once to make room for at least one more + element. +*/ + +#include +#include +#include + +/* Scratch buffer. Must be initialized with scratch_buffer_init + before its use. */ +struct scratch_buffer { + void *data; /* Pointer to the beginning of the scratch area. */ + size_t length; /* Allocated space at the data pointer, in bytes. */ + union { max_align_t __align; char __c[1024]; } __space; +}; + +/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space + and BUFFER->length reflects the available space. */ +static inline void +scratch_buffer_init (struct scratch_buffer *buffer) +{ + buffer->data = buffer->__space.__c; + buffer->length = sizeof (buffer->__space); +} + +/* Deallocates *BUFFER (if it was heap-allocated). */ +static inline void +scratch_buffer_free (struct scratch_buffer *buffer) +{ + if (buffer->data != buffer->__space.__c) + free (buffer->data); +} + +/* Grow *BUFFER by some arbitrary amount. The buffer contents is NOT + preserved. Return true on success, false on allocation failure (in + which case the old buffer is freed). On success, the new buffer is + larger than the previous size. On failure, *BUFFER is deallocated, + but remains in a free-able state, and errno is set. */ +bool __libc_scratch_buffer_grow (struct scratch_buffer *buffer); +libc_hidden_proto (__libc_scratch_buffer_grow) + +/* Alias for __libc_scratch_buffer_grow. */ +static __always_inline bool +scratch_buffer_grow (struct scratch_buffer *buffer) +{ + return __glibc_likely (__libc_scratch_buffer_grow (buffer)); +} + +/* Like __libc_scratch_buffer_grow, but preserve the old buffer + contents on success, as a prefix of the new buffer. */ +bool __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer); +libc_hidden_proto (__libc_scratch_buffer_grow_preserve) + +/* Alias for __libc_scratch_buffer_grow_preserve. */ +static __always_inline bool +scratch_buffer_grow_preserve (struct scratch_buffer *buffer) +{ + return __glibc_likely (__libc_scratch_buffer_grow_preserve (buffer)); +} + +/* Grow *BUFFER so that it can store at least NELEM elements of SIZE + bytes. The buffer contents are NOT preserved. Both NELEM and SIZE + can be zero. Return true on success, false on allocation failure + (in which case the old buffer is freed, but *BUFFER remains in a + free-able state, and errno is set). It is unspecified whether this + function can reduce the array size. */ +bool __libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer, + size_t nelem, size_t size); +libc_hidden_proto (__libc_scratch_buffer_set_array_size) + +/* Alias for __libc_scratch_set_array_size. */ +static __always_inline bool +scratch_buffer_set_array_size (struct scratch_buffer *buffer, + size_t nelem, size_t size) +{ + return __glibc_likely (__libc_scratch_buffer_set_array_size + (buffer, nelem, size)); +} + +#endif /* _SCRATCH_BUFFER_H */ diff --git a/lib/malloc/scratch_buffer_grow.c b/lib/malloc/scratch_buffer_grow.c new file mode 100644 index 00000000000..41befe3d65f --- /dev/null +++ b/lib/malloc/scratch_buffer_grow.c @@ -0,0 +1,56 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2015-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + . */ + +#ifndef _LIBC +# include +#endif + +#include +#include + +bool +__libc_scratch_buffer_grow (struct scratch_buffer *buffer) +{ + void *new_ptr; + size_t new_length = buffer->length * 2; + + /* Discard old buffer. */ + scratch_buffer_free (buffer); + + /* Check for overflow. */ + if (__glibc_likely (new_length >= buffer->length)) + new_ptr = malloc (new_length); + else + { + __set_errno (ENOMEM); + new_ptr = NULL; + } + + if (__glibc_unlikely (new_ptr == NULL)) + { + /* Buffer must remain valid to free. */ + scratch_buffer_init (buffer); + return false; + } + + /* Install new heap-based buffer. */ + buffer->data = new_ptr; + buffer->length = new_length; + return true; +} +libc_hidden_def (__libc_scratch_buffer_grow) diff --git a/lib/malloc/scratch_buffer_grow_preserve.c b/lib/malloc/scratch_buffer_grow_preserve.c new file mode 100644 index 00000000000..aef232938d5 --- /dev/null +++ b/lib/malloc/scratch_buffer_grow_preserve.c @@ -0,0 +1,67 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2015-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + . */ + +#ifndef _LIBC +# include +#endif + +#include +#include +#include + +bool +__libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer) +{ + size_t new_length = 2 * buffer->length; + void *new_ptr; + + if (buffer->data == buffer->__space.__c) + { + /* Move buffer to the heap. No overflow is possible because + buffer->length describes a small buffer on the stack. */ + new_ptr = malloc (new_length); + if (new_ptr == NULL) + return false; + memcpy (new_ptr, buffer->__space.__c, buffer->length); + } + else + { + /* Buffer was already on the heap. Check for overflow. */ + if (__glibc_likely (new_length >= buffer->length)) + new_ptr = realloc (buffer->data, new_length); + else + { + __set_errno (ENOMEM); + new_ptr = NULL; + } + + if (__glibc_unlikely (new_ptr == NULL)) + { + /* Deallocate, but buffer must remain valid to free. */ + free (buffer->data); + scratch_buffer_init (buffer); + return false; + } + } + + /* Install new heap-based buffer. */ + buffer->data = new_ptr; + buffer->length = new_length; + return true; +} +libc_hidden_def (__libc_scratch_buffer_grow_preserve) diff --git a/lib/malloc/scratch_buffer_set_array_size.c b/lib/malloc/scratch_buffer_set_array_size.c new file mode 100644 index 00000000000..5f5e4c24f5a --- /dev/null +++ b/lib/malloc/scratch_buffer_set_array_size.c @@ -0,0 +1,64 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2015-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + . */ + +#ifndef _LIBC +# include +#endif + +#include +#include +#include + +bool +__libc_scratch_buffer_set_array_size (struct scratch_buffer *buffer, + size_t nelem, size_t size) +{ + size_t new_length = nelem * size; + + /* Avoid overflow check if both values are small. */ + if ((nelem | size) >> (sizeof (size_t) * CHAR_BIT / 2) != 0 + && nelem != 0 && size != new_length / nelem) + { + /* Overflow. Discard the old buffer, but it must remain valid + to free. */ + scratch_buffer_free (buffer); + scratch_buffer_init (buffer); + __set_errno (ENOMEM); + return false; + } + + if (new_length <= buffer->length) + return true; + + /* Discard old buffer. */ + scratch_buffer_free (buffer); + + char *new_ptr = malloc (new_length); + if (new_ptr == NULL) + { + /* Buffer must remain valid to free. */ + scratch_buffer_init (buffer); + return false; + } + + /* Install new heap-based buffer. */ + buffer->data = new_ptr; + buffer->length = new_length; + return true; +} +libc_hidden_def (__libc_scratch_buffer_set_array_size) diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c new file mode 100644 index 00000000000..04bf08415c6 --- /dev/null +++ b/lib/rawmemchr.c @@ -0,0 +1,136 @@ +/* Searching in a string. + Copyright (C) 2008-2020 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 . */ + +#include + +/* Specification. */ +#include + +/* Find the first occurrence of C in S. */ +void * +rawmemchr (const void *s, int c_in) +{ + /* On 32-bit hardware, choosing longword to be a 32-bit unsigned + long instead of a 64-bit uintmax_t tends to give better + performance. On 64-bit hardware, unsigned long is generally 64 + bits already. Change this typedef to experiment with + performance. */ + typedef unsigned long int longword; + + const unsigned char *char_ptr; + const longword *longword_ptr; + longword repeated_one; + longword repeated_c; + unsigned char c; + + c = (unsigned char) c_in; + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + (size_t) char_ptr % sizeof (longword) != 0; + ++char_ptr) + if (*char_ptr == c) + return (void *) char_ptr; + + longword_ptr = (const longword *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + repeated_one = 0x01010101; + repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + } + + /* Instead of the traditional loop which tests each byte, we will + test a longword at a time. The tricky part is testing if *any of + the four* bytes in the longword in question are equal to NUL or + c. We first use an xor with repeated_c. This reduces the task + to testing whether *any of the four* bytes in longword1 is zero. + + We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + The test whether any byte in longword1 is zero is equivalent + to testing whether tmp is nonzero. + + This test can read beyond the end of a string, depending on where + C_IN is encountered. However, this is considered safe since the + initialization phase ensured that the read will be aligned, + therefore, the read will not cross page boundaries and will not + cause a fault. */ + + while (1) + { + longword longword1 = *longword_ptr ^ repeated_c; + + if ((((longword1 - repeated_one) & ~longword1) + & (repeated_one << 7)) != 0) + break; + longword_ptr++; + } + + char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that one of the sizeof (longword) bytes + starting at char_ptr is == c. On little-endian machines, we + could determine the first such byte without any further memory + accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. + Choose code that works in both cases. */ + + char_ptr = (unsigned char *) longword_ptr; + while (*char_ptr != c) + char_ptr++; + return (void *) char_ptr; +} diff --git a/lib/rawmemchr.valgrind b/lib/rawmemchr.valgrind new file mode 100644 index 00000000000..53c5b317d5f --- /dev/null +++ b/lib/rawmemchr.valgrind @@ -0,0 +1,28 @@ +# Suppress a valgrind message about use of uninitialized memory in rawmemchr(). + +# Copyright (C) 2008-2020 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 . + +# This use is OK because it provides only a speedup. +{ + rawmemchr-value4 + Memcheck:Value4 + fun:rawmemchr +} +{ + rawmemchr-value8 + Memcheck:Value8 + fun:rawmemchr +} diff --git a/lib/readlink.c b/lib/readlink.c index 4d392ef6995..531913eba3e 100644 --- a/lib/readlink.c +++ b/lib/readlink.c @@ -1,4 +1,4 @@ -/* Stub for readlink(). +/* Read the contents of a symbolic link. Copyright (C) 2003-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -29,7 +29,7 @@ such as DJGPP 2.03 and mingw32. */ ssize_t -readlink (const char *name, char *buf _GL_UNUSED, +readlink (char const *file, char *buf _GL_UNUSED, size_t bufsize _GL_UNUSED) { struct stat statbuf; @@ -37,7 +37,7 @@ readlink (const char *name, char *buf _GL_UNUSED, /* 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) + if (stat (file, &statbuf) >= 0) errno = EINVAL; return -1; } @@ -51,24 +51,54 @@ readlink (const char *name, char *buf _GL_UNUSED, for Solaris 9. */ ssize_t -rpl_readlink (const char *name, char *buf, size_t bufsize) +rpl_readlink (char const *file, char *buf, size_t bufsize) { # if READLINK_TRAILING_SLASH_BUG - size_t len = strlen (name); - if (len && name[len - 1] == '/') + size_t file_len = strlen (file); + if (file_len && file[file_len - 1] == '/') { - /* Even if name without the slash is a symlink to a directory, + /* Even if FILE 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) + if (stat (file, &st) == 0 || errno == EOVERFLOW) errno = EINVAL; return -1; } # endif /* READLINK_TRAILING_SLASH_BUG */ - return readlink (name, buf, bufsize); + + ssize_t r = readlink (file, buf, bufsize); + +# if READLINK_TRUNCATE_BUG + if (r < 0 && errno == ERANGE) + { + /* Try again with a bigger buffer. This is just for test cases; + real code invariably discards short reads. */ + char stackbuf[4032]; + r = readlink (file, stackbuf, sizeof stackbuf); + if (r < 0) + { + if (errno == ERANGE) + { + /* Clear the buffer, which is good enough for real code. + Thankfully, no test cases try short reads of enormous + symlinks and what would be the point anyway? */ + r = bufsize; + memset (buf, 0, r); + } + } + else + { + if (bufsize < r) + r = bufsize; + memcpy (buf, stackbuf, r); + } + } +# endif + + return r; } #endif /* HAVE_READLINK */ diff --git a/lib/readlinkat.c b/lib/readlinkat.c index 68ec65ebfc5..7a41208ebfd 100644 --- a/lib/readlinkat.c +++ b/lib/readlinkat.c @@ -28,10 +28,11 @@ #if HAVE_READLINKAT +# undef fstatat # undef readlinkat ssize_t -rpl_readlinkat (int fd, char const *file, char *buf, size_t len) +rpl_readlinkat (int fd, char const *file, char *buf, size_t bufsize) { # if READLINK_TRAILING_SLASH_BUG size_t file_len = strlen (file); @@ -40,15 +41,45 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len) /* Even if FILE 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(). */ + safely use fstatat(..., 0) to distinguish between EINVAL and + ENOTDIR/ENOENT, avoiding extra overhead of rpl_fstatat(). */ struct stat st; - if (stat (file, &st) == 0) + if (fstatat (fd, file, &st, 0) == 0 || errno == EOVERFLOW) errno = EINVAL; return -1; } # endif /* READLINK_TRAILING_SLASH_BUG */ - return readlinkat (fd, file, buf, len); + + ssize_t r = readlinkat (fd, file, buf, bufsize); + +# if READLINK_TRUNCATE_BUG + if (r < 0 && errno == ERANGE) + { + /* Try again with a bigger buffer. This is just for test cases; + real code invariably discards short reads. */ + char stackbuf[4032]; + r = readlinkat (fd, file, stackbuf, sizeof stackbuf); + if (r < 0) + { + if (errno == ERANGE) + { + /* Clear the buffer, which is good enough for real code. + Thankfully, no test cases try short reads of enormous + symlinks and what would be the point anyway? */ + r = bufsize; + memset (buf, 0, r); + } + } + else + { + if (bufsize < r) + r = bufsize; + memcpy (buf, stackbuf, r); + } + } +# endif + + return r; } #else @@ -61,7 +92,7 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len) readlinkat worthless since readlink does not guarantee a NUL-terminated buffer. Assume this was a bug in POSIX. */ -/* Read the contents of symlink FILE into buffer BUF of size LEN, in the +/* Read the contents of symlink FILE into buffer BUF of size BUFSIZE, in the directory open on descriptor FD. If possible, do it without changing the working directory. Otherwise, resort to using save_cwd/fchdir, then readlink/restore_cwd. If either the save_cwd or the restore_cwd @@ -69,8 +100,8 @@ rpl_readlinkat (int fd, char const *file, char *buf, size_t len) # define AT_FUNC_NAME readlinkat # define AT_FUNC_F1 readlink -# define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len -# define AT_FUNC_POST_FILE_ARGS , buf, len +# define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t bufsize +# define AT_FUNC_POST_FILE_ARGS , buf, bufsize # define AT_FUNC_RESULT ssize_t # include "at-func.c" # undef AT_FUNC_NAME diff --git a/lib/regex_internal.c b/lib/regex_internal.c index 2e217291468..bf9439e53fd 100644 --- a/lib/regex_internal.c +++ b/lib/regex_internal.c @@ -300,18 +300,20 @@ build_wcs_upper_buffer (re_string_t *pstr) while (byte_idx < end_idx) { wchar_t wc; + unsigned char ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; - if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]) - && mbsinit (&pstr->cur_state)) + if (isascii (ch) && mbsinit (&pstr->cur_state)) { - /* In case of a singlebyte character. */ - pstr->mbs[byte_idx] - = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]); /* The next step uses the assumption that wchar_t is encoded ASCII-safe: all ASCII values can be converted like this. */ - pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; - ++byte_idx; - continue; + wchar_t wcu = __towupper (ch); + if (isascii (wcu)) + { + pstr->mbs[byte_idx] = wcu; + pstr->wcs[byte_idx] = wcu; + byte_idx++; + continue; + } } remain_len = end_idx - byte_idx; @@ -348,7 +350,6 @@ build_wcs_upper_buffer (re_string_t *pstr) { /* It is an invalid character, an incomplete character at the end of the string, or '\0'. Just use the byte. */ - int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; pstr->mbs[byte_idx] = ch; /* And also cast it to wide char. */ pstr->wcs[byte_idx++] = (wchar_t) ch; diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 0c72e3f7b01..7b50b478114 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -77,6 +77,14 @@ # define isblank(ch) ((ch) == ' ' || (ch) == '\t') #endif +/* regex code assumes isascii has its usual numeric meaning, + even if the portable character set uses EBCDIC encoding, + and even if wint_t is wider than int. */ +#ifndef _LIBC +# undef isascii +# define isascii(c) (((c) & ~0x7f) == 0) +#endif + #ifdef _LIBC # ifndef _RE_DEFINE_LOCALE_FUNCTIONS # define _RE_DEFINE_LOCALE_FUNCTIONS 1 diff --git a/lib/scratch_buffer.h b/lib/scratch_buffer.h new file mode 100644 index 00000000000..0b45f92c105 --- /dev/null +++ b/lib/scratch_buffer.h @@ -0,0 +1,29 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2017-2020 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 . */ + +/* Written by Paul Eggert, 2017. */ + +#ifndef _GL_SCRATCH_BUFFER_H +#define _GL_SCRATCH_BUFFER_H + +#include + +#define __libc_scratch_buffer_grow gl_scratch_buffer_grow +#define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve +#define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size +#include + +#endif /* _GL_SCRATCH_BUFFER_H */ diff --git a/lib/signal.in.h b/lib/signal.in.h index c94b053d6af..70a2d4af6ca 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -55,13 +55,13 @@ #ifndef _@GUARD_PREFIX@_SIGNAL_H #define _@GUARD_PREFIX@_SIGNAL_H -/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android - declare pthread_sigmask in , not in . +/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android, + OS/2 kLIBC declare pthread_sigmask in , not in . But avoid namespace pollution on glibc systems.*/ #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ && ((defined __APPLE__ && defined __MACH__) \ || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \ - || defined __sun || defined __ANDROID__) \ + || defined __sun || defined __ANDROID__ || defined __KLIBC__) \ && ! defined __GLIBC__ # include #endif diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 63fa1aa628f..6f2235a750a 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h @@ -579,11 +579,6 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) -> -> -> , and the latter includes and assumes its types are already defined. */ # if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX) - /* BSD/OS 4.0.1 has a bug: , and must be - included before . */ -# include -# include -# include # define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H # include # undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index 067b95ebd64..15066aa59f8 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -175,7 +175,7 @@ # define fp_ fp # endif -# if defined _SCO_DS /* OpenServer */ +# if defined _SCO_DS || (defined __SCO_VERSION__ || defined __sysv5__) /* OpenServer 5, OpenServer 6, UnixWare 7 */ # define _cnt __cnt # define _ptr __ptr # define _base __base diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 6d12cd826de..458036b3441 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -70,30 +70,44 @@ # endif #endif -/* _GL_ATTRIBUTE_FORMAT_PRINTF - indicates to GCC that the function takes a format string and arguments, - where the format string directives are the ones standardized by ISO C99 - and POSIX. */ +/* An __attribute__ __format__ specifier for a function that takes a format + string and arguments, where the format string directives are the ones + standardized by ISO C99 and POSIX. + _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */ +/* __gnu_printf__ is supported in GCC >= 4.4. */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__ #else -# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__ #endif -/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, - except that it indicates to GCC that the supported format string directives - are the ones of the system printf(), rather than the ones standardized by - ISO C99 and POSIX. */ +/* An __attribute__ __format__ specifier for a function that takes a format + string and arguments, where the format string directives are the ones of the + system printf(), rather than the ones standardized by ISO C99 and POSIX. + _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM */ +/* On mingw, Gnulib sets __USE_MINGW_ANSI_STDIO in order to get closer to + the standards. The macro GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU indicates + whether this change is effective. On older mingw, it is not. */ #if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU -# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT_PRINTF (formatstring_parameter, first_argument) +# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD #else -# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM __printf__ #endif +/* _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD + indicates to GCC that the function takes a format string and arguments, + where the format string directives are the ones standardized by ISO C99 + and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, formatstring_parameter, first_argument)) + +/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD, + except that it indicates to GCC that the supported format string directives + are the ones of the system printf(), rather than the ones standardized by + ISO C99 and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, formatstring_parameter, first_argument)) + /* _GL_ATTRIBUTE_FORMAT_SCANF indicates to GCC that the function takes a format string and arguments, where the format string directives are the ones standardized by ISO C99 @@ -174,13 +188,13 @@ # define dprintf rpl_dprintf # endif _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((2))); _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...)); # else # if !@HAVE_DPRINTF@ _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((2))); # endif _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...)); @@ -215,9 +229,27 @@ _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - " "use gnulib module fclose for portable POSIX compliance"); #endif +/* On native Windows, map 'fcloseall' to '_fcloseall', so that -loldnames is + not required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::fcloseall on all platforms that have + it. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef fcloseall -# define fcloseall _fcloseall +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fcloseall +# define fcloseall _fcloseall +# endif +_GL_CXXALIAS_MDA (fcloseall, int, (void)); +#else +# if @HAVE_DECL_FCLOSEALL@ +# if defined __FreeBSD__ +_GL_CXXALIAS_SYS (fcloseall, void, (void)); +# else +_GL_CXXALIAS_SYS (fcloseall, int, (void)); +# endif +# endif +#endif +#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCLOSEALL@ +_GL_CXXALIASWARN (fcloseall); #endif #if @GNULIB_FDOPEN@ @@ -244,9 +276,20 @@ _GL_CXXALIASWARN (fdopen); /* Assume fdopen is always declared. */ _GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - " "use gnulib module fdopen for portability"); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef fdopen -# define fdopen _fdopen +#else +/* On native Windows, map 'fdopen' to '_fdopen', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::fdopen always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fdopen +# define fdopen _fdopen +# endif +_GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode)); +# else +_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); +# endif +_GL_CXXALIASWARN (fdopen); #endif #if @GNULIB_FFLUSH@ @@ -311,10 +354,19 @@ _GL_CXXALIASWARN (fgets); # endif #endif +/* On native Windows, map 'fileno' to '_fileno', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::fileno always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef fileno -# define fileno _fileno +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fileno +# define fileno _fileno +# endif +_GL_CXXALIAS_MDA (fileno, int, (FILE *restrict stream)); +#else +_GL_CXXALIAS_SYS (fileno, int, (FILE *restrict stream)); #endif +_GL_CXXALIASWARN (fileno); #if @GNULIB_FOPEN@ # if @REPLACE_FOPEN@ @@ -351,7 +403,7 @@ _GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX complian # if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ _GL_FUNCDECL_RPL (fprintf, int, (FILE *restrict fp, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # else _GL_FUNCDECL_RPL (fprintf, int, @@ -843,10 +895,19 @@ _GL_WARN_ON_USE (getline, "getline is unportable - " _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif +/* On native Windows, map 'getw' to '_getw', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::getw always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef getw -# define getw _getw +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getw +# define getw _getw +# endif +_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream)); +#else +_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream)); #endif +_GL_CXXALIASWARN (getw); #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ struct obstack; @@ -861,7 +922,7 @@ struct obstack; # endif _GL_FUNCDECL_RPL (obstack_printf, int, (struct obstack *obs, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (obstack_printf, int, (struct obstack *obs, const char *format, ...)); @@ -869,7 +930,7 @@ _GL_CXXALIAS_RPL (obstack_printf, int, # if !@HAVE_DECL_OBSTACK_PRINTF@ _GL_FUNCDECL_SYS (obstack_printf, int, (struct obstack *obs, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (obstack_printf, int, @@ -882,7 +943,7 @@ _GL_CXXALIASWARN (obstack_printf); # endif _GL_FUNCDECL_RPL (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args)); @@ -890,7 +951,7 @@ _GL_CXXALIAS_RPL (obstack_vprintf, int, # if !@HAVE_DECL_OBSTACK_PRINTF@ _GL_FUNCDECL_SYS (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (obstack_vprintf, int, @@ -974,7 +1035,7 @@ _GL_FUNCDECL_RPL_1 (__printf__, int, (const char *restrict format, ...) __asm__ (@ASM_SYMBOL_PREFIX@ _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2) _GL_ARG_NONNULL ((1))); # else _GL_FUNCDECL_RPL_1 (__printf__, int, @@ -991,7 +1052,7 @@ _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); # endif _GL_FUNCDECL_RPL (printf, int, (const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...)); # endif @@ -1061,10 +1122,19 @@ _GL_CXXALIASWARN (puts); # endif #endif +/* On native Windows, map 'putw' to '_putw', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::putw always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef putw -# define putw _putw +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putw +# define putw _putw +# endif +_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream)); +#else +_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream)); #endif +_GL_CXXALIASWARN (putw); #if @GNULIB_REMOVE@ # if @REPLACE_REMOVE@ @@ -1182,7 +1252,7 @@ _GL_CXXALIASWARN (scanf); _GL_FUNCDECL_RPL (snprintf, int, (char *restrict str, size_t size, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4) _GL_ARG_NONNULL ((3))); _GL_CXXALIAS_RPL (snprintf, int, (char *restrict str, size_t size, @@ -1192,7 +1262,7 @@ _GL_CXXALIAS_RPL (snprintf, int, _GL_FUNCDECL_SYS (snprintf, int, (char *restrict str, size_t size, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4) _GL_ARG_NONNULL ((3))); # endif _GL_CXXALIAS_SYS (snprintf, int, @@ -1226,7 +1296,7 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - " # endif _GL_FUNCDECL_RPL (sprintf, int, (char *restrict str, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (sprintf, int, (char *restrict str, const char *restrict format, ...)); @@ -1245,10 +1315,19 @@ _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - " "POSIX compliance"); #endif +/* On native Windows, map 'tempnam' to '_tempnam', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::tempnam always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef tempnam -# define tempnam _tempnam +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef tempnam +# define tempnam _tempnam +# endif +_GL_CXXALIAS_MDA (tempnam, char *, (const char *dir, const char *prefix)); +#else +_GL_CXXALIAS_SYS (tempnam, char *, (const char *dir, const char *prefix)); #endif +_GL_CXXALIASWARN (tempnam); #if @GNULIB_TMPFILE@ # if @REPLACE_TMPFILE@ @@ -1282,7 +1361,7 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " # endif _GL_FUNCDECL_RPL (asprintf, int, (char **result, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (asprintf, int, (char **result, const char *format, ...)); @@ -1290,7 +1369,7 @@ _GL_CXXALIAS_RPL (asprintf, int, # if !@HAVE_VASPRINTF@ _GL_FUNCDECL_SYS (asprintf, int, (char **result, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (asprintf, int, @@ -1303,7 +1382,7 @@ _GL_CXXALIASWARN (asprintf); # endif _GL_FUNCDECL_RPL (vasprintf, int, (char **result, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (vasprintf, int, (char **result, const char *format, va_list args)); @@ -1311,7 +1390,7 @@ _GL_CXXALIAS_RPL (vasprintf, int, # if !@HAVE_VASPRINTF@ _GL_FUNCDECL_SYS (vasprintf, int, (char **result, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (vasprintf, int, @@ -1327,7 +1406,7 @@ _GL_CXXALIASWARN (vasprintf); # endif _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((2))); _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *restrict format, va_list args)); @@ -1335,7 +1414,7 @@ _GL_CXXALIAS_RPL (vdprintf, int, # if !@HAVE_VDPRINTF@ _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((2))); # endif /* Need to cast, because on Solaris, the third parameter will likely be @@ -1365,7 +1444,7 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - " _GL_FUNCDECL_RPL (vfprintf, int, (FILE *restrict fp, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # else _GL_FUNCDECL_RPL (vfprintf, int, @@ -1432,7 +1511,7 @@ _GL_CXXALIASWARN (vfscanf); # define GNULIB_overrides_vprintf 1 # if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ _GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0) _GL_ARG_NONNULL ((1))); # else _GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) @@ -1487,7 +1566,7 @@ _GL_CXXALIASWARN (vscanf); _GL_FUNCDECL_RPL (vsnprintf, int, (char *restrict str, size_t size, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))); _GL_CXXALIAS_RPL (vsnprintf, int, (char *restrict str, size_t size, @@ -1497,7 +1576,7 @@ _GL_CXXALIAS_RPL (vsnprintf, int, _GL_FUNCDECL_SYS (vsnprintf, int, (char *restrict str, size_t size, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))); # endif _GL_CXXALIAS_SYS (vsnprintf, int, @@ -1523,7 +1602,7 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " _GL_FUNCDECL_RPL (vsprintf, int, (char *restrict str, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (vsprintf, int, (char *restrict str, diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 47a1309e633..1964443a22f 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -53,8 +53,8 @@ # include #endif -/* Native Windows platforms declare mktemp() in . */ -#if 0 && (defined _WIN32 && ! defined __CYGWIN__) +/* Native Windows platforms declare _mktemp() in . */ +#if defined _WIN32 && !defined __CYGWIN__ # include #endif @@ -149,6 +149,31 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - " #endif +/* Allocate memory with indefinite extent and specified alignment. */ +#if @GNULIB_ALIGNED_ALLOC@ +# if @REPLACE_ALIGNED_ALLOC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef aligned_alloc +# define aligned_alloc rpl_aligned_alloc +# endif +_GL_FUNCDECL_RPL (aligned_alloc, void *, (size_t alignment, size_t size)); +_GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size)); +# else +# if @HAVE_ALIGNED_ALLOC@ +_GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size)); +# endif +# endif +# if @HAVE_ALIGNED_ALLOC@ +_GL_CXXALIASWARN (aligned_alloc); +# endif +#elif defined GNULIB_POSIXCHECK +# undef aligned_alloc +# if HAVE_RAW_DECL_ALIGNED_ALLOC +_GL_WARN_ON_USE (aligned_alloc, "aligned_alloc is not portable - " + "use gnulib module aligned_alloc for portability"); +# endif +#endif + #if @GNULIB_ATOLL@ /* Parse a signed decimal integer. Returns the value of the integer. Errors are not detected. */ @@ -217,19 +242,86 @@ _GL_WARN_ON_USE (canonicalize_file_name, # endif #endif +/* On native Windows, map 'ecvt' to '_ecvt', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::ecvt on all platforms that have + it. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef ecvt -# define ecvt _ecvt +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ecvt +# define ecvt _ecvt +# endif +_GL_CXXALIAS_MDA (ecvt, char *, + (double number, int ndigits, int *decptp, int *signp)); +#else +# if @HAVE_DECL_ECVT@ +_GL_CXXALIAS_SYS (ecvt, char *, + (double number, int ndigits, int *decptp, int *signp)); +# endif +#endif +#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_ECVT@ +_GL_CXXALIASWARN (ecvt); #endif +/* On native Windows, map 'fcvt' to '_fcvt', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::fcvt on all platforms that have + it. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef fcvt -# define fcvt _fcvt +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fcvt +# define fcvt _fcvt +# endif +_GL_CXXALIAS_MDA (fcvt, char *, + (double number, int ndigits, int *decptp, int *signp)); +#else +# if @HAVE_DECL_FCVT@ +_GL_CXXALIAS_SYS (fcvt, char *, + (double number, int ndigits, int *decptp, int *signp)); +# endif +#endif +#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCVT@ +_GL_CXXALIASWARN (fcvt); +#endif + +#if @GNULIB_FREE_POSIX@ +# if @REPLACE_FREE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef free +# define free rpl_free +# endif +_GL_FUNCDECL_RPL (free, void, (void *ptr)); +_GL_CXXALIAS_RPL (free, void, (void *ptr)); +# else +_GL_CXXALIAS_SYS (free, void, (void *ptr)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (free); +# endif +#elif defined GNULIB_POSIXCHECK +# undef free +/* Assume free is always declared. */ +_GL_WARN_ON_USE (free, "free is not future POSIX compliant everywhere - " + "use gnulib module free for portability"); #endif +/* On native Windows, map 'gcvt' to '_gcvt', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::gcvt on all platforms that have + it. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef gcvt -# define gcvt _gcvt +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gcvt +# define gcvt _gcvt +# endif +_GL_CXXALIAS_MDA (gcvt, char *, (double number, int ndigits, char *buf)); +#else +# if @HAVE_DECL_GCVT@ +_GL_CXXALIAS_SYS (gcvt, char *, (double number, int ndigits, char *buf)); +# endif +#endif +#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_GCVT@ +_GL_CXXALIASWARN (gcvt); #endif #if @GNULIB_GETLOADAVG@ @@ -483,9 +575,47 @@ _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - " # endif #endif +/* On native Windows, map 'mktemp' to '_mktemp', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::mktemp always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef mktemp -# define mktemp _mktemp +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mktemp +# define mktemp _mktemp +# endif +_GL_CXXALIAS_MDA (mktemp, char *, (char * /*template*/)); +#else +_GL_CXXALIAS_SYS (mktemp, char *, (char * /*template*/)); +#endif +_GL_CXXALIASWARN (mktemp); + +/* Allocate memory with indefinite extent and specified alignment. */ +#if @GNULIB_POSIX_MEMALIGN@ +# if @REPLACE_POSIX_MEMALIGN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef posix_memalign +# define posix_memalign rpl_posix_memalign +# endif +_GL_FUNCDECL_RPL (posix_memalign, int, + (void **memptr, size_t alignment, size_t size) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_memalign, int, + (void **memptr, size_t alignment, size_t size)); +# else +# if @HAVE_POSIX_MEMALIGN@ +_GL_CXXALIAS_SYS (posix_memalign, int, + (void **memptr, size_t alignment, size_t size)); +# endif +# endif +# if @HAVE_POSIX_MEMALIGN@ +_GL_CXXALIASWARN (posix_memalign); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_memalign +# if HAVE_RAW_DECL_POSIX_MEMALIGN +_GL_WARN_ON_USE (posix_memalign, "posix_memalign is not portable - " + "use gnulib module posix_memalign for portability"); +# endif #endif #if @GNULIB_POSIX_OPENPT@ @@ -576,9 +706,22 @@ _GL_CXXALIAS_MDA (putenv, int, (char *string)); _GL_CXXALIAS_SYS (putenv, int, (char *string)); # endif _GL_CXXALIASWARN (putenv); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef putenv -# define putenv _putenv +#else +/* On native Windows, map 'putenv' to '_putenv', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::putenv always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putenv +# define putenv _putenv +# endif +/* Need to cast, because on mingw, the parameter is either + 'const char *string' or 'char *string'. */ +_GL_CXXALIAS_MDA_CAST (putenv, int, (char *string)); +# else +_GL_CXXALIAS_SYS (putenv, int, (char *string)); +# endif +_GL_CXXALIASWARN (putenv); #endif #if @GNULIB_QSORT_R@ diff --git a/lib/string.in.h b/lib/string.in.h index 9724addef43..f34bfabfb99 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -123,16 +123,28 @@ _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module"); #endif +/* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::memccpy always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef memccpy -# define memccpy _memccpy +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef memccpy +# define memccpy _memccpy +# endif +_GL_CXXALIAS_MDA (memccpy, void *, + (void *dest, const void *src, int c, size_t n)); +#else +_GL_CXXALIAS_SYS (memccpy, void *, + (void *dest, const void *src, int c, size_t n)); #endif +_GL_CXXALIASWARN (memccpy); /* Return the first instance of C within N bytes of S, or NULL. */ #if @GNULIB_MEMCHR@ # if @REPLACE_MEMCHR@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef memchr # define memchr rpl_memchr # endif _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) @@ -413,9 +425,23 @@ _GL_CXXALIASWARN (strdup); _GL_WARN_ON_USE (strdup, "strdup is unportable - " "use gnulib module strdup for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef strdup -# define strdup _strdup +#else +/* On native Windows, map 'creat' to '_creat', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::creat always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strdup +# define strdup _strdup +# endif +_GL_CXXALIAS_MDA (strdup, char *, (char const *__s)); +# else +# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup +# undef strdup +# endif +_GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); +# endif +_GL_CXXALIASWARN (strdup); #endif /* Append no more than N characters from SRC onto DEST. */ diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index 72cb9ba7b0f..ac1e93919b7 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -103,9 +103,16 @@ /* Get definition of 'sigset_t'. But avoid namespace pollution on glibc systems and "unknown type name" problems on Cygwin. + On OS/2 kLIBC, sigset_t is defined in , too. In addition, + if is included, -> -> + are included. Then -> are included by GNULIB. By the + way, requires PAGE_SIZE defined in . However, + has not been processed, yet. As a result, 'PAGE_SIZE' + undeclared error occurs in . Do this after the include_next (for the sake of OpenBSD 5.0) but before the split double-inclusion guard (for the sake of Solaris). */ -#if !((defined __GLIBC__ || defined __CYGWIN__) && !defined __UCLIBC__) +#if !((defined __GLIBC__ || defined __CYGWIN__ || defined __KLIBC__) \ + && !defined __UCLIBC__) # include #endif diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 3e0e4b27b7e..3ce2a0dcf15 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -375,11 +375,11 @@ struct stat # define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) #endif -/* S_IXUGO is a common extension to POSIX. */ +/* Although S_IXUGO and S_IRWXUGO are not specified by POSIX and are + not implemented in GNU/Linux, some Gnulib-using apps use the macros. */ #if !S_IXUGO # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) #endif - #ifndef S_IRWXUGO # define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) #endif @@ -391,10 +391,20 @@ struct stat #endif +/* On native Windows, map 'chmod' to '_chmod', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::chmod always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef chmod -# define chmod _chmod +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef chmod +# define chmod _chmod +# endif +/* Need to cast, because in mingw the last argument is 'int mode'. */ +_GL_CXXALIAS_MDA_CAST (chmod, int, (const char *filename, mode_t mode)); +#else +_GL_CXXALIAS_SYS (chmod, int, (const char *filename, mode_t mode)); #endif +_GL_CXXALIASWARN (chmod); #if @GNULIB_FCHMODAT@ @@ -808,10 +818,20 @@ _GL_WARN_ON_USE (stat, "stat is unportable - " #endif +/* On native Windows, map 'umask' to '_umask', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::umask always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef umask -# define umask _umask +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef umask +# define umask _umask +# endif +/* Need to cast, because in mingw the last argument is 'int mode'. */ +_GL_CXXALIAS_MDA_CAST (umask, mode_t, (mode_t mask)); +#else +_GL_CXXALIAS_SYS (umask, mode_t, (mode_t mask)); #endif +_GL_CXXALIASWARN (umask); #if @GNULIB_UTIMENSAT@ diff --git a/lib/tempname.c b/lib/tempname.c index cfb0fc42eca..b9f7cc8703d 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -47,9 +47,11 @@ #include #include +#include #include #include #include +#include #if _LIBC # define struct_stat64 struct stat64 @@ -60,27 +62,33 @@ # define __mkdir mkdir # define __open open # define __lxstat64(version, file, buf) lstat (file, buf) +# define __getrandom getrandom +# define __clock_gettime64 clock_gettime +# define __timespec64 timespec #endif -#ifdef _LIBC -# include -# define RANDOM_BITS(Var) ((Var) = random_bits ()) -typedef uint32_t random_value; -# define RANDOM_VALUE_MAX UINT32_MAX -# define BASE_62_DIGITS 5 /* 62**5 < UINT32_MAX */ -# define BASE_62_POWER (62 * 62 * 62 * 62 * 62) /* 2**BASE_62_DIGITS */ -#else /* Use getrandom if it works, falling back on a 64-bit linear - congruential generator that starts with whatever Var's value - happens to be. */ -# define RANDOM_BITS(Var) \ - ((void) (getrandom (&(Var), sizeof (Var), 0) == sizeof (Var) \ - || ((Var) = 2862933555777941757 * (Var) + 3037000493))) + congruential generator that starts with Var's value + mixed in with a clock's low-order bits if available. */ typedef uint_fast64_t random_value; -# define RANDOM_VALUE_MAX UINT_FAST64_MAX -# define BASE_62_DIGITS 10 /* 62**10 < UINT_FAST64_MAX */ -# define BASE_62_POWER (62LL * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62) +#define RANDOM_VALUE_MAX UINT_FAST64_MAX +#define BASE_62_DIGITS 10 /* 62**10 < UINT_FAST64_MAX */ +#define BASE_62_POWER (62LL * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62 * 62) + +static random_value +random_bits (random_value var) +{ + random_value r; + if (__getrandom (&r, sizeof r, 0) == sizeof r) + return r; +#if _LIBC || (defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME) + /* Add entropy if getrandom is not supported. */ + struct __timespec64 tv; + __clock_gettime64 (CLOCK_MONOTONIC, &tv); + var ^= tv.tv_nsec; #endif + return 2862933555777941757 * var + 3037000493; +} #if _LIBC /* Return nonzero if DIR is an existent directory. */ @@ -250,8 +258,11 @@ try_tempname_len (char *tmpl, int suffixlen, void *args, unsigned int attempts = ATTEMPTS_MIN; #endif - /* A random variable. */ - random_value v; + /* A random variable. The initial value is used only the for fallback path + on 'random_bits' on 'getrandom' failure. Its initial value tries to use + some entropy from the ASLR and ignore possible bits from the stack + alignment. */ + random_value v = ((uintptr_t) &v) / alignof (max_align_t); /* How many random base-62 digits can currently be extracted from V. */ int vdigits = 0; @@ -279,7 +290,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args, if (vdigits == 0) { do - RANDOM_BITS (v); + v = random_bits (v); while (unfair_min <= v); vdigits = BASE_62_DIGITS; diff --git a/lib/time.in.h b/lib/time.in.h index 32e6ec03ef4..1b17c156eba 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -145,9 +145,20 @@ _GL_CXXALIAS_MDA (tzset, void, (void)); _GL_CXXALIAS_SYS (tzset, void, (void)); # endif _GL_CXXALIASWARN (tzset); -# elif defined _WIN32 && !defined __CYGWIN__ -# undef tzset -# define tzset _tzset +# else +/* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::tzset always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef tzset +# define tzset _tzset +# endif +_GL_CXXALIAS_MDA (tzset, void, (void)); +# else +_GL_CXXALIAS_SYS (tzset, void, (void)); +# endif +_GL_CXXALIASWARN (tzset); # endif /* Return the 'time_t' representation of TP and normalize TP. */ @@ -356,17 +367,17 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " # endif # if defined GNULIB_POSIXCHECK # undef asctime_r -_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " +_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); # endif # if defined GNULIB_POSIXCHECK # undef ctime -_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " +_GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); # endif # if defined GNULIB_POSIXCHECK # undef ctime_r -_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " +_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - " "better use strftime (or even sprintf) instead"); # endif diff --git a/lib/time_rz.c b/lib/time_rz.c index 95438cf876e..8992c2e37e0 100644 --- a/lib/time_rz.c +++ b/lib/time_rz.c @@ -27,19 +27,15 @@ #include #include -#include #include #include #include #include #include "flexmember.h" +#include "idx.h" #include "time-internal.h" -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - /* The approximate size to use for small allocation requests. This is the largest "small" request for the GNU C library malloc. */ enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; @@ -125,14 +121,8 @@ save_abbr (timezone_t tz, struct tm *tm) { if (! (*zone_copy || (zone_copy == tz->abbrs && tz->tz_is_set))) { - size_t zone_size = strlen (zone) + 1; - size_t zone_used = zone_copy - tz->abbrs; - if (SIZE_MAX - zone_used < zone_size) - { - errno = ENOMEM; - return false; - } - if (zone_used + zone_size < ABBR_SIZE_MIN) + idx_t zone_size = strlen (zone) + 1; + if (zone_size < tz->abbrs + ABBR_SIZE_MIN - zone_copy) extend_abbrs (zone_copy, zone, zone_size); else { diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 357a35e3881..4033ffeef72 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -93,20 +93,18 @@ # undef __need_system_stdlib_h #endif -/* Native Windows platforms declare chdir, getcwd, rmdir in +/* Native Windows platforms declare _chdir, _getcwd, _rmdir in and/or , not in . - They also declare access(), chmod(), close(), dup(), dup2(), isatty(), - lseek(), read(), unlink(), write() in . */ -#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ - || defined GNULIB_POSIXCHECK) \ - && (defined _WIN32 && ! defined __CYGWIN__)) -# include /* mingw32, mingw64 */ -# include /* mingw64, MSVC 9 */ -#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \ - || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \ - || defined GNULIB_POSIXCHECK) \ - && (defined _WIN32 && ! defined __CYGWIN__) + They also declare _access(), _chmod(), _close(), _dup(), _dup2(), _isatty(), + _lseek(), _read(), _unlink(), _write() in . */ +#if defined _WIN32 && !defined __CYGWIN__ # include +# include +#endif + +/* Native Windows platforms declare _execl*, _execv* in . */ +#if defined _WIN32 && !defined __CYGWIN__ +# include #endif /* AIX and OSF/1 5.1 declare getdomainname in , not in . @@ -138,11 +136,8 @@ /* MSVC defines off_t in . May also define off_t to a 64-bit type on native Windows. */ -/* But avoid namespace pollution on glibc systems. */ -#ifndef __GLIBC__ -/* Get off_t, ssize_t. */ -# include -#endif +/* Get off_t, ssize_t, mode_t. */ +#include /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ @@ -292,9 +287,20 @@ _GL_WARN_ON_USE (access, "access does not always support X_OK - " "also, this function is a security risk - " "use the gnulib module faccessat instead"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef access -# define access _access +#else +/* On native Windows, map 'access' to '_access', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::access always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef access +# define access _access +# endif +_GL_CXXALIAS_MDA (access, int, (const char *file, int mode)); +# else +_GL_CXXALIAS_SYS (access, int, (const char *file, int mode)); +# endif +_GL_CXXALIASWARN (access); #endif @@ -315,9 +321,20 @@ _GL_CXXALIASWARN (chdir); _GL_WARN_ON_USE (chown, "chdir is not always in - " "use gnulib module chdir for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef chdir -# define chdir _chdir +#else +/* On native Windows, map 'chdir' to '_chdir', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::chdir always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef chdir +# define chdir _chdir +# endif +_GL_CXXALIAS_MDA (chdir, int, (const char *file)); +# else +_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIASWARN (chdir); #endif @@ -380,9 +397,20 @@ _GL_CXXALIASWARN (close); /* Assume close is always declared. */ _GL_WARN_ON_USE (close, "close does not portably work on sockets - " "use gnulib module close for portability"); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef close -# define close _close +#else +/* On native Windows, map 'close' to '_close', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::close always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef close +# define close _close +# endif +_GL_CXXALIAS_MDA (close, int, (int fd)); +# else +_GL_CXXALIAS_SYS (close, int, (int fd)); +# endif +_GL_CXXALIASWARN (close); #endif @@ -397,10 +425,11 @@ _GL_CXXALIAS_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos, # endif _GL_CXXALIASWARN (copy_file_range); #elif defined GNULIB_POSIXCHECK -/* Assume copy_file_range is always declared. */ +# if HAVE_RAW_DECL_COPY_FILE_RANGE _GL_WARN_ON_USE (copy_file_range, "copy_file_range is unportable - " "use gnulib module copy_file_range for portability"); +# endif #endif @@ -427,9 +456,20 @@ _GL_CXXALIASWARN (dup); _GL_WARN_ON_USE (dup, "dup is unportable - " "use gnulib module dup for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef dup -# define dup _dup +#else +/* On native Windows, map 'dup' to '_dup', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::dup always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef dup +# define dup _dup +# endif +_GL_CXXALIAS_MDA (dup, int, (int oldfd)); +# else +_GL_CXXALIAS_SYS (dup, int, (int oldfd)); +# endif +_GL_CXXALIASWARN (dup); #endif @@ -461,9 +501,20 @@ _GL_CXXALIASWARN (dup2); _GL_WARN_ON_USE (dup2, "dup2 is unportable - " "use gnulib module dup2 for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef dup2 -# define dup2 _dup2 +#else +/* On native Windows, map 'dup2' to '_dup2', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::dup2 always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef dup2 +# define dup2 _dup2 +# endif +_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd)); +# else +_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd)); +# endif +_GL_CXXALIASWARN (dup2); #endif @@ -564,40 +615,116 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - " #endif +/* On native Windows, map 'execl' to '_execl', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execl always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execl -# define execl _execl +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execl +# define execl _execl +# endif +_GL_CXXALIAS_MDA (execl, intptr_t, (const char *program, const char *arg, ...)); +#else +_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...)); #endif +_GL_CXXALIASWARN (execl); +/* On native Windows, map 'execle' to '_execle', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execle always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execle -# define execle _execle +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execle +# define execle _execle +# endif +_GL_CXXALIAS_MDA (execle, intptr_t, (const char *program, const char *arg, ...)); +#else +_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...)); #endif +_GL_CXXALIASWARN (execle); +/* On native Windows, map 'execlp' to '_execlp', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execlp always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execlp -# define execlp _execlp +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execlp +# define execlp _execlp +# endif +_GL_CXXALIAS_MDA (execlp, intptr_t, (const char *program, const char *arg, ...)); +#else +_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...)); #endif +_GL_CXXALIASWARN (execlp); +/* On native Windows, map 'execv' to '_execv', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execv always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execv -# define execv _execv +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execv +# define execv _execv +# endif +_GL_CXXALIAS_MDA (execv, intptr_t, + (const char *program, const char * const *argv)); +#else +_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv)); #endif +_GL_CXXALIASWARN (execv); +/* On native Windows, map 'execve' to '_execve', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execve always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execve -# define execve _execve +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execve +# define execve _execve +# endif +_GL_CXXALIAS_MDA (execve, intptr_t, + (const char *program, const char * const *argv, + const char * const *env)); +#else +_GL_CXXALIAS_SYS (execve, int, + (const char *program, char * const *argv, char * const *env)); #endif +_GL_CXXALIASWARN (execve); +/* On native Windows, map 'execvp' to '_execvp', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execvp always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execvp -# define execvp _execvp +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execvp +# define execvp _execvp +# endif +_GL_CXXALIAS_MDA (execvp, intptr_t, + (const char *program, const char * const *argv)); +#else +_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv)); #endif +_GL_CXXALIASWARN (execvp); +/* On native Windows, map 'execvpe' to '_execvpe', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::execvpe on all platforms that have + it. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef execvpe -# define execvpe _execvpe +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef execvpe +# define execvpe _execvpe +# endif +_GL_CXXALIAS_MDA (execvpe, intptr_t, + (const char *program, const char * const *argv, + const char * const *env)); +#else +# if @HAVE_DECL_EXECVPE@ +_GL_CXXALIAS_SYS (execvpe, int, + (const char *program, char * const *argv, char * const *env)); +# endif +#endif +#if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_EXECVPE@ +_GL_CXXALIASWARN (execvpe); #endif @@ -794,9 +921,22 @@ _GL_CXXALIASWARN (getcwd); _GL_WARN_ON_USE (getcwd, "getcwd is unportable - " "use gnulib module getcwd for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef getcwd -# define getcwd _getcwd +#else +/* On native Windows, map 'getcwd' to '_getcwd', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::getcwd always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getcwd +# define getcwd _getcwd +# endif +/* Need to cast, because on mingw, the second parameter is either + 'int size' or 'size_t size'. */ +_GL_CXXALIAS_MDA_CAST (getcwd, char *, (char *buf, size_t size)); +# else +_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size)); +# endif +_GL_CXXALIASWARN (getcwd); #endif @@ -1131,10 +1271,19 @@ _GL_WARN_ON_USE (getpass, "getpass is unportable - " #endif +/* On native Windows, map 'getpid' to '_getpid', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::getpid always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef getpid -# define getpid _getpid +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getpid +# define getpid _getpid +# endif +_GL_CXXALIAS_MDA (getpid, int, (void)); +#else +_GL_CXXALIAS_SYS (getpid, pid_t, (void)); #endif +_GL_CXXALIASWARN (getpid); #if @GNULIB_GETUSERSHELL@ @@ -1225,9 +1374,20 @@ _GL_CXXALIASWARN (isatty); _GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - " "use gnulib module isatty for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef isatty -# define isatty _isatty +#else +/* On native Windows, map 'isatty' to '_isatty', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::isatty always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef isatty +# define isatty _isatty +# endif +_GL_CXXALIAS_MDA (isatty, int, (int fd)); +# else +_GL_CXXALIAS_SYS (isatty, int, (int fd)); +# endif +_GL_CXXALIASWARN (isatty); #endif @@ -1355,9 +1515,20 @@ _GL_CXXALIASWARN (lseek); _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " "systems - use gnulib module lseek for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef lseek -# define lseek _lseek +#else +/* On native Windows, map 'lseek' to '_lseek', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::lseek always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef lseek +# define lseek _lseek +# endif +_GL_CXXALIAS_MDA (lseek, long, (int fd, long offset, int whence)); +# else +_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence)); +# endif +_GL_CXXALIASWARN (lseek); #endif @@ -1497,15 +1668,27 @@ _GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count)); # endif _GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, size_t count)); # else -/* Need to cast, because on mingw, the third parameter is - unsigned int count - and the return type is 'int'. */ -_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count)); +_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count)); +# endif +_GL_CXXALIASWARN (read); +#else +/* On native Windows, map 'read' to '_read', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::read always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef read +# define read _read +# endif +# ifdef __MINGW32__ +_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count)); +# else +_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count)); +# endif +# else +_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count)); # endif _GL_CXXALIASWARN (read); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef read -# define read _read #endif @@ -1604,9 +1787,20 @@ _GL_CXXALIASWARN (rmdir); _GL_WARN_ON_USE (rmdir, "rmdir is unportable - " "use gnulib module rmdir for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef rmdir -# define rmdir _rmdir +#else +/* On native Windows, map 'rmdir' to '_rmdir', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::rmdir always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef rmdir +# define rmdir _rmdir +# endif +_GL_CXXALIAS_MDA (rmdir, int, (char const *name)); +# else +_GL_CXXALIAS_SYS (rmdir, int, (char const *name)); +# endif +_GL_CXXALIASWARN (rmdir); #endif @@ -1665,10 +1859,19 @@ _GL_WARN_ON_USE (sleep, "sleep is unportable - " #endif +/* On native Windows, map 'swab' to '_swab', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::creat always. */ #if defined _WIN32 && !defined __CYGWIN__ -# undef swab -# define swab _swab +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef swab +# define swab _swab +# endif +_GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n)); +#else +_GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n)); #endif +_GL_CXXALIASWARN (swab); #if @GNULIB_SYMLINK@ @@ -1811,9 +2014,20 @@ _GL_CXXALIASWARN (unlink); _GL_WARN_ON_USE (unlink, "unlink is not portable - " "use gnulib module unlink for portability"); # endif -#elif defined _WIN32 && !defined __CYGWIN__ -# undef unlink -# define unlink _unlink +#else +/* On native Windows, map 'unlink' to '_unlink', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::unlink always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unlink +# define unlink _unlink +# endif +_GL_CXXALIAS_MDA (unlink, int, (char const *file)); +# else +_GL_CXXALIAS_SYS (unlink, int, (char const *file)); +# endif +_GL_CXXALIASWARN (unlink); #endif @@ -1892,15 +2106,27 @@ _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); # endif _GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, size_t count)); # else -/* Need to cast, because on mingw, the third parameter is - unsigned int count - and the return type is 'int'. */ -_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count)); +_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count)); +# endif +_GL_CXXALIASWARN (write); +#else +/* On native Windows, map 'write' to '_write', so that -loldnames is not + required. In C++ with GNULIB_NAMESPACE, avoid differences between + platforms by defining GNULIB_NAMESPACE::write always. */ +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef write +# define write _write +# endif +# ifdef __MINGW32__ +_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count)); +# else +_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count)); +# endif +# else +_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count)); # endif _GL_CXXALIASWARN (write); -#elif defined _WIN32 && !defined __CYGWIN__ -# undef write -# define write _write #endif _GL_INLINE_HEADER_END diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h index 13ee23031a0..7cd4a74f04d 100644 --- a/lib/xalloc-oversized.h +++ b/lib/xalloc-oversized.h @@ -41,7 +41,7 @@ typedef size_t __xalloc_count_type; positive and N must be nonnegative. This is a macro, not a function, so that it works correctly even when SIZE_MAX < N. */ -#if 7 <= __GNUC__ +#if 7 <= __GNUC__ && !defined __clang__ # define xalloc_oversized(n, s) \ __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1) #elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ diff --git a/m4/alloca.m4 b/m4/alloca.m4 index d8414896308..e3c377c9e2c 100644 --- a/m4/alloca.m4 +++ b/m4/alloca.m4 @@ -1,4 +1,4 @@ -# alloca.m4 serial 18 +# alloca.m4 serial 20 dnl Copyright (C) 2002-2004, 2006-2007, 2009-2020 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -104,5 +104,5 @@ AH_VERBATIM([STACK_DIRECTION], STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION])dnl AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) -]) +])# _AC_LIBOBJ_ALLOCA ]) diff --git a/m4/extensions.m4 b/m4/extensions.m4 index d7c95effdac..44be1d15cbf 100644 --- a/m4/extensions.m4 +++ b/m4/extensions.m4 @@ -1,4 +1,4 @@ -# serial 18 -*- Autoconf -*- +# serial 21 -*- Autoconf -*- # Enable extensions on systems that normally disable them. # Copyright (C) 2003, 2006-2020 Free Software Foundation, Inc. @@ -6,9 +6,14 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. +dnl Define to empty for the benefit of Autoconf 2.69 and earlier, so that +dnl AC_USE_SYSTEM_EXTENSIONS (below) can be used unchanged from Autoconf 2.70+. +m4_ifndef([AC_CHECK_INCLUDES_DEFAULT], + [AC_DEFUN([AC_CHECK_INCLUDES_DEFAULT], [])]) + # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from git # Autoconf. Perhaps we can remove this once we can assume Autoconf -# 2.70 or later everywhere, but since Autoconf mutates rapidly +# is recent-enough everywhere, but since Autoconf mutates rapidly # enough in this area it's likely we'll need to redefine # AC_USE_SYSTEM_EXTENSIONS for quite some time. @@ -26,36 +31,27 @@ # its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS # invocation occurs in gl_EARLY, not in gl_INIT. +m4_version_prereq([2.70.1], [], [ + # AC_USE_SYSTEM_EXTENSIONS # ------------------------ # Enable extensions on systems that normally disable them, # typically due to standards-conformance issues. -# -# Remember that #undef in AH_VERBATIM gets replaced with #define by -# AC_DEFINE. The goal here is to define all known feature-enabling -# macros, then, if reports of conflicts are made, disable macros that -# cause problems on some platforms (such as __EXTENSIONS__). +# We unconditionally define as many of the known feature-enabling +# as possible, reserving conditional behavior for macros that are +# known to cause problems on some platforms (such as __EXTENSIONS__). AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS], -[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl +[AC_BEFORE([$0], [AC_PREPROC_IFELSE])dnl +AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl +AC_BEFORE([$0], [AC_LINK_IFELSE])dnl AC_BEFORE([$0], [AC_RUN_IFELSE])dnl - - AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) - if test "$MINIX" = yes; then - AC_DEFINE([_POSIX_SOURCE], [1], - [Define to 1 if you need to in order for 'stat' and other - things to work.]) - AC_DEFINE([_POSIX_1_SOURCE], [2], - [Define to 2 if the system does not provide POSIX.1 features - except with this defined.]) - AC_DEFINE([_MINIX], [1], - [Define to 1 if on MINIX.]) - AC_DEFINE([_NETBSD_SOURCE], [1], - [Define to 1 to make NetBSD features available. MINIX 3 needs this.]) - fi - +AC_BEFORE([$0], [AC_CHECK_INCLUDES_DEFAULT])dnl +dnl #undef in AH_VERBATIM gets replaced with #define by AC_DEFINE. dnl Use a different key than __EXTENSIONS__, as that name broke existing dnl configure.ac when using autoheader 2.62. - AH_VERBATIM([USE_SYSTEM_EXTENSIONS], +dnl The macros below are in alphabetical order ignoring leading _ or __ +dnl prefixes. +AH_VERBATIM([USE_SYSTEM_EXTENSIONS], [/* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # undef _ALL_SOURCE @@ -64,19 +60,44 @@ dnl configure.ac when using autoheader 2.62. #ifndef _DARWIN_C_SOURCE # undef _DARWIN_C_SOURCE #endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # undef _GNU_SOURCE #endif -/* Enable NetBSD extensions on NetBSD. */ +/* Enable X/Open compliant socket functions that do not require linking + with -lxnet on HP-UX 11.11. */ +#ifndef _HPUX_ALT_XOPEN_SOCKET_API +# undef _HPUX_ALT_XOPEN_SOCKET_API +#endif +/* Identify the host operating system as Minix. + This macro does not affect the system headers' behavior. + A future release of Autoconf may stop defining this macro. */ +#ifndef _MINIX +# undef _MINIX +#endif +/* Enable general extensions on NetBSD. + Enable NetBSD compatibility extensions on Minix. */ #ifndef _NETBSD_SOURCE # undef _NETBSD_SOURCE #endif -/* Enable OpenBSD extensions on NetBSD. */ +/* Enable OpenBSD compatibility extensions on NetBSD. + Oddly enough, this does nothing on OpenBSD. */ #ifndef _OPENBSD_SOURCE # undef _OPENBSD_SOURCE #endif -/* Enable threading extensions on Solaris. */ +/* Define to 1 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_SOURCE +# undef _POSIX_SOURCE +#endif +/* Define to 2 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_1_SOURCE +# undef _POSIX_1_SOURCE +#endif +/* Enable POSIX-compatible threading on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS # undef _POSIX_PTHREAD_SEMANTICS #endif @@ -112,22 +133,19 @@ dnl configure.ac when using autoheader 2.62. #ifndef _TANDEM_SOURCE # undef _TANDEM_SOURCE #endif -/* Enable X/Open extensions if necessary. HP-UX 11.11 defines - mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of - whether compiling with -Ae or -D_HPUX_SOURCE=1. */ +/* Enable X/Open extensions. Define to 500 only if necessary + to make mbstate_t available. */ #ifndef _XOPEN_SOURCE # undef _XOPEN_SOURCE #endif -/* Enable X/Open compliant socket functions that do not require linking - with -lxnet on HP-UX 11.11. */ -#ifndef _HPUX_ALT_XOPEN_SOCKET_API -# undef _HPUX_ALT_XOPEN_SOCKET_API -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif -]) +])dnl + + AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])dnl + _AC_CHECK_HEADER_ONCE([wchar.h]) + _AC_CHECK_HEADER_ONCE([minix/config.h]) + +dnl Defining __EXTENSIONS__ may break the system headers on some systems. +dnl (FIXME: Which ones?) AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], [ac_cv_safe_to_define___extensions__], [AC_COMPILE_IFELSE( @@ -136,11 +154,33 @@ dnl configure.ac when using autoheader 2.62. ]AC_INCLUDES_DEFAULT])], [ac_cv_safe_to_define___extensions__=yes], [ac_cv_safe_to_define___extensions__=no])]) - test $ac_cv_safe_to_define___extensions__ = yes && - AC_DEFINE([__EXTENSIONS__]) + +dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to +dnl 500, regardless of whether compiling with -Ae or -D_HPUX_SOURCE=1. +dnl But defining _XOPEN_SOURCE may turn *off* extensions on platforms +dnl not covered by turn-on-extensions macros (notably Dragonfly, Free, +dnl and OpenBSD, which don't have any equivalent of _NETBSD_SOURCE) so +dnl it should only be defined when necessary. + AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined], + [ac_cv_should_define__xopen_source], + [ac_cv_should_define__xopen_source=no + AS_IF([test $ac_cv_header_wchar_h = yes], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #include + mbstate_t x;]])], + [], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #define _XOPEN_SOURCE 500 + #include + mbstate_t x;]])], + [ac_cv_should_define__xopen_source=yes])])])]) + AC_DEFINE([_ALL_SOURCE]) AC_DEFINE([_DARWIN_C_SOURCE]) AC_DEFINE([_GNU_SOURCE]) + AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API]) AC_DEFINE([_NETBSD_SOURCE]) AC_DEFINE([_OPENBSD_SOURCE]) AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) @@ -152,24 +192,18 @@ dnl configure.ac when using autoheader 2.62. AC_DEFINE([__STDC_WANT_LIB_EXT2__]) AC_DEFINE([__STDC_WANT_MATH_SPEC_FUNCS__]) AC_DEFINE([_TANDEM_SOURCE]) - AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined], - [ac_cv_should_define__xopen_source], - [ac_cv_should_define__xopen_source=no - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ - #include - mbstate_t x;]])], - [], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ - #define _XOPEN_SOURCE 500 - #include - mbstate_t x;]])], - [ac_cv_should_define__xopen_source=yes])])]) - test $ac_cv_should_define__xopen_source = yes && - AC_DEFINE([_XOPEN_SOURCE], [500]) - AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API]) + AS_IF([test $ac_cv_header_minix_config_h = yes], + [MINIX=yes + AC_DEFINE([_MINIX]) + AC_DEFINE([_POSIX_SOURCE]) + AC_DEFINE([_POSIX_1_SOURCE], [2])], + [MINIX=]) + AS_IF([test $ac_cv_safe_to_define___extensions__ = yes], + [AC_DEFINE([__EXTENSIONS__])]) + AS_IF([test $ac_cv_should_define__xopen_source = yes], + [AC_DEFINE([_XOPEN_SOURCE], [500])]) ])# AC_USE_SYSTEM_EXTENSIONS +]) # gl_USE_SYSTEM_EXTENSIONS # ------------------------ @@ -177,13 +211,5 @@ dnl configure.ac when using autoheader 2.62. # typically due to standards-conformance issues. AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], [ - dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS. - dnl gnulib does not need it. But if it gets required by third-party macros - dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a - dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". - dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE, - dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck. - AC_REQUIRE([AC_GNU_SOURCE]) - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) ]) diff --git a/m4/fcntl.m4 b/m4/fcntl.m4 index ea24f3d64ef..547ff40b804 100644 --- a/m4/fcntl.m4 +++ b/m4/fcntl.m4 @@ -1,4 +1,4 @@ -# fcntl.m4 serial 10 +# fcntl.m4 serial 11 dnl Copyright (C) 2009-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -81,15 +81,29 @@ AC_DEFUN([gl_FUNC_FCNTL], behavior does not match POSIX]) ;; esac - dnl Many systems lack F_DUPFD_CLOEXEC + dnl Many systems lack F_DUPFD_CLOEXEC. + dnl NetBSD 9.0 declares F_DUPFD_CLOEXEC but it works only like F_DUPFD. AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC], [gl_cv_func_fcntl_f_dupfd_cloexec], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -#ifndef F_DUPFD_CLOEXEC -choke me -#endif - ]])], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE( + [[#include + #include + int main (int argc, char *argv[]) + { + if (argc == 1) + /* parent process */ + { + if (fcntl (1, F_DUPFD_CLOEXEC, 10) < 0) + return 1; + return execl ("./conftest", "./conftest", "child", NULL); + } + else + /* child process */ + return (fcntl (10, F_GETFL) < 0 ? 0 : 42); + } + ]]) + ], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #ifdef __linux__ /* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace @@ -98,12 +112,22 @@ choke me #endif ]])], [gl_cv_func_fcntl_f_dupfd_cloexec=yes], - [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])], - [gl_cv_func_fcntl_f_dupfd_cloexec=no])]) - if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then - gl_REPLACE_FCNTL - dnl No witness macro needed for this bug. - fi + [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"]) + ], + [gl_cv_func_fcntl_f_dupfd_cloexec=no], + [case "$host_os" in + # Guess no on NetBSD. + netbsd*) gl_cv_func_fcntl_f_dupfd_cloexec="guessing no" ;; + *) gl_cv_func_fcntl_f_dupfd_cloexec="$gl_cross_guess_normal" ;; + esac + ]) + ]) + case "$gl_cv_func_fcntl_f_dupfd_cloexec" in + *yes) ;; + *) gl_REPLACE_FCNTL + dnl No witness macro needed for this bug. + ;; + esac fi dnl Replace fcntl() for supporting the gnulib-defined fchdir() function, dnl to keep fchdir's bookkeeping up-to-date. diff --git a/m4/filemode.m4 b/m4/filemode.m4 index 5aaaa1a167d..8bbfcdbafe0 100644 --- a/m4/filemode.m4 +++ b/m4/filemode.m4 @@ -1,4 +1,4 @@ -# filemode.m4 serial 8 +# filemode.m4 serial 9 dnl Copyright (C) 2002, 2005-2006, 2009-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -6,6 +6,5 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FILEMODE], [ - AC_REQUIRE([AC_STRUCT_ST_DM_MODE]) AC_CHECK_DECLS_ONCE([strmode]) ]) diff --git a/m4/free.m4 b/m4/free.m4 new file mode 100644 index 00000000000..bf9fc31d9b4 --- /dev/null +++ b/m4/free.m4 @@ -0,0 +1,49 @@ +# free.m4 serial 5 +# Copyright (C) 2003-2005, 2009-2020 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Written by Paul Eggert and Bruno Haible. + +AC_DEFUN([gl_FUNC_FREE], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + + dnl In the next release of POSIX, free must preserve errno. + dnl https://www.austingroupbugs.net/view.php?id=385 + dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924 + dnl So far, we know of three platforms that do this: + dnl * glibc >= 2.33, thanks to the fix for this bug: + dnl + dnl * OpenBSD >= 4.5, thanks to this commit: + dnl + dnl * Solaris, because its malloc() implementation is based on brk(), + dnl not mmap(); hence its free() implementation makes no system calls. + dnl For other platforms, you can only be sure if they state it in their + dnl documentation, or by code inspection of the free() implementation in libc. + AC_CACHE_CHECK([whether free is known to preserve errno], + [gl_cv_func_free_preserves_errno], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[#if 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__) + #elif defined __OpenBSD__ + #elif defined __sun + #else + #error "'free' is not known to preserve errno" + #endif + ]])], + [gl_cv_func_free_preserves_errno=yes], + [gl_cv_func_free_preserves_errno=no]) + ]) + + case $gl_cv_func_free_preserves_errno in + *yes) ;; + *) REPLACE_FREE=1 ;; + esac +]) + +# Prerequisites of lib/free.c. +AC_DEFUN([gl_PREREQ_FREE], [:]) diff --git a/m4/fsusage.m4 b/m4/fsusage.m4 index 0bc62066aab..c15cfca4d3e 100644 --- a/m4/fsusage.m4 +++ b/m4/fsusage.m4 @@ -1,4 +1,4 @@ -# serial 34 +# serial 35 # Obtaining file system usage information. # Copyright (C) 1997-1998, 2000-2001, 2003-2020 Free Software Foundation, Inc. @@ -36,7 +36,6 @@ AC_DEFUN([gl_FILE_SYSTEM_USAGE], dnl Mac OS X >= 10.5 (32-bit mode). AC_REQUIRE([AC_SYS_LARGEFILE]) - AC_MSG_CHECKING([how to get file system space usage]) ac_fsusage_space=no # Perform only the link test since it seems there are no variants of the diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 33e56faa98e..2c0ae9bef40 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 57 +# gnulib-common.m4 serial 63 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -483,23 +483,17 @@ AC_DEFUN([gl_FEATURES_H], # gl_PROG_CC_C99 # Modifies the value of the shell variable CC in an attempt to make $CC # understand ISO C99 source code. -# This is like AC_PROG_CC_C99, except that -# - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC -# , -# but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99 -# . -# Remaining problems: -# - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options -# to CC twice -# . -# - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard. AC_DEFUN([gl_PROG_CC_C99], [ - dnl Change that version number to the minimum Autoconf version that supports - dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls. - m4_version_prereq([9.0], - [AC_REQUIRE([AC_PROG_CC_C99])], - [AC_REQUIRE([AC_PROG_CC_STDC])]) + dnl Just use AC_PROG_CC_C99. + dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted + dnl value of CC will contain the C99 enabling options twice. But this is only + dnl a cosmetic problem. + dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99; + dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete." + m4_version_prereq([2.70], + [AC_REQUIRE([AC_PROG_CC])], + [AC_REQUIRE([AC_PROG_CC_C99])]) ]) # gl_PROG_AR_RANLIB @@ -573,16 +567,16 @@ Amsterdam ]) # AC_C_RESTRICT -# This definition is copied from post-2.69 Autoconf and overrides the -# AC_C_RESTRICT macro from autoconf 2.60..2.69. It can be removed -# once autoconf >= 2.70 can be assumed. It's painful to check version -# numbers, and in practice this macro is more up-to-date than Autoconf -# is, so override Autoconf unconditionally. +# This definition is copied from post-2.70 Autoconf and overrides the +# AC_C_RESTRICT macro from autoconf 2.60..2.70. +m4_version_prereq([2.70.1], [], [ AC_DEFUN([AC_C_RESTRICT], [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], [ac_cv_c_restrict=no - # The order here caters to the fact that C++ does not require restrict. - for ac_kw in __restrict __restrict__ _Restrict restrict; do + # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see: + # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html + # Put 'restrict' last, because C++ lacks it. + for ac_kw in __restrict__ __restrict _Restrict restrict; do AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[typedef int *int_ptr; @@ -602,7 +596,7 @@ AC_DEFUN([AC_C_RESTRICT], AH_VERBATIM([restrict], [/* Define to the equivalent of the C99 'restrict' keyword, or to nothing if this is not supported. Do not define if restrict is - supported directly. */ + supported only directly. */ #undef restrict /* Work around a bug in older versions of Sun C++, which did not #define __restrict__ or support _Restrict or __restrict__ @@ -620,6 +614,7 @@ AC_DEFUN([AC_C_RESTRICT], *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; esac ])# AC_C_RESTRICT +]) # gl_BIGENDIAN # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd. @@ -630,13 +625,20 @@ AC_DEFUN([gl_BIGENDIAN], AC_C_BIGENDIAN ]) +# A temporary file descriptor. +# Must be less than 10, because dash 0.5.8 does not support redirections +# with multi-digit file descriptors. +m4_define([GL_TMP_FD], 9) + # gl_SILENT(command) # executes command, but without the normal configure output. +# This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.) +# inside another AC_CACHE_CHECK. AC_DEFUN([gl_SILENT], [ - { - $1 - } AS_MESSAGE_FD>/dev/null + exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null + $1 + exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&- ]) # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) @@ -646,10 +648,9 @@ AC_DEFUN([gl_SILENT], # by an AC_MSG_CHECKING/AC_MSG_RESULT pair. AC_DEFUN([gl_CACHE_VAL_SILENT], [ - saved_as_echo_n="$as_echo_n" - as_echo_n=':' - AC_CACHE_VAL([$1], [$2]) - as_echo_n="$saved_as_echo_n" + gl_SILENT([ + AC_CACHE_VAL([$1], [$2]) + ]) ]) dnl Expands to some code for use in .c programs that, on native Windows, defines diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index d2fdbd82e73..beb9817d266 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -94,6 +94,7 @@ AC_DEFUN([gl_EARLY], # Code from module fpending: # Code from module fpieee: AC_REQUIRE([gl_FP_IEEE]) + # Code from module free-posix: # Code from module fstatat: # Code from module fsusage: # Code from module fsync: @@ -109,6 +110,7 @@ AC_DEFUN([gl_EARLY], # Code from module gettimeofday: # Code from module gitlog-to-changelog: # Code from module group-member: + # Code from module idx: # Code from module ieee754-h: # Code from module ignore-value: # Code from module include_next: @@ -121,7 +123,6 @@ AC_DEFUN([gl_EARLY], # Code from module libgmp: # Code from module limits-h: # Code from module lstat: - # Code from module malloca: # Code from module manywarnings: # Code from module memmem-simple: # Code from module mempcpy: @@ -140,10 +141,12 @@ AC_DEFUN([gl_EARLY], # Code from module pselect: # Code from module pthread_sigmask: # Code from module qcopy-acl: + # Code from module rawmemchr: # Code from module readlink: # Code from module readlinkat: # Code from module regex: # Code from module root-uid: + # Code from module scratch_buffer: # Code from module sig2str: # Code from module sigdescr_np: # Code from module signal-h: @@ -508,16 +511,19 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_cloexec=false gl_gnulib_enabled_dirfd=false gl_gnulib_enabled_euidaccess=false + gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955=false gl_gnulib_enabled_getdtablesize=false gl_gnulib_enabled_getgroups=false gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false + gl_gnulib_enabled_idx=false gl_gnulib_enabled_lchmod=false - gl_gnulib_enabled_malloca=false gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false gl_gnulib_enabled_open=false gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false + gl_gnulib_enabled_rawmemchr=false gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false + gl_gnulib_enabled_scratch_buffer=false gl_gnulib_enabled_strtoll=false gl_gnulib_enabled_utimens=false gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false @@ -567,6 +573,18 @@ AC_DEFUN([gl_INIT], func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c fi } + func_gl_gnulib_m4code_ef07dc4b3077c11ea9cef586db4e5955 () + { + if ! $gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955; then + gl_FUNC_FREE + if test $REPLACE_FREE = 1; then + AC_LIBOBJ([free]) + gl_PREREQ_FREE + fi + gl_STDLIB_MODULE_INDICATOR([free-posix]) + gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955=true + fi + } func_gl_gnulib_m4code_getdtablesize () { if ! $gl_gnulib_enabled_getdtablesize; then @@ -616,6 +634,12 @@ AC_DEFUN([gl_INIT], fi fi } + func_gl_gnulib_m4code_idx () + { + if ! $gl_gnulib_enabled_idx; then + gl_gnulib_enabled_idx=true + fi + } func_gl_gnulib_m4code_lchmod () { if ! $gl_gnulib_enabled_lchmod; then @@ -628,14 +652,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_lchmod=true fi } - func_gl_gnulib_m4code_malloca () - { - if ! $gl_gnulib_enabled_malloca; then - gl_MALLOCA - gl_gnulib_enabled_malloca=true - func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec - fi - } func_gl_gnulib_m4code_5264294aa0a5557541b53c8c741f7f31 () { if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then @@ -668,12 +684,30 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true fi } + func_gl_gnulib_m4code_rawmemchr () + { + if ! $gl_gnulib_enabled_rawmemchr; then + gl_FUNC_RAWMEMCHR + if test $HAVE_RAWMEMCHR = 0; then + AC_LIBOBJ([rawmemchr]) + gl_PREREQ_RAWMEMCHR + fi + gl_STRING_MODULE_INDICATOR([rawmemchr]) + gl_gnulib_enabled_rawmemchr=true + fi + } func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c () { if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=true fi } + func_gl_gnulib_m4code_scratch_buffer () + { + if ! $gl_gnulib_enabled_scratch_buffer; then + gl_gnulib_enabled_scratch_buffer=true + fi + } func_gl_gnulib_m4code_strtoll () { if ! $gl_gnulib_enabled_strtoll; then @@ -700,7 +734,16 @@ AC_DEFUN([gl_INIT], fi } if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then - func_gl_gnulib_m4code_malloca + func_gl_gnulib_m4code_ef07dc4b3077c11ea9cef586db4e5955 + fi + if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then + func_gl_gnulib_m4code_idx + fi + if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then + func_gl_gnulib_m4code_rawmemchr + fi + if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then + func_gl_gnulib_m4code_scratch_buffer fi if test $HAVE_FACCESSAT = 0 || test $REPLACE_FACCESSAT = 1; then func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b @@ -747,15 +790,18 @@ AC_DEFUN([gl_INIT], if case $host_os in mingw*) false;; *) test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1;; esac; then func_gl_gnulib_m4code_open fi - if test $HAVE_READLINKAT = 0; then + if test $HAVE_READLINKAT = 0 || test $REPLACE_READLINKAT = 1; then func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b fi - if test $HAVE_READLINKAT = 0; then + if test $HAVE_READLINKAT = 0 || test $REPLACE_READLINKAT = 1; then func_gl_gnulib_m4code_03e0aaad4cb89ca757653bd367a6ccb7 fi if { test $HAVE_DECL_STRTOIMAX = 0 || test $REPLACE_STRTOIMAX = 1; } && test $ac_cv_type_long_long_int = yes; then func_gl_gnulib_m4code_strtoll fi + if test $HAVE_TIMEZONE_T = 0; then + func_gl_gnulib_m4code_idx + fi if test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1; then func_gl_gnulib_m4code_5264294aa0a5557541b53c8c741f7f31 fi @@ -773,16 +819,19 @@ AC_DEFUN([gl_INIT], AM_CONDITIONAL([gl_GNULIB_ENABLED_cloexec], [$gl_gnulib_enabled_cloexec]) AM_CONDITIONAL([gl_GNULIB_ENABLED_dirfd], [$gl_gnulib_enabled_dirfd]) AM_CONDITIONAL([gl_GNULIB_ENABLED_euidaccess], [$gl_gnulib_enabled_euidaccess]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955], [$gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955]) AM_CONDITIONAL([gl_GNULIB_ENABLED_getdtablesize], [$gl_gnulib_enabled_getdtablesize]) AM_CONDITIONAL([gl_GNULIB_ENABLED_getgroups], [$gl_gnulib_enabled_getgroups]) AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36]) AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_idx], [$gl_gnulib_enabled_idx]) AM_CONDITIONAL([gl_GNULIB_ENABLED_lchmod], [$gl_gnulib_enabled_lchmod]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_malloca], [$gl_gnulib_enabled_malloca]) AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31]) AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open]) AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_rawmemchr], [$gl_gnulib_enabled_rawmemchr]) AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_scratch_buffer], [$gl_gnulib_enabled_scratch_buffer]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) AM_CONDITIONAL([gl_GNULIB_ENABLED_utimens], [$gl_gnulib_enabled_utimens]) AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) @@ -989,6 +1038,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/flexmember.h lib/fpending.c lib/fpending.h + lib/free.c lib/fstatat.c lib/fsusage.c lib/fsusage.h @@ -1015,6 +1065,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gettimeofday.c lib/gl_openssl.h lib/group-member.c + lib/idx.h lib/ieee754.in.h lib/ignore-value.h lib/intprops.h @@ -1023,8 +1074,10 @@ AC_DEFUN([gl_FILE_LIST], [ lib/libc-config.h lib/limits.in.h lib/lstat.c - lib/malloca.c - lib/malloca.h + lib/malloc/scratch_buffer.h + lib/malloc/scratch_buffer_grow.c + lib/malloc/scratch_buffer_grow_preserve.c + lib/malloc/scratch_buffer_set_array_size.c lib/md5.c lib/md5.h lib/memmem.c @@ -1047,6 +1100,8 @@ AC_DEFUN([gl_FILE_LIST], [ lib/pselect.c lib/pthread_sigmask.c lib/qcopy-acl.c + lib/rawmemchr.c + lib/rawmemchr.valgrind lib/readlink.c lib/readlinkat.c lib/regcomp.c @@ -1056,6 +1111,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/regex_internal.h lib/regexec.c lib/root-uid.h + lib/scratch_buffer.h lib/set-permissions.c lib/sha1.c lib/sha1.h @@ -1145,6 +1201,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/flexmember.m4 m4/fpending.m4 m4/fpieee.m4 + m4/free.m4 m4/fstatat.m4 m4/fsusage.m4 m4/fsync.m4 @@ -1168,7 +1225,6 @@ AC_DEFUN([gl_FILE_LIST], [ m4/libgmp.m4 m4/limits-h.m4 m4/lstat.m4 - m4/malloca.m4 m4/manywarnings-c++.m4 m4/manywarnings.m4 m4/mbstate_t.m4 @@ -1192,6 +1248,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/pipe2.m4 m4/pselect.m4 m4/pthread_sigmask.m4 + m4/rawmemchr.m4 m4/readlink.m4 m4/readlinkat.m4 m4/regex.m4 @@ -1203,7 +1260,6 @@ AC_DEFUN([gl_FILE_LIST], [ m4/signal_h.m4 m4/socklen.m4 m4/ssize_t.m4 - m4/st_dm_mode.m4 m4/stat-time.m4 m4/std-gnu11.m4 m4/stdalign.m4 diff --git a/m4/largefile.m4 b/m4/largefile.m4 index f4c5d3a5cea..c4cc835bea0 100644 --- a/m4/largefile.m4 +++ b/m4/largefile.m4 @@ -25,7 +25,7 @@ AC_DEFUN([gl_SET_LARGEFILE_SOURCE], # The following implementation works around a problem in autoconf <= 2.69; # AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, # or configures them incorrectly in some cases. -m4_version_prereq([2.70], [] ,[ +m4_version_prereq([2.70], [], [ # _AC_SYS_LARGEFILE_TEST_INCLUDES # ------------------------------- diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4 index 057ce12ebe6..226f1228dde 100644 --- a/m4/mbstate_t.m4 +++ b/m4/mbstate_t.m4 @@ -1,4 +1,4 @@ -# mbstate_t.m4 serial 13 +# mbstate_t.m4 serial 14 dnl Copyright (C) 2000-2002, 2008-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -20,14 +20,7 @@ AC_DEFUN([AC_TYPE_MBSTATE_T], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [AC_INCLUDES_DEFAULT[ -/* Tru64 with Desktop Toolkit C has a bug: must be included before - . - BSD/OS 4.0.1 has a bug: , and must be - included before . */ -#include -#include -#include -#include ]], + #include ]], [[mbstate_t x; return sizeof x;]])], [ac_cv_type_mbstate_t=yes], [ac_cv_type_mbstate_t=no])]) diff --git a/m4/pid_t.m4 b/m4/pid_t.m4 new file mode 100644 index 00000000000..c7abceeecba --- /dev/null +++ b/m4/pid_t.m4 @@ -0,0 +1,38 @@ +# pid_t.m4 serial 4 +dnl Copyright (C) 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# The following implementation works around a problem in autoconf <= 2.69. +m4_version_prereq([2.70], [], [ + +dnl Define pid_t if the headers don't define it. +AC_DEFUN([AC_TYPE_PID_T], +[ + AC_CHECK_TYPE([pid_t], + [], + [dnl On 64-bit native Windows, define it to the equivalent of 'intptr_t' + dnl (= 'long long' = '__int64'), because that is the return type + dnl of the _spawnv* functions + dnl + dnl and the argument type of the _cwait function + dnl . + dnl Otherwise (on 32-bit Windows and on old Unix platforms), define it + dnl to 'int'. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #if defined _WIN64 && !defined __CYGWIN__ + LLP64 + #endif + ]]) + ], + [gl_pid_type='int'], + [gl_pid_type='__int64']) + AC_DEFINE_UNQUOTED([pid_t], [$gl_pid_type], + [Define as a signed integer type capable of holding a process identifier.]) + ], + [AC_INCLUDES_DEFAULT]) +]) + +])# m4_version_prereq 2.70 diff --git a/m4/rawmemchr.m4 b/m4/rawmemchr.m4 new file mode 100644 index 00000000000..c5bf04189c6 --- /dev/null +++ b/m4/rawmemchr.m4 @@ -0,0 +1,20 @@ +# rawmemchr.m4 serial 2 +dnl Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_RAWMEMCHR], +[ + dnl Persuade glibc to declare rawmemchr(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([rawmemchr]) + if test $ac_cv_func_rawmemchr = no; then + HAVE_RAWMEMCHR=0 + fi +]) + +# Prerequisites of lib/strchrnul.c. +AC_DEFUN([gl_PREREQ_RAWMEMCHR], [:]) diff --git a/m4/readlink.m4 b/m4/readlink.m4 index 9aa9e46da8c..c7f436a3125 100644 --- a/m4/readlink.m4 +++ b/m4/readlink.m4 @@ -1,4 +1,4 @@ -# readlink.m4 serial 15 +# readlink.m4 serial 16 dnl Copyright (C) 2003, 2007, 2009-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -23,7 +23,7 @@ AC_DEFUN([gl_FUNC_READLINK], dnl Solaris 9 ignores trailing slash. dnl FreeBSD 7.2 dereferences only one level of links with trailing slash. AC_CACHE_CHECK([whether readlink handles trailing slash correctly], - [gl_cv_func_readlink_works], + [gl_cv_func_readlink_trailing_slash], [# We have readlink, so assume ln -s works. ln -s conftest.no-such conftest.link ln -s conftest.link conftest.lnk2 @@ -32,18 +32,22 @@ AC_DEFUN([gl_FUNC_READLINK], [[#include ]], [[char buf[20]; return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])], - [gl_cv_func_readlink_works=yes], [gl_cv_func_readlink_works=no], + [gl_cv_func_readlink_trailing_slash=yes], + [gl_cv_func_readlink_trailing_slash=no], [case "$host_os" in - # Guess yes on Linux systems. - linux-* | linux) gl_cv_func_readlink_works="guessing yes" ;; - # Guess yes on glibc systems. - *-gnu* | gnu*) gl_cv_func_readlink_works="guessing yes" ;; - # If we don't know, obey --enable-cross-guesses. - *) gl_cv_func_readlink_works="$gl_cross_guess_normal" ;; + # Guess yes on Linux or glibc systems. + linux-* | linux | *-gnu* | gnu*) + gl_cv_func_readlink_trailing_slash="guessing yes" ;; + # Guess no on AIX or HP-UX. + aix* | hpux*) + gl_cv_func_readlink_trailing_slash="guessing no" ;; + # If we don't know, obey --enable-cross-guesses. + *) + gl_cv_func_readlink_trailing_slash="$gl_cross_guess_normal" ;; esac ]) rm -f conftest.link conftest.lnk2]) - case "$gl_cv_func_readlink_works" in + case "$gl_cv_func_readlink_trailing_slash" in *yes) if test "$gl_cv_decl_readlink_works" != yes; then REPLACE_READLINK=1 @@ -55,6 +59,43 @@ AC_DEFUN([gl_FUNC_READLINK], REPLACE_READLINK=1 ;; esac + + AC_CACHE_CHECK([whether readlink truncates results correctly], + [gl_cv_func_readlink_truncate], + [# We have readlink, so assume ln -s works. + ln -s ab conftest.link + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include +]], [[char c; + return readlink ("conftest.link", &c, 1) != 1;]])], + [gl_cv_func_readlink_truncate=yes], + [gl_cv_func_readlink_truncate=no], + [case "$host_os" in + # Guess yes on Linux or glibc systems. + linux-* | linux | *-gnu* | gnu*) + gl_cv_func_readlink_truncate="guessing yes" ;; + # Guess no on AIX or HP-UX. + aix* | hpux*) + gl_cv_func_readlink_truncate="guessing no" ;; + # If we don't know, obey --enable-cross-guesses. + *) + gl_cv_func_readlink_truncate="$gl_cross_guess_normal" ;; + esac + ]) + rm -f conftest.link conftest.lnk2]) + case $gl_cv_func_readlink_truncate in + *yes) + if test "$gl_cv_decl_readlink_works" != yes; then + REPLACE_READLINK=1 + fi + ;; + *) + AC_DEFINE([READLINK_TRUNCATE_BUG], [1], [Define to 1 if readlink + sets errno instead of truncating a too-long link.]) + REPLACE_READLINK=1 + ;; + esac fi ]) diff --git a/m4/readlinkat.m4 b/m4/readlinkat.m4 index 6ef1f590c06..73e343f746d 100644 --- a/m4/readlinkat.m4 +++ b/m4/readlinkat.m4 @@ -1,4 +1,4 @@ -# serial 5 +# serial 6 # See if we need to provide readlinkat replacement. dnl Copyright (C) 2009-2020 Free Software Foundation, Inc. @@ -26,13 +26,10 @@ AC_DEFUN([gl_FUNC_READLINKAT], ssize_t readlinkat (int, char const *, char *, size_t);]])], [gl_cv_decl_readlinkat_works=yes], [gl_cv_decl_readlinkat_works=no])]) - # Assume readinkat has the same trailing slash bug as readlink, - # as is the case on Mac Os X 10.10 - case "$gl_cv_func_readlink_works" in - *yes) - if test "$gl_cv_decl_readlinkat_works" != yes; then - REPLACE_READLINKAT=1 - fi + # Assume readlinkat has the same bugs as readlink, + # as is the case on OS X 10.10 with trailing slashes. + case $gl_cv_decl_readlinkat_works,$gl_cv_func_readlink_trailing_slash,$gl_cv_func_readlink_truncate in + *yes,*yes,*yes) ;; *) REPLACE_READLINKAT=1 diff --git a/m4/std-gnu11.m4 b/m4/std-gnu11.m4 index db833d820f3..b5ab8abed02 100644 --- a/m4/std-gnu11.m4 +++ b/m4/std-gnu11.m4 @@ -6,6 +6,8 @@ # This implementation will be obsolete once we can assume Autoconf 2.70 # or later is installed everywhere a Gnulib program might be developed. +m4_version_prereq([2.70], [], [ + # Copyright (C) 2001-2020 Free Software Foundation, Inc. @@ -822,3 +824,6 @@ dnl Tru64 N/A (no support) dnl with extended modes being tried first. [[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl ])# _AC_PROG_CXX_CXX11 + + +])# m4_version_prereq diff --git a/m4/stdint.m4 b/m4/stdint.m4 index d5f5d6133a9..adaea3e5826 100644 --- a/m4/stdint.m4 +++ b/m4/stdint.m4 @@ -1,4 +1,4 @@ -# stdint.m4 serial 56 +# stdint.m4 serial 58 dnl Copyright (C) 2001-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,7 +34,7 @@ AC_DEFUN_ONCE([gl_STDINT_H], AC_SUBST([HAVE_WCHAR_H]) dnl Check for . - dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. + AC_CHECK_HEADERS_ONCE([inttypes.h]) if test $ac_cv_header_inttypes_h = yes; then HAVE_INTTYPES_H=1 else @@ -43,7 +43,7 @@ AC_DEFUN_ONCE([gl_STDINT_H], AC_SUBST([HAVE_INTTYPES_H]) dnl Check for . - dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. + AC_CHECK_HEADERS_ONCE([sys/types.h]) if test $ac_cv_header_sys_types_h = yes; then HAVE_SYS_TYPES_H=1 else @@ -493,13 +493,9 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], dnl gl_STDINT_INCLUDES AC_DEFUN([gl_STDINT_INCLUDES], [[ - /* BSD/OS 4.0.1 has a bug: , and must be - included before . */ #include #include #if HAVE_WCHAR_H - # include - # include # include #endif ]]) diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 5f968bc26a5..6003a31b382 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -1,4 +1,4 @@ -# stdio_h.m4 serial 50 +# stdio_h.m4 serial 51 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -109,6 +109,11 @@ AC_DEFUN([gl_STDIO_H], renameat snprintf tmpfile vdprintf vsnprintf]) AC_REQUIRE([AC_C_RESTRICT]) + + AC_CHECK_DECLS_ONCE([fcloseall]) + if test $ac_cv_have_decl_fcloseall = no; then + HAVE_DECL_FCLOSEALL=0 + fi ]) AC_DEFUN([gl_STDIO_MODULE_INDICATOR], @@ -176,6 +181,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF]) GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX]) dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL]) HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE]) HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO]) HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 743066a6336..7e03b9a6d58 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 49 +# stdlib_h.m4 serial 54 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -22,13 +22,28 @@ AC_DEFUN([gl_STDLIB_H], #if HAVE_RANDOM_H # include #endif - ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt + ]], [_Exit aligned_alloc atoll canonicalize_file_name free + getloadavg getsubopt grantpt initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps - posix_openpt ptsname ptsname_r qsort_r random random_r reallocarray - realpath rpmatch secure_getenv setenv setstate setstate_r srandom - srandom_r strtod strtold strtoll strtoull unlockpt unsetenv]) + posix_memalign posix_openpt ptsname ptsname_r qsort_r + random random_r reallocarray realpath rpmatch secure_getenv setenv + setstate setstate_r srandom srandom_r + strtod strtold strtoll strtoull unlockpt unsetenv]) AC_REQUIRE([AC_C_RESTRICT]) + + AC_CHECK_DECLS_ONCE([ecvt]) + if test $ac_cv_have_decl_ecvt = no; then + HAVE_DECL_ECVT=0 + fi + AC_CHECK_DECLS_ONCE([fcvt]) + if test $ac_cv_have_decl_fcvt = no; then + HAVE_DECL_FCVT=0 + fi + AC_CHECK_DECLS_ONCE([gcvt]) + if test $ac_cv_have_decl_gcvt = no; then + HAVE_DECL_GCVT=0 + fi ]) AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], @@ -43,9 +58,11 @@ AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], AC_DEFUN([gl_STDLIB_H_DEFAULTS], [ GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT]) + GNULIB_ALIGNED_ALLOC=0; AC_SUBST([GNULIB_ALIGNED_ALLOC]) GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL]) GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX]) GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME]) + GNULIB_FREE_POSIX=0; AC_SUBST([GNULIB_FREE_POSIX]) GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG]) GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT]) @@ -56,6 +73,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS]) GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS]) + GNULIB_POSIX_MEMALIGN=0;AC_SUBST([GNULIB_POSIX_MEMALIGN]) GNULIB_POSIX_OPENPT=0; AC_SUBST([GNULIB_POSIX_OPENPT]) GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME]) GNULIB_PTSNAME_R=0; AC_SUBST([GNULIB_PTSNAME_R]) @@ -79,8 +97,12 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_WCTOMB=0; AC_SUBST([GNULIB_WCTOMB]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE__EXIT=1; AC_SUBST([HAVE__EXIT]) + HAVE_ALIGNED_ALLOC=1; AC_SUBST([HAVE_ALIGNED_ALLOC]) HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) + HAVE_DECL_ECVT=1; AC_SUBST([HAVE_DECL_ECVT]) + HAVE_DECL_FCVT=1; AC_SUBST([HAVE_DECL_FCVT]) + HAVE_DECL_GCVT=1; AC_SUBST([HAVE_DECL_GCVT]) HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) @@ -92,6 +114,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP]) HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) + HAVE_POSIX_MEMALIGN=1; AC_SUBST([HAVE_POSIX_MEMALIGN]) HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT]) HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R]) @@ -115,12 +138,15 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV]) + REPLACE_ALIGNED_ALLOC=0; AC_SUBST([REPLACE_ALIGNED_ALLOC]) REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC]) REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) + REPLACE_FREE=0; AC_SUBST([REPLACE_FREE]) REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE]) REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) + REPLACE_POSIX_MEMALIGN=0; AC_SUBST([REPLACE_POSIX_MEMALIGN]) REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME]) REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) diff --git a/m4/sys_types_h.m4 b/m4/sys_types_h.m4 index be918dc0d8b..c3a691becdf 100644 --- a/m4/sys_types_h.m4 +++ b/m4/sys_types_h.m4 @@ -1,4 +1,4 @@ -# sys_types_h.m4 serial 9 +# sys_types_h.m4 serial 11 dnl Copyright (C) 2011-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -36,25 +36,23 @@ AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS], # This works around a buggy version in autoconf <= 2.69. # See +# The 2.70 version isn't quoted properly, so override it too. -m4_version_prereq([2.70], [], [ - -# This is taken from the following Autoconf patch: -# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=e17a30e987d7ee695fb4294a82d987ec3dc9b974 +m4_version_prereq([2.70.1], [], [ m4_undefine([AC_HEADER_MAJOR]) AC_DEFUN([AC_HEADER_MAJOR], [AC_CHECK_HEADERS_ONCE([sys/types.h]) AC_CHECK_HEADER([sys/mkdev.h], - [AC_DEFINE([MAJOR_IN_MKDEV], [1], - [Define to 1 if `major', `minor', and `makedev' are declared in - .])]) + [AC_DEFINE([MAJOR_IN_MKDEV], [1], + [Define to 1 if `major', `minor', and `makedev' are + declared in .])]) if test $ac_cv_header_sys_mkdev_h = no; then AC_CHECK_HEADER([sys/sysmacros.h], - [AC_DEFINE([MAJOR_IN_SYSMACROS], [1], - [Define to 1 if `major', `minor', and `makedev' are declared in - .])]) + [AC_DEFINE([MAJOR_IN_SYSMACROS], [1], + [Define to 1 if `major', `minor', and `makedev' + are declared in .])]) fi -]) +])# AC_HEADER_MAJOR ]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index b4734daf603..b26d2c88dde 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 81 +# unistd_h.m4 serial 83 dnl Copyright (C) 2006-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -41,7 +41,8 @@ AC_DEFUN([gl_UNISTD_H], # include # endif #endif - ]], [access chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir + ]], [access chdir chown copy_file_range dup dup2 dup3 environ euidaccess + faccessat fchdir fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize getentropy getgroups gethostname getlogin getlogin_r getpagesize getpass getusershell setusershell endusershell @@ -50,6 +51,11 @@ AC_DEFUN([gl_UNISTD_H], truncate ttyname_r unlink unlinkat usleep]) AC_REQUIRE([AC_C_RESTRICT]) + + AC_CHECK_DECLS_ONCE([execvpe]) + if test $ac_cv_have_decl_execvpe = no; then + HAVE_DECL_EXECVPE=0 + fi ]) AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], @@ -152,6 +158,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) + HAVE_DECL_EXECVPE=1; AC_SUBST([HAVE_DECL_EXECVPE]) HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR]) HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC]) HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME]) diff --git a/m4/vararrays.m4 b/m4/vararrays.m4 index 49ded2efe0d..9524a6ddd33 100644 --- a/m4/vararrays.m4 +++ b/m4/vararrays.m4 @@ -1,6 +1,6 @@ # Check for variable-length arrays. -# serial 5 +# serial 6 # From Paul Eggert @@ -9,9 +9,11 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# This is a copy of AC_C_VARARRAYS from a recent development version -# of Autoconf. It replaces Autoconf's version, or for pre-2.61 autoconf -# it defines the macro that Autoconf lacks. +m4_version_prereq([2.70], [], [ + +# AC_C_VARARRAYS +# -------------- +# Check whether the C compiler supports variable-length arrays. AC_DEFUN([AC_C_VARARRAYS], [ AC_CACHE_CHECK([for variable-length arrays], @@ -27,7 +29,7 @@ AC_DEFUN([AC_C_VARARRAYS], [[/* Test for VLA support. This test is partly inspired from examples in the C standard. Use at least two VLA functions to detect the GCC 3.4.3 bug described in: - https://lists.gnu.org/r/bug-gnulib/2014-08/msg00014.html + https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html */ #ifdef __STDC_NO_VLA__ syntax error; @@ -66,3 +68,5 @@ AC_DEFUN([AC_C_VARARRAYS], if the compiler does not already define this.]) fi ]) + +]) -- cgit v1.2.1 From 527cc64e5d7e8945dfb89bf44d5f4141bd221456 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 24 Dec 2020 17:58:51 +0200 Subject: Unbreak the MinGW build broken by recent changes in callproc.c * src/w32.h (set_process_dir): * src/w32proc.c (set_process_dir): Change the argument to 'const char *'. * src/lisp.h (make_environment_block): * src/callproc.c (make_environment_block): Now returns 'char **'. (exec_failed) [DOS_NT]: Remove unused function. * src/callproc.c (child_setup): NEW_ARGV and ENV are now 'char **'. Making them 'const' breaks the MinGW build and is not needed for other platforms. * src/callproc.c (emacs_spawn): ARGV and ENVP arguments are now 'char *', for the same reason. * src/process.c (create_process): Adapt to above changes. --- src/callproc.c | 71 +++++++++++++++++++++++++--------------------------------- src/lisp.h | 6 ++--- src/process.c | 2 +- src/w32.h | 2 +- src/w32proc.c | 4 ++-- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index 8603382f0c3..e9502d2c4e8 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -107,8 +107,8 @@ static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int, ptrdiff_t); # define CHILD_SETUP_TYPE _Noreturn void #endif -static CHILD_SETUP_TYPE child_setup (int, int, int, char *const *, - char *const *, const char *); +static CHILD_SETUP_TYPE child_setup (int, int, int, char **, char **, + const char *); /* Return the current buffer's working directory, or the home directory if it's unreachable, as a string suitable for a system call. @@ -549,7 +549,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, callproc_fd[CALLPROC_STDERR] = fd_error; } - char *const *env = make_environment_block (current_dir); + char **env = make_environment_block (current_dir); #ifdef MSDOS /* MW, July 1993 */ status = child_setup (filefd, fd_output, fd_error, new_argv, env, @@ -1132,16 +1132,6 @@ exec_failed (char const *name, int err) _exit (err == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); } -#else - -/* Do nothing. There is no need to fail, as DOS_NT platforms do not - fork and exec, and handle alloca exhaustion in a different way. */ - -static void -exec_failed (char const *name, int err) -{ -} - #endif /* This is the last thing run in a newly forked inferior @@ -1160,8 +1150,8 @@ exec_failed (char const *name, int err) On MS-DOS, either return an exit status or signal an error. */ static CHILD_SETUP_TYPE -child_setup (int in, int out, int err, char *const *new_argv, - char *const *env, const char *current_dir) +child_setup (int in, int out, int err, char **new_argv, char **env, + const char *current_dir) { #ifdef WINDOWSNT int cpid; @@ -1235,9 +1225,8 @@ child_setup (int in, int out, int err, char *const *new_argv, NULL, don't perform any terminal setup. */ int -emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, - char *const *argv, char *const *envp, const char *cwd, - const char *pty) +emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, + char **argv, char **envp, const char *cwd, const char *pty) { sigset_t oldset; int pid; @@ -1251,9 +1240,9 @@ emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, const char *volatile cwd_volatile = cwd; const char *volatile pty_volatile = pty; char *const *volatile argv_volatile = argv; - int volatile stdin_volatile = stdin; - int volatile stdout_volatile = stdout; - int volatile stderr_volatile = stderr; + int volatile stdin_volatile = std_in; + int volatile stdout_volatile = std_out; + int volatile stderr_volatile = std_err; char *const *volatile envp_volatile = envp; #ifdef DARWIN_OS @@ -1272,9 +1261,9 @@ emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, cwd = cwd_volatile; pty = pty_volatile; argv = argv_volatile; - stdin = stdin_volatile; - stdout = stdout_volatile; - stderr = stderr_volatile; + std_in = stdin_volatile; + std_out = stdout_volatile; + std_err = stderr_volatile; envp = envp_volatile; if (pid == 0) @@ -1286,30 +1275,30 @@ emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, dissociate_controlling_tty (); /* Make the pty's terminal the controlling terminal. */ - if (pty_flag && stdin >= 0) + if (pty_flag && std_in >= 0) { #ifdef TIOCSCTTY /* We ignore the return value because faith@cs.unc.edu says that is necessary on Linux. */ - ioctl (stdin, TIOCSCTTY, 0); + ioctl (std_in, TIOCSCTTY, 0); #endif } #if defined (LDISC1) - if (pty_flag && stdin >= 0) + if (pty_flag && std_in >= 0) { struct termios t; - tcgetattr (stdin, &t); + tcgetattr (std_in, &t); t.c_lflag = LDISC1; - if (tcsetattr (stdin, TCSANOW, &t) < 0) + if (tcsetattr (std_in, TCSANOW, &t) < 0) emacs_perror ("create_process/tcsetattr LDISC1"); } #else #if defined (NTTYDISC) && defined (TIOCSETD) - if (pty_flag && stdin >= 0) + if (pty_flag && std_in >= 0) { /* Use new line discipline. */ int ldisc = NTTYDISC; - ioctl (stdin, TIOCSETD, &ldisc); + ioctl (std_in, TIOCSETD, &ldisc); } #endif #endif @@ -1327,11 +1316,11 @@ emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, /* I wonder if emacs_close (emacs_open (pty, ...)) would work? */ - if (stdin >= 0) - emacs_close (stdin); - stdout = stdin = emacs_open (pty, O_RDWR, 0); + if (std_in >= 0) + emacs_close (std_in); + std_out = std_in = emacs_open (pty, O_RDWR, 0); - if (stdin < 0) + if (std_in < 0) { emacs_perror (pty); _exit (EXIT_CANCELED); @@ -1373,14 +1362,14 @@ emacs_spawn (pid_t *newpid, int stdin, int stdout, int stderr, unblock_child_signal (&oldset); if (pty_flag) - child_setup_tty (stdout); + child_setup_tty (std_out); - if (stderr < 0) - stderr = stdout; + if (std_err < 0) + std_err = std_out; #ifdef WINDOWSNT - pid = child_setup (stdin, stdout, stderr, argv, envp, cwd); + pid = child_setup (std_in, std_out, std_err, argv, envp, cwd); #else /* not WINDOWSNT */ - child_setup (stdin, stdout, stderr, argv, envp, cwd); + child_setup (std_in, std_out, std_err, argv, envp, cwd); #endif /* not WINDOWSNT */ } @@ -1531,7 +1520,7 @@ egetenv_internal (const char *var, ptrdiff_t len) objects. Don't call any Lisp code or the garbage collector while the block is active. */ -char *const * +char ** make_environment_block (Lisp_Object current_dir) { char **env; diff --git a/src/lisp.h b/src/lisp.h index c7188b171f8..501bcd14a6f 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4498,9 +4498,9 @@ extern void setup_process_coding_systems (Lisp_Object); # define CHILD_SETUP_ERROR_DESC "Doing vfork" #endif -extern int emacs_spawn (pid_t *, int, int, int, char *const *, - char *const *, const char *, const char *); -extern char *const *make_environment_block (Lisp_Object); +extern int emacs_spawn (pid_t *, int, int, int, char **, char **, const char *, + const char *); +extern char **make_environment_block (Lisp_Object); extern void init_callproc_1 (void); extern void init_callproc (void); extern void set_initial_environment (void); diff --git a/src/process.c b/src/process.c index f3de9251b7a..98b575fc864 100644 --- a/src/process.c +++ b/src/process.c @@ -2127,7 +2127,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) /* This may signal an error. */ setup_process_coding_systems (process); - char *const *env = make_environment_block (current_dir); + char **env = make_environment_block (current_dir); pty_flag = p->pty_flag; eassert (pty_flag == ! NILP (lisp_pty_name)); diff --git a/src/w32.h b/src/w32.h index 1afb8ad0873..e23ea6a675d 100644 --- a/src/w32.h +++ b/src/w32.h @@ -216,7 +216,7 @@ extern int sys_rename_replace (char const *, char const *, BOOL); extern int pipe2 (int *, int); extern void register_aux_fd (int); -extern void set_process_dir (char *); +extern void set_process_dir (const char *); extern int sys_spawnve (int, char *, char **, char **); extern void register_child (pid_t, int); diff --git a/src/w32proc.c b/src/w32proc.c index 0cf82013065..66cdf7de461 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -3019,9 +3019,9 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[3]) } void -set_process_dir (char * dir) +set_process_dir (const char * dir) { - process_dir = dir; + process_dir = (char *) dir; } /* To avoid problems with winsock implementations that work over dial-up -- cgit v1.2.1 From 452baab8487d9a560a4b56a6ba2b9b1459c8ce76 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 24 Dec 2020 18:17:57 +0200 Subject: Fix the MinGW build broken by Gnulib update * nt/mingw-cfg.site (gl_cv_func_readlink_trailing_slash) (gl_cv_func_readlink_truncate): Define to "yes" to avoid compiling readlink.c. --- nt/mingw-cfg.site | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site index 4a77cc20b4e..a9ca20cb155 100644 --- a/nt/mingw-cfg.site +++ b/nt/mingw-cfg.site @@ -83,6 +83,8 @@ ac_cv_func_readlink=yes ac_cv_func_symlink=yes # Avoid run-time tests of readlink and symlink, which will fail gl_cv_func_readlink_works=yes +gl_cv_func_readlink_trailing_slash=yes +gl_cv_func_readlink_truncate=yes gl_cv_func_symlink_works=yes ac_cv_func_readlinkat=yes ac_cv_func_faccessat=yes -- cgit v1.2.1 From e3525712ee312627544bfd6d054b1defa46b660f Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 24 Dec 2020 18:32:54 +0200 Subject: ; * src/callproc.c (emacs_spawn) [!WINDOWSNT]: Fix last change. --- src/callproc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index e9502d2c4e8..3ecd6880274 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1239,11 +1239,11 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, pid_t *volatile newpid_volatile = newpid; const char *volatile cwd_volatile = cwd; const char *volatile pty_volatile = pty; - char *const *volatile argv_volatile = argv; + char **volatile argv_volatile = argv; int volatile stdin_volatile = std_in; int volatile stdout_volatile = std_out; int volatile stderr_volatile = std_err; - char *const *volatile envp_volatile = envp; + char **volatile envp_volatile = envp; #ifdef DARWIN_OS /* Darwin doesn't let us run setsid after a vfork, so use fork when -- cgit v1.2.1 From d63ccde966a561756675b9c84b39c724662c82a8 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 24 Dec 2020 18:42:27 +0100 Subject: Unbreak the build on *BSD and Macos after previous gnulib merge * lib/Makefile.in (DEPFLAGS): Unbreak build on BSD derivatives by writing all deps files into a single directory (instead of deps/malloc/*.c). --- lib/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile.in b/lib/Makefile.in index d68ec131dd3..a280b7a3311 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -67,7 +67,7 @@ endif DEPDIR = deps ifeq ($(AUTO_DEPEND),yes) - DEPFLAGS = -MMD -MF $(DEPDIR)/$*.d -MP + DEPFLAGS = -MMD -MF $(DEPDIR)/$(*F).d -MP -include $(ALLOBJS:%.o=$(DEPDIR)/%.d) else DEPFLAGS = -- cgit v1.2.1 From 269cec13a2fc6ac18b675d0dadd07a3d4e074a72 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 05:16:46 +0100 Subject: Remove `string-slice' -- it's not very well defined * doc/lispref/strings.texi (Creating Strings): Ditto. * lisp/emacs-lisp/subr-x.el (string-slice): Remove. --- doc/lispref/strings.texi | 11 ----------- etc/NEWS | 2 +- lisp/emacs-lisp/shortdoc.el | 3 --- lisp/emacs-lisp/subr-x.el | 13 ------------- test/lisp/emacs-lisp/subr-x-tests.el | 8 -------- 5 files changed, 1 insertion(+), 36 deletions(-) diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index ef848ac5107..19b91471ed3 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -381,17 +381,6 @@ The default value of @var{separators} for @code{split-string}. Its usual value is @w{@code{"[ \f\t\n\r\v]+"}}. @end defvar -@defun string-slice string regexp -Split @var{string} into a list of strings on @var{regexp} boundaries. -As opposed to @code{split-string}, the boundaries are included in the -result set: - -@example -(string-slice " two words " " +") - @result{} (" two" " words" " ") -@end example -@end defun - @defun string-clean-whitespace string Clean up the whitespace in @var{string} by collapsing stretches of whitespace to a single space character, as well as removing all diff --git a/etc/NEWS b/etc/NEWS index b155ff9d42e..3a0102238ca 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1467,7 +1467,7 @@ This can be set to nil to inhibit hiding passwords in .authinfo files. +++ *** A number of new string manipulation functions have been added. 'string-clean-whitespace', 'string-fill', 'string-limit', -'string-lines', 'string-pad', 'string-chop-newline' and 'string-slice'. +'string-lines', 'string-pad' and 'string-chop-newline'. +++ *** New variable 'current-minibuffer-command'. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 0067495fea0..618465513da 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -154,9 +154,6 @@ There can be any number of :example/:result elements." :eval (split-string "foo bar") :eval (split-string "|foo|bar|" "|") :eval (split-string "|foo|bar|" "|" t)) - (string-slice - :eval (string-slice "foo-bar" "-") - :eval (string-slice "foo-bar--zot-" "-+")) (string-lines :eval (string-lines "foo\n\nbar") :eval (string-lines "foo\n\nbar" t)) diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 7e17a3464e6..dc5840a0865 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -310,19 +310,6 @@ than this function." If OMIT-NULLS, empty lines will be removed from the results." (split-string string "\n" omit-nulls)) -(defun string-slice (string regexp) - "Split STRING at REGEXP boundaries and return a list of slices. -The boundaries that match REGEXP are included in the result. - -Also see `split-string'." - (if (zerop (length string)) - (list "") - (let ((i (string-match-p regexp string 1))) - (if i - (cons (substring string 0 i) - (string-slice (substring string i) regexp)) - (list string))))) - (defun string-pad (string length &optional padding start) "Pad STRING to LENGTH using PADDING. If PADDING is nil, the space character is used. If not nil, it diff --git a/test/lisp/emacs-lisp/subr-x-tests.el b/test/lisp/emacs-lisp/subr-x-tests.el index 3fc5f1d3ed3..2ae492ecf15 100644 --- a/test/lisp/emacs-lisp/subr-x-tests.el +++ b/test/lisp/emacs-lisp/subr-x-tests.el @@ -604,14 +604,6 @@ (should (equal (string-lines "foo") '("foo"))) (should (equal (string-lines "foo \nbar") '("foo " "bar")))) -(ert-deftest subr-string-slice () - (should (equal (string-slice "foo-bar" "-") '("foo" "-bar"))) - (should (equal (string-slice "foo-bar-" "-") '("foo" "-bar" "-"))) - (should (equal (string-slice "-foo-bar-" "-") '("-foo" "-bar" "-"))) - (should (equal (string-slice "ooo" "lala") '("ooo"))) - (should (equal (string-slice "foo bar" "\\b") '("foo" " " "bar" ""))) - (should (equal (string-slice "foo bar" "\\b\\|a") '("foo" " " "b" "ar" "")))) - (ert-deftest subr-string-pad () (should (equal (string-pad "foo" 5) "foo ")) (should (equal (string-pad "foo" 5 ?-) "foo--")) -- cgit v1.2.1 From af359de91772478587f768300ca61d64a693fedb Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 05:58:09 +0100 Subject: Allow `string-limit' to work on encoded strings * doc/lispref/strings.texi (Creating Strings): Document it. * lisp/emacs-lisp/subr-x.el (string-limit): Allow limiting on encoded strings. --- doc/lispref/strings.texi | 9 ++++++++- lisp/emacs-lisp/shortdoc.el | 3 ++- lisp/emacs-lisp/subr-x.el | 34 +++++++++++++++++++++++++++++----- test/lisp/emacs-lisp/subr-x-tests.el | 20 ++++++++++++++++++++ 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index 19b91471ed3..1e5f52ddfdd 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -394,12 +394,19 @@ there are individual words that are longer than @var{length}, these will not be shortened. @end defun -@defun string-limit string length &optional end +@defun string-limit string length &optional end coding-system If @var{string} is shorter than @var{length}, @var{string} is returned as is. Otherwise, return a substring of @var{string} consisting of the first @var{length} characters. If the optional @var{end} parameter is given, return a string of the @var{length} last characters instead. + +If @var{coding-system} is non-@code{nil}, @var{string} will be encoded +before limiting, and the result will be a unibyte string that's +shorter than @code{length}. If @var{string} contains characters that +are encoded into several bytes (for instance, when using +@code{utf-8}), the resulting unibyte string is never truncated in the +middle of a character representation. @end defun @defun string-lines string &optional omit-nulls diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 618465513da..9d183e0d4e9 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -146,7 +146,8 @@ There can be any number of :example/:result elements." (string-limit :eval (string-limit "foobar" 3) :eval (string-limit "foobar" 3 t) - :eval (string-limit "foobar" 10)) + :eval (string-limit "foobar" 10) + :eval (string-limit "fo好" 3 nil 'utf-8)) (truncate-string-to-width :eval (truncate-string-to-width "foobar" 3) :eval (truncate-string-to-width "你好bar" 5)) diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index dc5840a0865..9fbb0351af4 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -286,7 +286,7 @@ result will have lines that are longer than LENGTH." (fill-region (point-min) (point-max))) (buffer-string))) -(defun string-limit (string length &optional end) +(defun string-limit (string length &optional end coding-system) "Return (up to) a LENGTH substring of STRING. If STRING is shorter than or equal to LENGTH, the entire string is returned unchanged. @@ -295,15 +295,39 @@ If STRING is longer than LENGTH, return a substring consisting of the first LENGTH characters of STRING. If END is non-nil, return the last LENGTH characters instead. +If CODING-SYSTEM is non-nil, STRING will be encoded before +limiting, and LENGTH is interpreted as the number of bytes to +limit the string to. The result will be a unibyte string that is +shorter than LENGTH, but will not contain \"partial\" characters, +even if CODING-SYSTEM encodes characters with several bytes per +character. + When shortening strings for display purposes, `truncate-string-to-width' is almost always a better alternative than this function." (unless (natnump length) (signal 'wrong-type-argument (list 'natnump length))) - (cond - ((<= (length string) length) string) - (end (substring string (- (length string) length))) - (t (substring string 0 length)))) + (if coding-system + (let ((result nil) + (result-length 0) + (index (if end (1- (length string)) 0))) + (while (let ((encoded (encode-coding-char + (aref string index) coding-system))) + (and (<= (+ (length encoded) result-length) length) + (progn + (push encoded result) + (cl-incf result-length (length encoded)) + (setq index (if end (1- index) + (1+ index)))) + (if end (> index -1) + (< index (length string))))) + ;; No body. + ) + (apply #'concat (if end result (nreverse result)))) + (cond + ((<= (length string) length) string) + (end (substring string (- (length string) length))) + (t (substring string 0 length))))) (defun string-lines (string &optional omit-nulls) "Split STRING into a list of lines. diff --git a/test/lisp/emacs-lisp/subr-x-tests.el b/test/lisp/emacs-lisp/subr-x-tests.el index 2ae492ecf15..b17185ab0d3 100644 --- a/test/lisp/emacs-lisp/subr-x-tests.el +++ b/test/lisp/emacs-lisp/subr-x-tests.el @@ -600,6 +600,26 @@ (should (equal (string-limit "foo" 0) "")) (should-error (string-limit "foo" -1))) +(ert-deftest subr-string-limit-coding () + (should (not (multibyte-string-p (string-limit "foó" 10 nil 'utf-8)))) + (should (equal (string-limit "foó" 10 nil 'utf-8) "fo\303\263")) + (should (equal (string-limit "foó" 3 nil 'utf-8) "fo")) + (should (equal (string-limit "foó" 4 nil 'utf-8) "fo\303\263")) + (should (equal (string-limit "foóa" 4 nil 'utf-8) "fo\303\263")) + (should (equal (string-limit "foóá" 4 nil 'utf-8) "fo\303\263")) + (should (equal (string-limit "foóa" 4 nil 'iso-8859-1) "fo\363a")) + (should (equal (string-limit "foóá" 4 nil 'iso-8859-1) "fo\363\341")) + (should (equal (string-limit "foóá" 4 nil 'utf-16) "\376\377\000f")) + + (should (equal (string-limit "foó" 10 t 'utf-8) "fo\303\263")) + (should (equal (string-limit "foó" 3 t 'utf-8) "o\303\263")) + (should (equal (string-limit "foó" 4 t 'utf-8) "fo\303\263")) + (should (equal (string-limit "foóa" 4 t 'utf-8) "o\303\263a")) + (should (equal (string-limit "foóá" 4 t 'utf-8) "\303\263\303\241")) + (should (equal (string-limit "foóa" 4 t 'iso-8859-1) "fo\363a")) + (should (equal (string-limit "foóá" 4 t 'iso-8859-1) "fo\363\341")) + (should (equal (string-limit "foóá" 4 t 'utf-16) "\376\377\000\341"))) + (ert-deftest subr-string-lines () (should (equal (string-lines "foo") '("foo"))) (should (equal (string-lines "foo \nbar") '("foo " "bar")))) -- cgit v1.2.1 From 174327cefa7b2982722ed5b33248cc6adc5b31bc Mon Sep 17 00:00:00 2001 From: Thibault Polge Date: Fri, 25 Dec 2020 06:44:40 +0100 Subject: Make `remove-hook' interactive * lisp/subr.el (remove-hook): Make `remove-hook' interactive (bug#45393). --- etc/NEWS | 3 +++ lisp/subr.el | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 3a0102238ca..b65f184bc82 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1460,6 +1460,9 @@ that makes it a valid button. ** Miscellaneous +--- +*** 'remove-hook' is now an interactive command. + --- *** New user option 'authinfo-hide-elements'. This can be set to nil to inhibit hiding passwords in .authinfo files. diff --git a/lisp/subr.el b/lisp/subr.el index 9527f7120aa..725722cbee1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1742,7 +1742,32 @@ FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the list of hooks to run in HOOK, then nothing is done. See `add-hook'. The optional third argument, LOCAL, if non-nil, says to modify -the hook's buffer-local value rather than its default value." +the hook's buffer-local value rather than its default value. + +Interactively, prompt for the various arguments (skipping local +unless HOOK has both local and global functions). If multiple +functions have the same representation under `princ', the first +one will be removed." + (interactive + (let* ((hook (intern (completing-read "Hook variable: " obarray #'boundp t))) + (local + (and + (local-variable-p hook) + (symbol-value hook) + ;; No need to prompt if there's nothing global + (or (not (default-value hook)) + (y-or-n-p (format "%s has a buffer-local binding, use that? " + hook))))) + (fn-alist (mapcar + (lambda (x) (cons (with-output-to-string (prin1 x)) x)) + (if local (symbol-value hook) (default-value hook)))) + (function (alist-get (completing-read + (format "%s hook to remove: " + (if local "Buffer-local" "Global")) + fn-alist + nil t) + fn-alist nil nil 'string=))) + (list hook function local))) (or (boundp hook) (set hook nil)) (or (default-boundp hook) (set-default hook nil)) ;; Do nothing if LOCAL is t but this hook has no local binding. -- cgit v1.2.1 From 290ee3474d8c7334e12baef0f922f9622a045cd5 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Fri, 25 Dec 2020 07:02:01 +0100 Subject: cperl-mode: Correctly syntax highlight index/value array slices * lisp/progmodes/cperl-mode.el (cperl-init-faces): %array[0, 1] should use the array face, not the hash one (bug#45373). Copyright-paperwork-exempt: yes --- lisp/progmodes/cperl-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 87542ea133c..2fc2d14ee6a 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -5666,7 +5666,7 @@ indentation and initial hashes. Behaves usually outside of comment." 'cperl-hash-face 'cperl-array-face) nil) ; arrays and hashes - ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)" + ("\\(\\([$@%]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)" 1 (if (= (- (match-end 2) (match-beginning 2)) 1) (if (eq (char-after (match-beginning 3)) ?{) -- cgit v1.2.1 From e0fc939c5f1f65cfd0ef18bb0498c41ece7cef25 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 10:30:02 +0200 Subject: Add more details to the "word processor" section * etc/TODO (Emacs as word processor): Add more details based on recent discussions. --- etc/TODO | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/etc/TODO b/etc/TODO index 5c6a210f2d7..19f9f79bf42 100644 --- a/etc/TODO +++ b/etc/TODO @@ -242,6 +242,36 @@ https://lists.gnu.org/r/emacs-devel/2013-11/msg00515.html processing. That is why we added text properties and variable width fonts. However, more features are still needed to achieve this. +Specifically, a major mode with the following features and abilities +should be added to Emacs: + + . import / export MS Office documents + . import / export Open Document Format (.odt) files + . import / export RTF files + . export to a PDF file + . select a font and its size + . apply a bold / italic / underline / strikethrough effect + . superscripts / subscripts + . apply a left / center / right / justified effect + . change the font color and the background color + . pixel-level text fill, justification, and indentation (so that + variable-pitch fonts could be freely used) + . create a list + . insert and change a table + . insert a picture + . define / use / modify styles + . print preview / print, in a way that is similar to what's on screen + (e.g., wrt the place where lines wrap) + . use footnotes + . support for "track changes" markings, including those which come + from Office documents + . multiple columns + . change page headers and footers + . save all the properties and settings mentioned above with the text + to a file, so that they are restored when later visiting that file + +The existing Enriched mode can be used as a starting point. + ** Support ligatures out of the box For the list of frequently-used typographical ligatures, see -- cgit v1.2.1 From b8b17038e140fe215a76f2e899c00b9b95614886 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Dec 2020 00:27:37 -0800 Subject: Pacify gcc 10.2 -Wanalyzer-null-argument in gtkutil.c * src/gtkutil.c (xg_item_label_same_p): Simplify. Without this simplification, GCC (Ubuntu 10.2.0-13ubuntu1) -Wanalyzer-null-argument complains about use of NULL where non-null expected as argument of strcmp. --- src/gtkutil.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/gtkutil.c b/src/gtkutil.c index fafd94c0f71..807ee17fa30 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -2944,14 +2944,11 @@ xg_get_menu_item_label (GtkMenuItem *witem) static bool xg_item_label_same_p (GtkMenuItem *witem, const char *label) { - bool is_same = 0; char *utf8_label = get_utf8_string (label); const char *old_label = witem ? xg_get_menu_item_label (witem) : 0; - if (! old_label && ! utf8_label) - is_same = 1; - else if (old_label && utf8_label) - is_same = strcmp (utf8_label, old_label) == 0; + bool is_same = (!old_label == !utf8_label + && (!old_label || strcmp (utf8_label, old_label) == 0)); if (utf8_label) g_free (utf8_label); -- cgit v1.2.1 From ec8a17e938c3ef213709ea6b6b3e565333a9c508 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Dec 2020 01:38:31 -0800 Subject: Adjust to recent Gnulib changes The latest Gnulib merge brought in free-posix, which causes 'free' to preserve errno. This lets us simplify some Emacs code that calls 'free'. * admin/merge-gnulib (GNULIB_MODULES): Add free-posix. This module is pulled in by canonicalize-lgpl anyway, so we might as well rely on it. * lib-src/emacsclient.c (get_current_dir_name): Sync better with src/sysdep.c. * lib-src/etags.c (process_file_name, etags_mktmp): * lib-src/update-game-score.c (unlock_file): * src/fileio.c (file_accessible_directory_p): * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by assuming that 'free' preserves errno. * src/alloc.c (malloc_unblock_input): Preserve errno, so that xfree preserves errno. * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by using strdup instead of malloc+memcpy. No need for realloc (and the old code leaked memory anyway on failure); just use free+malloc. --- admin/merge-gnulib | 3 ++- lib-src/emacsclient.c | 39 ++++++++++++--------------------------- lib-src/etags.c | 17 +++-------------- lib-src/update-game-score.c | 4 ++-- src/alloc.c | 6 +++++- src/fileio.c | 3 --- src/sysdep.c | 26 +++++++------------------- 7 files changed, 31 insertions(+), 67 deletions(-) diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 164300e1db6..880dc5eef53 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -34,7 +34,8 @@ GNULIB_MODULES=' d-type diffseq double-slash-root dtoastr dtotimespec dup2 environ execinfo explicit_bzero faccessat fchmodat fcntl fcntl-h fdopendir - filemode filename filevercmp flexmember fpieee fstatat fsusage fsync futimens + filemode filename filevercmp flexmember fpieee + free-posix fstatat fsusage fsync futimens getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog ieee754-h ignore-value intprops largefile libgmp lstat manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 871fa7a8d3c..8d184e28177 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -251,7 +251,6 @@ get_current_dir_name (void) bufsize_max = min (bufsize_max, PATH_MAX); #endif - char *buf; struct stat dotstat, pwdstat; size_t pwdlen; /* If PWD is accurate, use it instead of calling getcwd. PWD is @@ -265,37 +264,23 @@ get_current_dir_name (void) && stat (".", &dotstat) == 0 && dotstat.st_ino == pwdstat.st_ino && dotstat.st_dev == pwdstat.st_dev) - { - buf = xmalloc (strlen (pwd) + 1); - strcpy (buf, pwd); - } + return strdup (pwd); else { - size_t buf_size = 1024; + ptrdiff_t buf_size = min (bufsize_max, 1024); for (;;) - { - int tmp_errno; - buf = malloc (buf_size); - if (! buf) - break; - if (getcwd (buf, buf_size) == buf) - break; - tmp_errno = errno; + { + char *buf = malloc (buf_size); + if (!buf) + return NULL; + if (getcwd (buf, buf_size) == buf) + return buf; free (buf); - if (tmp_errno != ERANGE) - { - errno = tmp_errno; - return NULL; - } - buf_size *= 2; - if (! buf_size) - { - errno = ENOMEM; - return NULL; - } - } + if (errno != ERANGE || buf_size == bufsize_max) + return NULL; + buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; + } } - return buf; } #endif diff --git a/lib-src/etags.c b/lib-src/etags.c index a1c6837e880..071892ee317 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -1643,19 +1643,10 @@ process_file_name (char *file, language *lang) char *cmd = concat (cmd1, "' > ", tmp_name); #endif free (cmd1); - int tmp_errno; - if (system (cmd) == -1) - { - inf = NULL; - tmp_errno = EINVAL; - } - else - { - inf = fopen (tmp_name, "r" FOPEN_BINARY); - tmp_errno = errno; - } + inf = (system (cmd) == -1 + ? NULL + : fopen (tmp_name, "r" FOPEN_BINARY)); free (cmd); - errno = tmp_errno; } if (!inf) @@ -7068,9 +7059,7 @@ etags_mktmp (void) int fd = mkostemp (templt, O_CLOEXEC); if (fd < 0 || close (fd) != 0) { - int temp_errno = errno; free (templt); - errno = temp_errno; templt = NULL; } #if defined (DOS_NT) diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 93aa0393d94..fc6e72838ea 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -499,9 +499,9 @@ unlock_file (const char *filename, void *state) char *lockpath = (char *) state; int saved_errno = errno; int ret = unlink (lockpath); - int unlink_errno = errno; + if (0 <= ret) + errno = saved_errno; free (lockpath); - errno = ret < 0 ? unlink_errno : saved_errno; return ret; } diff --git a/src/alloc.c b/src/alloc.c index adbfa1883c5..0b387dd8c1b 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -732,7 +732,11 @@ static void malloc_unblock_input (void) { if (block_input_in_memory_allocators) - unblock_input (); + { + int err = errno; + unblock_input (); + errno = err; + } } # define MALLOC_BLOCK_INPUT malloc_block_input () # define MALLOC_UNBLOCK_INPUT malloc_unblock_input () diff --git a/src/fileio.c b/src/fileio.c index 651e765fca4..23b4523c944 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3050,7 +3050,6 @@ file_accessible_directory_p (Lisp_Object file) ptrdiff_t len = SBYTES (file); char const *dir; bool ok; - int saved_errno; USE_SAFE_ALLOCA; /* Normally a file "FOO" is an accessible directory if "FOO/." exists. @@ -3075,9 +3074,7 @@ file_accessible_directory_p (Lisp_Object file) } ok = file_access_p (dir, F_OK); - saved_errno = errno; SAFE_FREE (); - errno = saved_errno; return ok; #endif /* !DOS_NT */ } diff --git a/src/sysdep.c b/src/sysdep.c index 29c88f5308e..eeb9d184940 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -314,33 +314,21 @@ get_current_dir_name_or_unreachable (void) && emacs_fstatat (AT_FDCWD, ".", &dotstat, 0) == 0 && dotstat.st_ino == pwdstat.st_ino && dotstat.st_dev == pwdstat.st_dev) - { - char *buf = malloc (pwdlen + 1); - if (!buf) - return NULL; - return memcpy (buf, pwd, pwdlen + 1); - } + return strdup (pwd); else { ptrdiff_t buf_size = min (bufsize_max, 1024); - char *buf = malloc (buf_size); - if (!buf) - return NULL; for (;;) { + char *buf = malloc (buf_size); + if (!buf) + return NULL; if (getcwd (buf, buf_size) == buf) return buf; - int getcwd_errno = errno; - if (getcwd_errno != ERANGE || buf_size == bufsize_max) - { - free (buf); - errno = getcwd_errno; - return NULL; - } + free (buf); + if (errno != ERANGE || buf_size == bufsize_max) + return NULL; buf_size = buf_size <= bufsize_max / 2 ? 2 * buf_size : bufsize_max; - buf = realloc (buf, buf_size); - if (!buf) - return NULL; } } } -- cgit v1.2.1 From 5880c7caab394eac55c44d4be42b2f45dbd9bc53 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Dec 2020 02:15:45 -0800 Subject: Adjust test_module to recent Gnulib changes * test/Makefile.in ($(test_module)): Also compile lib/free.c if it is needed to define rpl_free. --- test/Makefile.in | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Makefile.in b/test/Makefile.in index 67d203df297..b6cf6493e32 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -268,6 +268,7 @@ $(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h $(AM_V_CCLD)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \ -o $@ $< $(LIBGMP) \ $(and $(GMP_H),$(srcdir)/../lib/mini-gmp-gnulib.c) \ + $(if $(OMIT_GNULIB_MODULE_free-posix),,$(srcdir)/../lib/free.c) \ $(srcdir)/../lib/timespec.c $(srcdir)/../lib/gettime.c endif -- cgit v1.2.1 From 42d58264db165d265cba68d6dbebc53a50738355 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Dec 2020 02:33:29 -0800 Subject: Update Gnulib. All changes in this commit are autogenerated by running admin/merge-gnulib. --- build-aux/config.guess | 5 +- lib/canonicalize-lgpl.c | 213 +++++++++++++++++++++++++++++++++++------------- lib/careadlinkat.c | 12 +-- lib/eloop-threshold.h | 83 +++++++++++++++++++ lib/euidaccess.c | 9 +- lib/faccessat.c | 14 +++- lib/gnulib.mk.in | 14 +++- lib/mini-gmp.c | 58 +++++++------ lib/mini-gmp.h | 5 +- lib/symlink.c | 2 +- m4/canonicalize.m4 | 10 ++- m4/faccessat.m4 | 33 +++++++- m4/gnulib-comp.m4 | 32 ++++---- 13 files changed, 369 insertions(+), 121 deletions(-) create mode 100644 lib/eloop-threshold.h diff --git a/build-aux/config.guess b/build-aux/config.guess index 699b3a10b21..7f748177972 100755 --- a/build-aux/config.guess +++ b/build-aux/config.guess @@ -2,7 +2,7 @@ # Attempt to guess a canonical system name. # Copyright 1992-2020 Free Software Foundation, Inc. -timestamp='2020-11-19' +timestamp='2020-12-22' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -996,6 +996,9 @@ EOF k1om:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + exit ;; m32r*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 584fce1cfa4..650d510f2d0 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -36,23 +37,26 @@ #include #include +#include +#include +#include #include #ifdef _LIBC -# include # include -typedef ptrdiff_t idx_t; -# define IDX_MAX PTRDIFF_MAX -# define FILE_SYSTEM_PREFIX_LEN(name) 0 -# define IS_ABSOLUTE_FILE_NAME(name) ISSLASH(*(name)) -# define ISSLASH(c) ((c) == '/') -# define freea(p) ((void) (p)) +# include +# ifdef __ASSUME_FACCESSAT2 +# define FACCESSAT_NEVER_EOVERFLOWS __ASSUME_FACCESSAT2 +# else +# define FACCESSAT_NEVER_EOVERFLOWS true +# endif +# define GCC_LINT 1 +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) #else # define __canonicalize_file_name canonicalize_file_name # define __realpath realpath -# include "idx.h" # include "pathmax.h" -# include "filename.h" +# define __faccessat faccessat # if defined _WIN32 && !defined __CYGWIN__ # define __getcwd _getcwd # elif HAVE_GETCWD @@ -77,22 +81,95 @@ typedef ptrdiff_t idx_t; # define __pathconf pathconf # define __rawmemchr rawmemchr # define __readlink readlink -# ifndef MAXSYMLINKS -# ifdef SYMLOOP_MAX -# define MAXSYMLINKS SYMLOOP_MAX -# else -# define MAXSYMLINKS 20 -# endif -# endif -# define __eloop_threshold() MAXSYMLINKS +# define __stat stat +#endif + +/* Suppress bogus GCC -Wmaybe-uninitialized warnings. */ +#if defined GCC_LINT || defined lint +# define IF_LINT(Code) Code +#else +# define IF_LINT(Code) /* empty */ #endif #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT -# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 +# define DOUBLE_SLASH_IS_DISTINCT_ROOT false +#endif +#ifndef FACCESSAT_NEVER_EOVERFLOWS +# define FACCESSAT_NEVER_EOVERFLOWS false #endif #if !FUNC_REALPATH_WORKS || defined _LIBC +/* Return true if FILE's existence can be shown, false (setting errno) + otherwise. Follow symbolic links. */ +static bool +file_accessible (char const *file) +{ +# if defined _LIBC || HAVE_FACCESSAT + int r = __faccessat (AT_FDCWD, file, F_OK, AT_EACCESS); +# else + struct stat st; + int r = __stat (file, &st); +# endif + + return ((!FACCESSAT_NEVER_EOVERFLOWS && r < 0 && errno == EOVERFLOW) + || r == 0); +} + +/* True if concatenating END as a suffix to a file name means that the + code needs to check that the file name is that of a searchable + directory, since the canonicalize_filename_mode_stk code won't + check this later anyway when it checks an ordinary file name + component within END. END must either be empty, or start with a + slash. */ + +static bool _GL_ATTRIBUTE_PURE +suffix_requires_dir_check (char const *end) +{ + /* If END does not start with a slash, the suffix is OK. */ + while (ISSLASH (*end)) + { + /* Two or more slashes act like a single slash. */ + do + end++; + while (ISSLASH (*end)); + + switch (*end++) + { + default: return false; /* An ordinary file name component is OK. */ + case '\0': return true; /* Trailing "/" is trouble. */ + case '.': break; /* Possibly "." or "..". */ + } + /* Trailing "/.", or "/.." even if not trailing, is trouble. */ + if (!*end || (*end == '.' && (!end[1] || ISSLASH (end[1])))) + return true; + } + + return false; +} + +/* Append this to a file name to test whether it is a searchable directory. + On POSIX platforms "/" suffices, but "/./" is sometimes needed on + macOS 10.13 , and should also work on + platforms like AIX 7.2 that need at least "/.". */ + +#if defined _LIBC || defined LSTAT_FOLLOWS_SLASHED_SYMLINK +static char const dir_suffix[] = "/"; +#else +static char const dir_suffix[] = "/./"; +#endif + +/* Return true if DIR is a searchable dir, false (setting errno) otherwise. + DIREND points to the NUL byte at the end of the DIR string. + Store garbage into DIREND[0 .. strlen (dir_suffix)]. */ + +static bool +dir_check (char *dir, char *dirend) +{ + strcpy (dirend, dir_suffix); + return file_accessible (dir); +} + static idx_t get_path_max (void) { @@ -111,19 +188,27 @@ get_path_max (void) return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX; } -/* Return the canonical absolute name of file NAME. A canonical name - does not contain any ".", ".." components nor any repeated file name - separators ('/') or symlinks. All file name 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 name of the first component - that cannot be resolved. If the name can be resolved, RESOLVED - holds the same value as the value returned. */ - -char * -__realpath (const char *name, char *resolved) +/* Act like __realpath (see below), with an additional argument + rname_buf that can be used as temporary storage. + + If GCC_LINT is defined, do not inline this function with GCC 10.1 + and later, to avoid creating a pointer to the stack that GCC + -Wreturn-local-addr incorrectly complains about. See: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644 + Although the noinline attribute can hurt performance a bit, no better way + to pacify GCC is known; even an explicit #pragma does not pacify GCC. + When the GCC bug is fixed this workaround should be limited to the + broken GCC versions. */ +#if __GNUC_PREREQ (10, 1) +# if defined GCC_LINT || defined lint +__attribute__ ((__noinline__)) +# elif __OPTIMIZE__ && !__NO_INLINE__ +# define GCC_BOGUS_WRETURN_LOCAL_ADDR +# endif +#endif +static char * +realpath_stk (const char *name, char *resolved, + struct scratch_buffer *rname_buf) { char *dest; char const *start; @@ -149,8 +234,6 @@ __realpath (const char *name, char *resolved) } struct scratch_buffer extra_buffer, link_buffer; - struct scratch_buffer rname_buffer; - struct scratch_buffer *rname_buf = &rname_buffer; scratch_buffer_init (&extra_buffer); scratch_buffer_init (&link_buffer); scratch_buffer_init (rname_buf); @@ -208,7 +291,9 @@ __realpath (const char *name, char *resolved) name ends in '/'. */ idx_t startlen = end - start; - if (startlen == 1 && start[0] == '.') + if (startlen == 0) + break; + else if (startlen == 1 && start[0] == '.') /* nothing */; else if (startlen == 2 && start[0] == '.' && start[1] == '.') { @@ -226,7 +311,8 @@ __realpath (const char *name, char *resolved) if (!ISSLASH (dest[-1])) *dest++ = '/'; - while (rname + rname_buf->length - dest <= startlen) + while (rname + rname_buf->length - dest + < startlen + sizeof dir_suffix) { idx_t dest_offset = dest - rname; if (!scratch_buffer_grow_preserve (rname_buf)) @@ -238,28 +324,19 @@ __realpath (const char *name, char *resolved) dest = __mempcpy (dest, start, startlen); *dest = '\0'; - /* If STARTLEN == 0, RNAME ends in '/'; use stat rather than - readlink, because readlink might fail with EINVAL without - checking whether RNAME sans '/' is valid. */ - struct stat st; - char *buf = NULL; + char *buf; ssize_t n; - if (startlen != 0) + while (true) { - while (true) - { - buf = link_buffer.data; - idx_t bufsize = link_buffer.length; - n = __readlink (rname, buf, bufsize - 1); - if (n < bufsize - 1) - break; - if (!scratch_buffer_grow (&link_buffer)) - goto error_nomem; - } - if (n < 0) - buf = NULL; + buf = link_buffer.data; + idx_t bufsize = link_buffer.length; + n = __readlink (rname, buf, bufsize - 1); + if (n < bufsize - 1) + break; + if (!scratch_buffer_grow (&link_buffer)) + goto error_nomem; } - if (buf) + if (0 <= n) { if (++num_links > __eloop_threshold ()) { @@ -270,7 +347,7 @@ __realpath (const char *name, char *resolved) buf[n] = '\0'; char *extra_buf = extra_buffer.data; - idx_t end_idx; + idx_t end_idx IF_LINT (= 0); if (end_in_extra_buffer) end_idx = end - extra_buf; idx_t len = strlen (end); @@ -315,8 +392,8 @@ __realpath (const char *name, char *resolved) dest++; } } - else if (! (startlen == 0 - ? stat (rname, &st) == 0 || errno == EOVERFLOW + else if (! (suffix_requires_dir_check (end) + ? dir_check (rname, dest) : errno == EINVAL)) goto error; } @@ -355,6 +432,28 @@ error_nomem: char *result = realloc (rname, rname_size); return result != NULL ? result : rname; } + +/* Return the canonical absolute name of file NAME. A canonical name + does not contain any ".", ".." components nor any repeated file name + separators ('/') or symlinks. All file name 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 name of the first component + that cannot be resolved. If the name can be resolved, RESOLVED + holds the same value as the value returned. */ + +char * +__realpath (const char *name, char *resolved) +{ + #ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR + #warning "GCC might issue a bogus -Wreturn-local-addr warning here." + #warning "See ." + #endif + struct scratch_buffer rname_buffer; + return realpath_stk (name, resolved, &rname_buffer); +} libc_hidden_def (__realpath) versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); #endif /* !FUNC_REALPATH_WORKS || defined _LIBC */ diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c index 26fe84df55e..6aaa712b9be 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c @@ -55,8 +55,7 @@ enum { STACK_BUF_SIZE = 1024 }; # if defined GCC_LINT || defined lint __attribute__ ((__noinline__)) # elif __OPTIMIZE__ && !__NO_INLINE__ -# warning "GCC might issue a bogus -Wreturn-local-addr warning here." -# warning "See ." +# define GCC_BOGUS_WRETURN_LOCAL_ADDR # endif #endif static char * @@ -180,10 +179,11 @@ careadlinkat (int fd, char const *filename, /* Allocate the initial buffer on the stack. This way, in the common case of a symlink of small size, we get away with a single small malloc instead of a big malloc followed by a - shrinking realloc. - - If GCC -Wreturn-local-addr warns about this buffer, the warning - is bogus; see readlink_stk. */ + shrinking realloc. */ + #ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR + #warning "GCC might issue a bogus -Wreturn-local-addr warning here." + #warning "See ." + #endif char stack_buf[STACK_BUF_SIZE]; return readlink_stk (fd, filename, buffer, buffer_size, alloc, preadlinkat, stack_buf); diff --git a/lib/eloop-threshold.h b/lib/eloop-threshold.h new file mode 100644 index 00000000000..5953a4cc065 --- /dev/null +++ b/lib/eloop-threshold.h @@ -0,0 +1,83 @@ +/* Threshold at which to diagnose ELOOP. Generic version. + Copyright (C) 2012-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 + . */ + +#ifndef _ELOOP_THRESHOLD_H +#define _ELOOP_THRESHOLD_H 1 + +#include +#ifdef _LIBC +# include +# define _GL_ATTRIBUTE_CONST __attribute__ ((const)) +#else +# include +# include "minmax.h" +# define __sysconf sysconf +# if (!defined SYMLOOP_MAX \ + && ! (defined _SC_SYMLOOP_MAX && defined _POSIX_SYMLOOP_MAX)) +# define SYMLOOP_MAX 8 +# endif +#endif + +/* POSIX specifies SYMLOOP_MAX as the "Maximum number of symbolic + links that can be reliably traversed in the resolution of a + pathname in the absence of a loop." This makes it a minimum that + we should certainly accept. But it leaves open the possibility + that more might sometimes work--just not "reliably". + + For example, Linux implements a complex policy whereby there is a + small limit on the number of direct symlink traversals (a symlink + to a symlink to a symlink), but larger limit on the total number of + symlink traversals overall. Hence the SYMLOOP_MAX number should be + the small one, but the limit library functions enforce on users + should be the larger one. + + So, we use the larger of the reported SYMLOOP_MAX (if any) and our + own constant MIN_ELOOP_THRESHOLD, below. This constant should be + large enough that it never rules out a file name and directory tree + that the underlying system (i.e. calls to 'open' et al) would + resolve successfully. It should be small enough that actual loops + are detected without a huge number of iterations. */ + +#ifndef MIN_ELOOP_THRESHOLD +# define MIN_ELOOP_THRESHOLD 40 +#endif + +/* Return the maximum number of symlink traversals to permit + before diagnosing ELOOP. */ +static inline unsigned int _GL_ATTRIBUTE_CONST +__eloop_threshold (void) +{ +#ifdef SYMLOOP_MAX + const int symloop_max = SYMLOOP_MAX; +#else + /* The function is marked 'const' even though we use memory and + call a function, because sysconf is required to return the + same value in every call and so it must always be safe to + call __eloop_threshold exactly once and reuse the value. */ + static long int sysconf_symloop_max; + if (sysconf_symloop_max == 0) + sysconf_symloop_max = __sysconf (_SC_SYMLOOP_MAX); + const unsigned int symloop_max = (sysconf_symloop_max <= 0 + ? _POSIX_SYMLOOP_MAX + : sysconf_symloop_max); +#endif + + return MAX (symloop_max, MIN_ELOOP_THRESHOLD); +} + +#endif /* eloop-threshold.h */ diff --git a/lib/euidaccess.c b/lib/euidaccess.c index b352123ae18..a32e3366eb8 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c @@ -107,7 +107,10 @@ euidaccess (const char *file, int mode) safe. */ if (mode == F_OK) - return stat (file, &stats); + { + int result = stat (file, &stats); + return result != 0 && errno == EOVERFLOW ? 0 : result; + } else { int result; @@ -142,8 +145,8 @@ euidaccess (const char *file, int mode) /* If we are not set-uid or set-gid, access does the same. */ return access (file, mode); - if (stat (file, &stats) != 0) - return -1; + if (stat (file, &stats) == -1) + return mode == F_OK && errno == EOVERFLOW ? 0 : -1; /* The super-user can read and write any file, and execute any file that anyone can execute. */ diff --git a/lib/faccessat.c b/lib/faccessat.c index 9f6a11bf6e3..330c54a0be2 100644 --- a/lib/faccessat.c +++ b/lib/faccessat.c @@ -32,6 +32,13 @@ #include #undef _GL_INCLUDING_UNISTD_H +#ifndef FACCESSAT_NEVER_EOVERFLOWS +# define FACCESSAT_NEVER_EOVERFLOWS 0 +#endif +#ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK +# define LSTAT_FOLLOWS_SLASHED_SYMLINK 0 +#endif + #if HAVE_FACCESSAT static int orig_faccessat (int fd, char const *name, int mode, int flag) @@ -59,7 +66,12 @@ rpl_faccessat (int fd, char const *file, int mode, int flag) { int result = orig_faccessat (fd, file, mode, flag); - if (result == 0 && file[strlen (file) - 1] == '/') + if (result != 0) + { + if (!FACCESSAT_NEVER_EOVERFLOWS && mode == F_OK && errno == EOVERFLOW) + return 0; + } + else if (!LSTAT_FOLLOWS_SLASHED_SYMLINK && file[strlen (file) - 1] == '/') { struct stat st; result = fstatat (fd, file, &st, 0); diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index df533fa6740..a37f9278a31 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -103,6 +103,7 @@ # filevercmp \ # flexmember \ # fpieee \ +# free-posix \ # fstatat \ # fsusage \ # fsync \ @@ -1528,6 +1529,17 @@ EXTRA_libgnu_a_SOURCES += dup2.c endif ## end gnulib module dup2 +## begin gnulib module eloop-threshold +ifeq (,$(OMIT_GNULIB_MODULE_eloop-threshold)) + +ifneq (,$(gl_GNULIB_ENABLED_925677f0343de64b89a9f0c790b4104c)) + +endif +EXTRA_DIST += eloop-threshold.h + +endif +## end gnulib module eloop-threshold + ## begin gnulib module errno ifeq (,$(OMIT_GNULIB_MODULE_errno)) @@ -1750,9 +1762,7 @@ endif ## begin gnulib module free-posix ifeq (,$(OMIT_GNULIB_MODULE_free-posix)) -ifneq (,$(gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955)) -endif EXTRA_DIST += free.c EXTRA_libgnu_a_SOURCES += free.c diff --git a/lib/mini-gmp.c b/lib/mini-gmp.c index 2e0301b0081..d34fe525e4c 100644 --- a/lib/mini-gmp.c +++ b/lib/mini-gmp.c @@ -32,7 +32,7 @@ see https://www.gnu.org/licenses/. */ /* NOTE: All functions in this file which are not declared in mini-gmp.h are internal, and are not intended to be compatible - neither with GMP nor with future versions of mini-gmp. */ + with GMP or with future versions of mini-gmp. */ /* Much of the material copied from GMP files, including: gmp-impl.h, longlong.h, mpn/generic/add_n.c, mpn/generic/addmul_1.c, @@ -1331,29 +1331,26 @@ mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn, unsigned bits) { mp_size_t rn; - size_t j; + mp_limb_t limb; unsigned shift; - for (j = sn, rn = 0, shift = 0; j-- > 0; ) + for (limb = 0, rn = 0, shift = 0; sn-- > 0; ) { - if (shift == 0) - { - rp[rn++] = sp[j]; - shift += bits; - } - else + limb |= (mp_limb_t) sp[sn] << shift; + shift += bits; + if (shift >= GMP_LIMB_BITS) { - rp[rn-1] |= (mp_limb_t) sp[j] << shift; - shift += bits; - if (shift >= GMP_LIMB_BITS) - { - shift -= GMP_LIMB_BITS; - if (shift > 0) - rp[rn++] = (mp_limb_t) sp[j] >> (bits - shift); - } + shift -= GMP_LIMB_BITS; + rp[rn++] = limb; + /* Next line is correct also if shift == 0, + bits == 8, and mp_limb_t == unsigned char. */ + limb = (unsigned int) sp[sn] >> (bits - shift); } } - rn = mpn_normalized_size (rp, rn); + if (limb != 0) + rp[rn++] = limb; + else + rn = mpn_normalized_size (rp, rn); return rn; } @@ -2723,7 +2720,7 @@ mpz_make_odd (mpz_t r) assert (r->_mp_size > 0); /* Count trailing zeros, equivalent to mpn_scan1, because we know that there is a 1 */ - shift = mpn_common_scan (r->_mp_d[0], 0, r->_mp_d, 0, 0); + shift = mpn_scan1 (r->_mp_d, 0); mpz_tdiv_q_2exp (r, r, shift); return shift; @@ -2780,9 +2777,13 @@ mpz_gcd (mpz_t g, const mpz_t u, const mpz_t v) if (tv->_mp_size == 1) { - mp_limb_t vl = tv->_mp_d[0]; - mp_limb_t ul = mpz_tdiv_ui (tu, vl); - mpz_set_ui (g, mpn_gcd_11 (ul, vl)); + mp_limb_t *gp; + + mpz_tdiv_r (tu, tu, tv); + gp = MPZ_REALLOC (g, 1); /* gp = mpz_limbs_modify (g, 1); */ + *gp = mpn_gcd_11 (tu->_mp_d[0], tv->_mp_d[0]); + + g->_mp_size = *gp != 0; /* mpz_limbs_finish (g, 1); */ break; } mpz_sub (tu, tu, tv); @@ -2871,7 +2872,6 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v) * s0 = 0, s1 = 2^vz */ - mpz_setbit (t0, uz); mpz_tdiv_qr (t1, tu, tu, tv); mpz_mul_2exp (t1, t1, uz); @@ -2882,8 +2882,7 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v) { mp_bitcnt_t shift; shift = mpz_make_odd (tu); - mpz_mul_2exp (t0, t0, shift); - mpz_mul_2exp (s0, s0, shift); + mpz_setbit (t0, uz + shift); power += shift; for (;;) @@ -2921,6 +2920,8 @@ mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v) power += shift; } } + else + mpz_setbit (t0, uz); /* Now tv = odd part of gcd, and -s0 and t0 are corresponding cofactors. */ @@ -3604,7 +3605,8 @@ mpz_probab_prime_p (const mpz_t n, int reps) /* Find q and k, where q is odd and n = 1 + 2**k * q. */ mpz_abs (nm1, n); nm1->_mp_d[0] -= 1; - k = mpz_scan1 (nm1, 0); + /* Count trailing zeros, equivalent to mpn_scan1, because we know that there is a 1 */ + k = mpn_scan1 (nm1->_mp_d, 0); mpz_tdiv_q_2exp (q, nm1, k); /* BPSW test */ @@ -4301,7 +4303,7 @@ mpz_get_str (char *sp, int base, const mpz_t u) ret: sp[sn] = '\0'; if (osn && osn != sn + 1) - sp = gmp_realloc(sp, osn, sn + 1); + sp = (char*) gmp_realloc (sp, osn, sn + 1); return sp; } @@ -4425,6 +4427,8 @@ mpz_out_str (FILE *stream, int base, const mpz_t x) size_t len, n; str = mpz_get_str (NULL, base, x); + if (!str) + return 0; len = strlen (str); n = fwrite (str, 1, len, stream); gmp_free (str, len + 1); diff --git a/lib/mini-gmp.h b/lib/mini-gmp.h index c00568c2568..59a37e64947 100644 --- a/lib/mini-gmp.h +++ b/lib/mini-gmp.h @@ -1,6 +1,6 @@ /* mini-gmp, a minimalistic implementation of a GNU GMP subset. -Copyright 2011-2015, 2017, 2019 Free Software Foundation, Inc. +Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -295,7 +295,8 @@ int mpz_init_set_str (mpz_t, const char *, int); || defined (_MSL_STDIO_H) /* Metrowerks */ \ || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \ - || defined (__STDIO_LOADED) /* VMS */ + || defined (__STDIO_LOADED) /* VMS */ \ + || defined (__DEFINED_FILE) /* musl */ size_t mpz_out_str (FILE *, int, const mpz_t); #endif diff --git a/lib/symlink.c b/lib/symlink.c index e7dbd184a99..b1196b9ee85 100644 --- a/lib/symlink.c +++ b/lib/symlink.c @@ -36,7 +36,7 @@ rpl_symlink (char const *contents, char const *name) if (len && name[len - 1] == '/') { struct stat st; - if (lstat (name, &st) == 0) + if (lstat (name, &st) == 0 || errno == EOVERFLOW) errno = EEXIST; return -1; } diff --git a/m4/canonicalize.m4 b/m4/canonicalize.m4 index 14ea3e12fa0..c8da4dfcb6b 100644 --- a/m4/canonicalize.m4 +++ b/m4/canonicalize.m4 @@ -1,4 +1,4 @@ -# canonicalize.m4 serial 33 +# canonicalize.m4 serial 34 dnl Copyright (C) 2003-2007, 2009-2020 Free Software Foundation, Inc. @@ -11,7 +11,9 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_CANONICALIZE_FILENAME_MODE], [ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_FUNCS_ONCE([canonicalize_file_name]) + AC_REQUIRE([gl_FUNC_FACCESSAT_EOVERFLOW]) + AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK]) + AC_CHECK_FUNCS_ONCE([canonicalize_file_name faccessat]) AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) AC_REQUIRE([gl_FUNC_REALPATH_WORKS]) if test $ac_cv_func_canonicalize_file_name = no; then @@ -56,7 +58,9 @@ AC_DEFUN([gl_CANONICALIZE_LGPL], AC_DEFUN([gl_CANONICALIZE_LGPL_SEPARATE], [ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_FUNCS_ONCE([canonicalize_file_name readlink]) + AC_REQUIRE([gl_FUNC_FACCESSAT_EOVERFLOW]) + AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK]) + AC_CHECK_FUNCS_ONCE([canonicalize_file_name faccessat]) dnl On native Windows, we use _getcwd(), regardless whether getcwd() is dnl available through the linker option '-loldnames'. diff --git a/m4/faccessat.m4 b/m4/faccessat.m4 index 7a8b979f8db..a4ad31a469b 100644 --- a/m4/faccessat.m4 +++ b/m4/faccessat.m4 @@ -1,4 +1,4 @@ -# serial 8 +# serial 9 # See if we need to provide faccessat replacement. dnl Copyright (C) 2009-2020 Free Software Foundation, Inc. @@ -8,6 +8,31 @@ dnl with or without modifications, as long as this notice is preserved. # Written by Eric Blake. +AC_DEFUN([gl_FUNC_FACCESSAT_EOVERFLOW], +[ + AC_CHECK_FUNCS_ONCE([faccessat]) + if test "$ac_cv_func_faccessat" = yes; then + AC_CACHE_CHECK([whether faccessat works when stat would EOVERFLOW], + [gl_cv_func_faccessat_never_eoverflows], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([], + [[#ifdef __linux__ + #include + #if (! (KERNEL_VERSION (5, 8, 0) <= LINUX_VERSION_CODE \ + && 2 < (__GLIBC__ + (33 <= __GLIBC_MINOR__)))) + #error "faccessat might fail with EOVERFLOW" + #endif + #endif + ]])], + [gl_cv_func_faccessat_never_eoverflows=yes], + [gl_cv_func_faccessat_never_eoverflows=no])]) + if test "$gl_cv_func_faccessat_never_eoverflows" = yes; then + AC_DEFINE([FACCESSAT_NEVER_EOVERFLOWS], 1, + [Define to 1 if faccessat is EOVERFLOW-free.]) + fi + fi +]) + AC_DEFUN([gl_FUNC_FACCESSAT], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) @@ -16,12 +41,14 @@ AC_DEFUN([gl_FUNC_FACCESSAT], dnl Persuade glibc to declare faccessat(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([gl_FUNC_FACCESSAT_EOVERFLOW]) + AC_CHECK_FUNCS_ONCE([faccessat]) if test $ac_cv_func_faccessat = no; then HAVE_FACCESSAT=0 else - case "$gl_cv_func_lstat_dereferences_slashed_symlink" in - *yes) ;; + case $gl_cv_func_lstat_dereferences_slashed_symlink,$gl_cv_func_faccessat_never_eoverflows in + *yes,*yes) ;; *) REPLACE_FACCESSAT=1 ;; esac fi diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index beb9817d266..0971636c33d 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -75,6 +75,7 @@ AC_DEFUN([gl_EARLY], # Code from module dtoastr: # Code from module dtotimespec: # Code from module dup2: + # Code from module eloop-threshold: # Code from module environ: # Code from module errno: # Code from module euidaccess: @@ -291,6 +292,12 @@ AC_DEFUN([gl_INIT], if test $gl_cv_func___fpending = no; then AC_LIBOBJ([fpending]) fi + gl_FUNC_FREE + if test $REPLACE_FREE = 1; then + AC_LIBOBJ([free]) + gl_PREREQ_FREE + fi + gl_STDLIB_MODULE_INDICATOR([free-posix]) gl_FUNC_FSTATAT if test $HAVE_FSTATAT = 0 || test $REPLACE_FSTATAT = 1; then AC_LIBOBJ([fstatat]) @@ -510,8 +517,8 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_260941c0e5dc67ec9e87d1fb321c300b=false gl_gnulib_enabled_cloexec=false gl_gnulib_enabled_dirfd=false + gl_gnulib_enabled_925677f0343de64b89a9f0c790b4104c=false gl_gnulib_enabled_euidaccess=false - gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955=false gl_gnulib_enabled_getdtablesize=false gl_gnulib_enabled_getgroups=false gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false @@ -557,6 +564,12 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_dirfd=true fi } + func_gl_gnulib_m4code_925677f0343de64b89a9f0c790b4104c () + { + if ! $gl_gnulib_enabled_925677f0343de64b89a9f0c790b4104c; then + gl_gnulib_enabled_925677f0343de64b89a9f0c790b4104c=true + fi + } func_gl_gnulib_m4code_euidaccess () { if ! $gl_gnulib_enabled_euidaccess; then @@ -573,18 +586,6 @@ AC_DEFUN([gl_INIT], func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c fi } - func_gl_gnulib_m4code_ef07dc4b3077c11ea9cef586db4e5955 () - { - if ! $gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955; then - gl_FUNC_FREE - if test $REPLACE_FREE = 1; then - AC_LIBOBJ([free]) - gl_PREREQ_FREE - fi - gl_STDLIB_MODULE_INDICATOR([free-posix]) - gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955=true - fi - } func_gl_gnulib_m4code_getdtablesize () { if ! $gl_gnulib_enabled_getdtablesize; then @@ -734,7 +735,7 @@ AC_DEFUN([gl_INIT], fi } if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then - func_gl_gnulib_m4code_ef07dc4b3077c11ea9cef586db4e5955 + func_gl_gnulib_m4code_925677f0343de64b89a9f0c790b4104c fi if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then func_gl_gnulib_m4code_idx @@ -818,8 +819,8 @@ AC_DEFUN([gl_INIT], AM_CONDITIONAL([gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b], [$gl_gnulib_enabled_260941c0e5dc67ec9e87d1fb321c300b]) AM_CONDITIONAL([gl_GNULIB_ENABLED_cloexec], [$gl_gnulib_enabled_cloexec]) AM_CONDITIONAL([gl_GNULIB_ENABLED_dirfd], [$gl_gnulib_enabled_dirfd]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_925677f0343de64b89a9f0c790b4104c], [$gl_gnulib_enabled_925677f0343de64b89a9f0c790b4104c]) AM_CONDITIONAL([gl_GNULIB_ENABLED_euidaccess], [$gl_gnulib_enabled_euidaccess]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955], [$gl_gnulib_enabled_ef07dc4b3077c11ea9cef586db4e5955]) AM_CONDITIONAL([gl_GNULIB_ENABLED_getdtablesize], [$gl_gnulib_enabled_getdtablesize]) AM_CONDITIONAL([gl_GNULIB_ENABLED_getgroups], [$gl_gnulib_enabled_getgroups]) AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36]) @@ -1020,6 +1021,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/dtoastr.c lib/dtotimespec.c lib/dup2.c + lib/eloop-threshold.h lib/errno.in.h lib/euidaccess.c lib/execinfo.c -- cgit v1.2.1 From 3ba34141da77a24c251ee6530f3f72a366fe556e Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Fri, 25 Dec 2020 11:33:02 +0100 Subject: Import posix_spawn from Gnulib. posix_spawn is less error-prone than vfork + exec, and can make use of system-specific optimizations like `clone' on Linux. Import Gnulib replacement so that we can use recent additions like `posix_spawn_file_actions_addchdir'. The only manual change are to admin/merge-gnulib and .gitignore. All other changes are due to rerunning merge-gnulib. * admin/merge-gnulib (GNULIB_MODULES): Add posix_spawn-related modules. * .gitignore: Add new generated files. --- .gitignore | 2 + admin/merge-gnulib | 9 +- lib/gnulib.mk.in | 302 ++++++++++++ lib/sched.in.h | 99 ++++ lib/spawn.c | 34 ++ lib/spawn.in.h | 974 +++++++++++++++++++++++++++++++++++++ lib/spawn_faction_addchdir.c | 70 +++ lib/spawn_faction_adddup2.c | 70 +++ lib/spawn_faction_destroy.c | 61 +++ lib/spawn_faction_init.c | 56 +++ lib/spawn_int.h | 72 +++ lib/spawnattr_destroy.c | 28 ++ lib/spawnattr_init.c | 33 ++ lib/spawnattr_setdefault.c | 33 ++ lib/spawnattr_setflags.c | 45 ++ lib/spawnattr_setpgroup.c | 32 ++ lib/spawnattr_setsigmask.c | 33 ++ lib/spawni.c | 349 +++++++++++++ lib/strchrnul.c | 142 ++++++ lib/strchrnul.valgrind | 28 ++ m4/gnulib-comp.m4 | 144 ++++++ m4/posix_spawn.m4 | 678 ++++++++++++++++++++++++++ m4/posix_spawn_faction_addchdir.m4 | 20 + m4/sched_h.m4 | 91 ++++ m4/sh-filename.m4 | 22 + m4/spawn_h.m4 | 136 ++++++ m4/strchrnul.m4 | 50 ++ 27 files changed, 3612 insertions(+), 1 deletion(-) create mode 100644 lib/sched.in.h create mode 100644 lib/spawn.c create mode 100644 lib/spawn.in.h create mode 100644 lib/spawn_faction_addchdir.c create mode 100644 lib/spawn_faction_adddup2.c create mode 100644 lib/spawn_faction_destroy.c create mode 100644 lib/spawn_faction_init.c create mode 100644 lib/spawn_int.h create mode 100644 lib/spawnattr_destroy.c create mode 100644 lib/spawnattr_init.c create mode 100644 lib/spawnattr_setdefault.c create mode 100644 lib/spawnattr_setflags.c create mode 100644 lib/spawnattr_setpgroup.c create mode 100644 lib/spawnattr_setsigmask.c create mode 100644 lib/spawni.c create mode 100644 lib/strchrnul.c create mode 100644 lib/strchrnul.valgrind create mode 100644 m4/posix_spawn.m4 create mode 100644 m4/posix_spawn_faction_addchdir.m4 create mode 100644 m4/sched_h.m4 create mode 100644 m4/sh-filename.m4 create mode 100644 m4/spawn_h.m4 create mode 100644 m4/strchrnul.m4 diff --git a/.gitignore b/.gitignore index bf7e9349813..f9c0fae4f60 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,9 @@ lib/ieee754.h lib/inttypes.h lib/libgnu.a lib/limits.h +lib/sched.h lib/signal.h +lib/spawn.h lib/std*.h !lib/std*.in.h !lib/stdio-impl.h diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 880dc5eef53..f1ed2da69e5 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -39,7 +39,14 @@ GNULIB_MODULES=' getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog ieee754-h ignore-value intprops largefile libgmp lstat manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime - pathmax pipe2 pselect pthread_sigmask + pathmax pipe2 + posix_spawn posix_spawn_file_actions_addchdir + posix_spawn_file_actions_adddup2 posix_spawn_file_actions_destroy + posix_spawn_file_actions_init + posix_spawnattr_destroy posix_spawnattr_init + posix_spawnattr_setflags posix_spawnattr_setpgroup + posix_spawnattr_setsigdefault posix_spawnattr_setsigmask + pselect pthread_sigmask qcopy-acl readlink readlinkat regex sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strnlen strtoimax symlink sys_stat sys_time diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index a37f9278a31..209c7eef299 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -130,6 +130,17 @@ # nstrftime \ # pathmax \ # pipe2 \ +# posix_spawn \ +# posix_spawn_file_actions_addchdir \ +# posix_spawn_file_actions_adddup2 \ +# posix_spawn_file_actions_destroy \ +# posix_spawn_file_actions_init \ +# posix_spawnattr_destroy \ +# posix_spawnattr_init \ +# posix_spawnattr_setflags \ +# posix_spawnattr_setpgroup \ +# posix_spawnattr_setsigdefault \ +# posix_spawnattr_setsigmask \ # pselect \ # pthread_sigmask \ # qcopy-acl \ @@ -393,6 +404,29 @@ GNULIB_PIPE2 = @GNULIB_PIPE2@ GNULIB_POPEN = @GNULIB_POPEN@ GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@ GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@ +GNULIB_POSIX_SPAWN = @GNULIB_POSIX_SPAWN@ +GNULIB_POSIX_SPAWNATTR_DESTROY = @GNULIB_POSIX_SPAWNATTR_DESTROY@ +GNULIB_POSIX_SPAWNATTR_GETFLAGS = @GNULIB_POSIX_SPAWNATTR_GETFLAGS@ +GNULIB_POSIX_SPAWNATTR_GETPGROUP = @GNULIB_POSIX_SPAWNATTR_GETPGROUP@ +GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@ +GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@ +GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@ +GNULIB_POSIX_SPAWNATTR_GETSIGMASK = @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@ +GNULIB_POSIX_SPAWNATTR_INIT = @GNULIB_POSIX_SPAWNATTR_INIT@ +GNULIB_POSIX_SPAWNATTR_SETFLAGS = @GNULIB_POSIX_SPAWNATTR_SETFLAGS@ +GNULIB_POSIX_SPAWNATTR_SETPGROUP = @GNULIB_POSIX_SPAWNATTR_SETPGROUP@ +GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@ +GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@ +GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@ +GNULIB_POSIX_SPAWNATTR_SETSIGMASK = @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@ +GNULIB_POSIX_SPAWNP = @GNULIB_POSIX_SPAWNP@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@ +GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@ GNULIB_PREAD = @GNULIB_PREAD@ GNULIB_PRINTF = @GNULIB_PRINTF@ GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@ @@ -425,6 +459,7 @@ GNULIB_RMDIR = @GNULIB_RMDIR@ GNULIB_RPMATCH = @GNULIB_RPMATCH@ GNULIB_SCANDIR = @GNULIB_SCANDIR@ GNULIB_SCANF = @GNULIB_SCANF@ +GNULIB_SCHED_YIELD = @GNULIB_SCHED_YIELD@ GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@ GNULIB_SELECT = @GNULIB_SELECT@ GNULIB_SETENV = @GNULIB_SETENV@ @@ -634,6 +669,11 @@ HAVE_POPEN = @HAVE_POPEN@ HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ +HAVE_POSIX_SPAWN = @HAVE_POSIX_SPAWN@ +HAVE_POSIX_SPAWNATTR_T = @HAVE_POSIX_SPAWNATTR_T@ +HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +HAVE_POSIX_SPAWN_FILE_ACTIONS_T = @HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ HAVE_PREAD = @HAVE_PREAD@ HAVE_PSELECT = @HAVE_PSELECT@ HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@ @@ -655,6 +695,8 @@ HAVE_RENAMEAT = @HAVE_RENAMEAT@ HAVE_REWINDDIR = @HAVE_REWINDDIR@ HAVE_RPMATCH = @HAVE_RPMATCH@ HAVE_SCANDIR = @HAVE_SCANDIR@ +HAVE_SCHED_H = @HAVE_SCHED_H@ +HAVE_SCHED_YIELD = @HAVE_SCHED_YIELD@ HAVE_SECURE_GETENV = @HAVE_SECURE_GETENV@ HAVE_SETENV = @HAVE_SETENV@ HAVE_SETHOSTNAME = @HAVE_SETHOSTNAME@ @@ -669,6 +711,7 @@ HAVE_SIGNED_WCHAR_T = @HAVE_SIGNED_WCHAR_T@ HAVE_SIGNED_WINT_T = @HAVE_SIGNED_WINT_T@ HAVE_SIGSET_T = @HAVE_SIGSET_T@ HAVE_SLEEP = @HAVE_SLEEP@ +HAVE_SPAWN_H = @HAVE_SPAWN_H@ HAVE_STDINT_H = @HAVE_STDINT_H@ HAVE_STPCPY = @HAVE_STPCPY@ HAVE_STPNCPY = @HAVE_STPNCPY@ @@ -683,6 +726,7 @@ HAVE_STRTOLD = @HAVE_STRTOLD@ HAVE_STRTOLL = @HAVE_STRTOLL@ HAVE_STRTOULL = @HAVE_STRTOULL@ HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@ +HAVE_STRUCT_SCHED_PARAM = @HAVE_STRUCT_SCHED_PARAM@ HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@ HAVE_STRUCT_TIMEVAL = @HAVE_STRUCT_TIMEVAL@ HAVE_STRVERSCMP = @HAVE_STRVERSCMP@ @@ -782,6 +826,7 @@ LIB_EACCESS = @LIB_EACCESS@ LIB_EXECINFO = @LIB_EXECINFO@ LIB_GETRANDOM = @LIB_GETRANDOM@ LIB_MATH = @LIB_MATH@ +LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@ LIB_PTHREAD = @LIB_PTHREAD@ LIB_PTHREAD_SIGMASK = @LIB_PTHREAD_SIGMASK@ LIB_TIMER_TIME = @LIB_TIMER_TIME@ @@ -805,7 +850,9 @@ NEXT_AS_FIRST_DIRECTIVE_FCNTL_H = @NEXT_AS_FIRST_DIRECTIVE_FCNTL_H@ NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@ NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@ NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@ +NEXT_AS_FIRST_DIRECTIVE_SCHED_H = @NEXT_AS_FIRST_DIRECTIVE_SCHED_H@ NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@ +NEXT_AS_FIRST_DIRECTIVE_SPAWN_H = @NEXT_AS_FIRST_DIRECTIVE_SPAWN_H@ NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ NEXT_AS_FIRST_DIRECTIVE_STDINT_H = @NEXT_AS_FIRST_DIRECTIVE_STDINT_H@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@ @@ -824,7 +871,9 @@ NEXT_FCNTL_H = @NEXT_FCNTL_H@ NEXT_GETOPT_H = @NEXT_GETOPT_H@ NEXT_INTTYPES_H = @NEXT_INTTYPES_H@ NEXT_LIMITS_H = @NEXT_LIMITS_H@ +NEXT_SCHED_H = @NEXT_SCHED_H@ NEXT_SIGNAL_H = @NEXT_SIGNAL_H@ +NEXT_SPAWN_H = @NEXT_SPAWN_H@ NEXT_STDDEF_H = @NEXT_STDDEF_H@ NEXT_STDINT_H = @NEXT_STDINT_H@ NEXT_STDIO_H = @NEXT_STDIO_H@ @@ -946,6 +995,12 @@ REPLACE_OPENDIR = @REPLACE_OPENDIR@ REPLACE_PERROR = @REPLACE_PERROR@ REPLACE_POPEN = @REPLACE_POPEN@ REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ +REPLACE_POSIX_SPAWN = @REPLACE_POSIX_SPAWN@ +REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ +REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ +REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PRINTF = @REPLACE_PRINTF@ REPLACE_PSELECT = @REPLACE_PSELECT@ @@ -967,6 +1022,7 @@ REPLACE_REMOVE = @REPLACE_REMOVE@ REPLACE_RENAME = @REPLACE_RENAME@ REPLACE_RENAMEAT = @REPLACE_RENAMEAT@ REPLACE_RMDIR = @REPLACE_RMDIR@ +REPLACE_SCHED_YIELD = @REPLACE_SCHED_YIELD@ REPLACE_SELECT = @REPLACE_SELECT@ REPLACE_SETENV = @REPLACE_SETENV@ REPLACE_SETSTATE = @REPLACE_SETSTATE@ @@ -1108,11 +1164,13 @@ gamegroup = @gamegroup@ gameuser = @gameuser@ gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7 = @gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7@ gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b = @gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b@ +gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7 = @gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7@ gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31 = @gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31@ gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c = @gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c@ gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec = @gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec@ gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1@ gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@ +gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70 = @gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70@ gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@ gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@ gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@ @@ -1124,6 +1182,7 @@ gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@ gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@ gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@ gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@ +gl_GNULIB_ENABLED_strchrnul = @gl_GNULIB_ENABLED_strchrnul@ gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@ gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@ gl_LIBOBJS = @gl_LIBOBJS@ @@ -2270,6 +2329,140 @@ libgnu_a_SOURCES += pipe2.c endif ## end gnulib module pipe2 +## begin gnulib module posix_spawn +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn)) + + +EXTRA_DIST += spawn.c + +EXTRA_libgnu_a_SOURCES += spawn.c + +endif +## end gnulib module posix_spawn + +## begin gnulib module posix_spawn-internal +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn-internal)) + +ifneq (,$(gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7)) + +endif +EXTRA_DIST += spawn_int.h spawni.c + +EXTRA_libgnu_a_SOURCES += spawni.c + +endif +## end gnulib module posix_spawn-internal + +## begin gnulib module posix_spawn_file_actions_addchdir +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_addchdir)) + + +EXTRA_DIST += spawn_faction_addchdir.c spawn_int.h + +EXTRA_libgnu_a_SOURCES += spawn_faction_addchdir.c + +endif +## end gnulib module posix_spawn_file_actions_addchdir + +## begin gnulib module posix_spawn_file_actions_adddup2 +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_adddup2)) + + +EXTRA_DIST += spawn_faction_adddup2.c spawn_int.h + +EXTRA_libgnu_a_SOURCES += spawn_faction_adddup2.c + +endif +## end gnulib module posix_spawn_file_actions_adddup2 + +## begin gnulib module posix_spawn_file_actions_destroy +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_destroy)) + + +EXTRA_DIST += spawn_faction_destroy.c + +EXTRA_libgnu_a_SOURCES += spawn_faction_destroy.c + +endif +## end gnulib module posix_spawn_file_actions_destroy + +## begin gnulib module posix_spawn_file_actions_init +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_init)) + + +EXTRA_DIST += spawn_faction_init.c spawn_int.h + +EXTRA_libgnu_a_SOURCES += spawn_faction_init.c + +endif +## end gnulib module posix_spawn_file_actions_init + +## begin gnulib module posix_spawnattr_destroy +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_destroy)) + + +EXTRA_DIST += spawnattr_destroy.c + +EXTRA_libgnu_a_SOURCES += spawnattr_destroy.c + +endif +## end gnulib module posix_spawnattr_destroy + +## begin gnulib module posix_spawnattr_init +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_init)) + + +EXTRA_DIST += spawnattr_init.c + +EXTRA_libgnu_a_SOURCES += spawnattr_init.c + +endif +## end gnulib module posix_spawnattr_init + +## begin gnulib module posix_spawnattr_setflags +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setflags)) + + +EXTRA_DIST += spawnattr_setflags.c + +EXTRA_libgnu_a_SOURCES += spawnattr_setflags.c + +endif +## end gnulib module posix_spawnattr_setflags + +## begin gnulib module posix_spawnattr_setpgroup +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setpgroup)) + + +EXTRA_DIST += spawnattr_setpgroup.c + +EXTRA_libgnu_a_SOURCES += spawnattr_setpgroup.c + +endif +## end gnulib module posix_spawnattr_setpgroup + +## begin gnulib module posix_spawnattr_setsigdefault +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigdefault)) + + +EXTRA_DIST += spawnattr_setdefault.c + +EXTRA_libgnu_a_SOURCES += spawnattr_setdefault.c + +endif +## end gnulib module posix_spawnattr_setsigdefault + +## begin gnulib module posix_spawnattr_setsigmask +ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigmask)) + + +EXTRA_DIST += spawnattr_setsigmask.c + +EXTRA_libgnu_a_SOURCES += spawnattr_setsigmask.c + +endif +## end gnulib module posix_spawnattr_setsigmask + ## begin gnulib module pselect ifeq (,$(OMIT_GNULIB_MODULE_pselect)) @@ -2357,6 +2550,39 @@ EXTRA_DIST += root-uid.h endif ## end gnulib module root-uid +## begin gnulib module sched +ifeq (,$(OMIT_GNULIB_MODULE_sched)) + +BUILT_SOURCES += sched.h + +# We need the following in order to create a replacement for when +# the system doesn't have one. +sched.h: sched.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_SCHED_H''@|$(HAVE_SCHED_H)|g' \ + -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SCHED_H''@|$(NEXT_SCHED_H)|g' \ + -e 's|@''HAVE_STRUCT_SCHED_PARAM''@|$(HAVE_STRUCT_SCHED_PARAM)|g' \ + -e 's/@''GNULIB_SCHED_YIELD''@/$(GNULIB_SCHED_YIELD)/g' \ + -e 's|@''HAVE_SCHED_YIELD''@|$(HAVE_SCHED_YIELD)|g' \ + -e 's|@''REPLACE_SCHED_YIELD''@|$(REPLACE_SCHED_YIELD)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/sched.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sched.h sched.h-t + +EXTRA_DIST += sched.in.h + +endif +## end gnulib module sched + ## begin gnulib module scratch_buffer ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer)) @@ -2491,6 +2717,69 @@ EXTRA_DIST += warn-on-use.h endif ## end gnulib module snippet/warn-on-use +## begin gnulib module spawn +ifeq (,$(OMIT_GNULIB_MODULE_spawn)) + +BUILT_SOURCES += spawn.h + +# We need the following in order to create a replacement for when +# the system doesn't have one. +spawn.h: spawn.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_SPAWN_H''@|$(HAVE_SPAWN_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SPAWN_H''@|$(NEXT_SPAWN_H)|g' \ + -e 's/@''GNULIB_POSIX_SPAWN''@/$(GNULIB_POSIX_SPAWN)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNP''@/$(GNULIB_POSIX_SPAWNP)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)/g' \ + -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_INIT''@/$(GNULIB_POSIX_SPAWNATTR_INIT)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_GETFLAGS)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_SETFLAGS)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_GETPGROUP)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_SETPGROUP)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGMASK)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGMASK)/g' \ + -e 's/@''GNULIB_POSIX_SPAWNATTR_DESTROY''@/$(GNULIB_POSIX_SPAWNATTR_DESTROY)/g' \ + -e 's|@''HAVE_POSIX_SPAWN''@|$(HAVE_POSIX_SPAWN)|g' \ + -e 's|@''HAVE_POSIX_SPAWNATTR_T''@|$(HAVE_POSIX_SPAWNATTR_T)|g' \ + -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_T''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_T)|g' \ + -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \ + -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN''@|$(REPLACE_POSIX_SPAWN)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \ + -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/spawn.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += spawn.h spawn.h-t + +EXTRA_DIST += spawn.in.h + +endif +## end gnulib module spawn + ## begin gnulib module stat-time ifeq (,$(OMIT_GNULIB_MODULE_stat-time)) @@ -2885,6 +3174,19 @@ EXTRA_libgnu_a_SOURCES += stpcpy.c endif ## end gnulib module stpcpy +## begin gnulib module strchrnul +ifeq (,$(OMIT_GNULIB_MODULE_strchrnul)) + +ifneq (,$(gl_GNULIB_ENABLED_strchrnul)) + +endif +EXTRA_DIST += strchrnul.c strchrnul.valgrind + +EXTRA_libgnu_a_SOURCES += strchrnul.c + +endif +## end gnulib module strchrnul + ## begin gnulib module string ifeq (,$(OMIT_GNULIB_MODULE_string)) diff --git a/lib/sched.in.h b/lib/sched.in.h new file mode 100644 index 00000000000..4ee9defe82b --- /dev/null +++ b/lib/sched.in.h @@ -0,0 +1,99 @@ +/* A GNU-like . + Copyright (C) 2008-2020 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 . */ + +#ifndef _@GUARD_PREFIX@_SCHED_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_SCHED_H@ +# if @HAVE_SYS_CDEFS_H@ +# include +# endif +# @INCLUDE_NEXT@ @NEXT_SCHED_H@ +#endif + +#ifndef _@GUARD_PREFIX@_SCHED_H +#define _@GUARD_PREFIX@_SCHED_H + +/* Get pid_t. + This is needed on glibc 2.11 (see + glibc bug ) + and Mac OS X 10.5. */ +#include + +#ifdef __KLIBC__ +/* On OS/2 kLIBC, struct sched_param is in spawn.h. */ +# include +#endif + +#ifdef __VMS +/* On OpenVMS, struct sched_param is in . */ +# include +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +#if !@HAVE_STRUCT_SCHED_PARAM@ + +# if !GNULIB_defined_struct_sched_param +struct sched_param +{ + int sched_priority; +}; +# define GNULIB_defined_struct_sched_param 1 +# endif + +#endif + +#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER) +# define SCHED_FIFO 1 +# define SCHED_RR 2 +# define SCHED_OTHER 0 +#endif + +#if @GNULIB_SCHED_YIELD@ +# if @REPLACE_SCHED_YIELD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef sched_yield +# define sched_yield rpl_sched_yield +# endif +_GL_FUNCDECL_RPL (sched_yield, int, (void)); +_GL_CXXALIAS_RPL (sched_yield, int, (void)); +# else +# if !@HAVE_SCHED_YIELD@ +_GL_FUNCDECL_SYS (sched_yield, int, (void)); +# endif +_GL_CXXALIAS_SYS (sched_yield, int, (void)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (sched_yield); +# endif +#elif defined GNULIB_POSIXCHECK +# undef sched_yield +# if HAVE_RAW_DECL_SCHED_YIELD +_GL_WARN_ON_USE (sched_yield, "sched_yield is not portable - " + "use gnulib module sched_yield for portability"); +# endif +#endif + +#endif /* _@GUARD_PREFIX@_SCHED_H */ +#endif /* _@GUARD_PREFIX@_SCHED_H */ diff --git a/lib/spawn.c b/lib/spawn.c new file mode 100644 index 00000000000..b658453a10f --- /dev/null +++ b/lib/spawn.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include "spawn_int.h" + +/* Spawn a new process executing PATH with the attributes describes in *ATTRP. + Before running the process perform the actions described in FILE-ACTIONS. */ +int +posix_spawn (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[]) +{ + return __spawni (pid, path, file_actions, attrp, + (const char * const *) argv, (const char * const *) envp, 0); +} diff --git a/lib/spawn.in.h b/lib/spawn.in.h new file mode 100644 index 00000000000..537fac7dbc5 --- /dev/null +++ b/lib/spawn.in.h @@ -0,0 +1,974 @@ +/* Definitions for POSIX spawn interface. + Copyright (C) 2000, 2003-2004, 2008-2020 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 . */ + +#ifndef _@GUARD_PREFIX@_SPAWN_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_SPAWN_H@ +# @INCLUDE_NEXT@ @NEXT_SPAWN_H@ +#endif + +#ifndef _@GUARD_PREFIX@_SPAWN_H +#define _@GUARD_PREFIX@_SPAWN_H + +/* Get definitions of 'struct sched_param' and 'sigset_t'. + But avoid namespace pollution on glibc systems. */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +# include +#endif + +#include + +#ifndef __THROW +# define __THROW +#endif + +/* For plain 'restrict', use glibc's __restrict if defined. + Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have + "restrict", and "configure" may have defined "restrict". + Other compilers use __restrict, __restrict__, and _Restrict, and + 'configure' might #define 'restrict' to those words, so pick a + different name. */ +#ifndef _Restrict_ +# if defined __restrict \ + || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \ + || __clang_major__ >= 3 +# define _Restrict_ __restrict +# elif 199901L <= __STDC_VERSION__ || defined restrict +# define _Restrict_ restrict +# else +# define _Restrict_ +# endif +#endif +/* For the ISO C99 syntax + array_name[restrict] + use glibc's __restrict_arr if available. + Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode). + Other ISO C99 compilers support it as well. */ +#ifndef _Restrict_arr_ +# ifdef __restrict_arr +# define _Restrict_arr_ __restrict_arr +# elif ((199901L <= __STDC_VERSION__ \ + || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \ + || __clang_major__ >= 3) \ + && !defined __cplusplus) +# define _Restrict_arr_ _Restrict_ +# else +# define _Restrict_arr_ +# endif +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Data structure to contain attributes for thread creation. */ +#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWNATTR_T@ && !@HAVE_POSIX_SPAWN@) +# define posix_spawnattr_t rpl_posix_spawnattr_t +#endif +#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWNATTR_T@ || !@HAVE_POSIX_SPAWN@ +# if !GNULIB_defined_posix_spawnattr_t +typedef struct +{ + short int _flags; + pid_t _pgrp; + sigset_t _sd; + sigset_t _ss; + struct sched_param _sp; + int _policy; + int __pad[16]; +} posix_spawnattr_t; +# define GNULIB_defined_posix_spawnattr_t 1 +# endif +#endif + + +/* Data structure to contain information about the actions to be + performed in the new process with respect to file descriptors. */ +#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ && !@HAVE_POSIX_SPAWN@) +# define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t +#endif +#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ || !@HAVE_POSIX_SPAWN@ +# if !GNULIB_defined_posix_spawn_file_actions_t +typedef struct +{ + int _allocated; + int _used; + struct __spawn_action *_actions; + int __pad[16]; +} posix_spawn_file_actions_t; +# define GNULIB_defined_posix_spawn_file_actions_t 1 +# endif +#endif + + +/* Flags to be set in the 'posix_spawnattr_t'. */ +#if @HAVE_POSIX_SPAWN@ +/* Use the values from the system, but provide the missing ones. */ +# ifndef POSIX_SPAWN_SETSCHEDPARAM +# define POSIX_SPAWN_SETSCHEDPARAM 0 +# endif +# ifndef POSIX_SPAWN_SETSCHEDULER +# define POSIX_SPAWN_SETSCHEDULER 0 +# endif +#else +# if @REPLACE_POSIX_SPAWN@ +/* Use the values from the system, for better compatibility. */ +/* But this implementation does not support AIX extensions. */ +# undef POSIX_SPAWN_FORK_HANDLERS +# else +# define POSIX_SPAWN_RESETIDS 0x01 +# define POSIX_SPAWN_SETPGROUP 0x02 +# define POSIX_SPAWN_SETSIGDEF 0x04 +# define POSIX_SPAWN_SETSIGMASK 0x08 +# define POSIX_SPAWN_SETSCHEDPARAM 0x10 +# define POSIX_SPAWN_SETSCHEDULER 0x20 +# endif +#endif +/* A GNU extension. Use the next free bit position. */ +#ifndef POSIX_SPAWN_USEVFORK +# define POSIX_SPAWN_USEVFORK \ + ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \ + | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \ + | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \ + | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \ + | POSIX_SPAWN_SETSCHEDPARAM \ + | (POSIX_SPAWN_SETSCHEDPARAM > 0 ? POSIX_SPAWN_SETSCHEDPARAM - 1 : 0) \ + | POSIX_SPAWN_SETSCHEDULER \ + | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0)) \ + + 1) +#endif +#if !GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap +typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap + [(((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP + | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK + | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER) + & POSIX_SPAWN_USEVFORK) + == 0) + ? 1 : -1]; +# define GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap 1 +#endif + + +#if @GNULIB_POSIX_SPAWN@ +/* Spawn a new process executing PATH with the attributes describes in *ATTRP. + Before running the process perform the actions described in FILE-ACTIONS. + + This function is a possible cancellation points and therefore not + marked with __THROW. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn rpl_posix_spawn +# endif +_GL_FUNCDECL_RPL (posix_spawn, int, + (pid_t *_Restrict_ __pid, + const char *_Restrict_ __path, + const posix_spawn_file_actions_t *_Restrict_ __file_actions, + const posix_spawnattr_t *_Restrict_ __attrp, + char *const argv[_Restrict_arr_], + char *const envp[_Restrict_arr_]) + _GL_ARG_NONNULL ((2, 5, 6))); +_GL_CXXALIAS_RPL (posix_spawn, int, + (pid_t *_Restrict_ __pid, + const char *_Restrict_ __path, + const posix_spawn_file_actions_t *_Restrict_ __file_actions, + const posix_spawnattr_t *_Restrict_ __attrp, + char *const argv[_Restrict_arr_], + char *const envp[_Restrict_arr_])); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn, int, + (pid_t *_Restrict_ __pid, + const char *_Restrict_ __path, + const posix_spawn_file_actions_t *_Restrict_ __file_actions, + const posix_spawnattr_t *_Restrict_ __attrp, + char *const argv[_Restrict_arr_], + char *const envp[_Restrict_arr_]) + _GL_ARG_NONNULL ((2, 5, 6))); +# endif +_GL_CXXALIAS_SYS (posix_spawn, int, + (pid_t *_Restrict_ __pid, + const char *_Restrict_ __path, + const posix_spawn_file_actions_t *_Restrict_ __file_actions, + const posix_spawnattr_t *_Restrict_ __attrp, + char *const argv[_Restrict_arr_], + char *const envp[_Restrict_arr_])); +# endif +_GL_CXXALIASWARN (posix_spawn); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn +# if HAVE_RAW_DECL_POSIX_SPAWN +_GL_WARN_ON_USE (posix_spawn, "posix_spawn is unportable - " + "use gnulib module posix_spawn for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNP@ +/* Similar to 'posix_spawn' but search for FILE in the PATH. + + This function is a possible cancellation points and therefore not + marked with __THROW. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnp rpl_posix_spawnp +# endif +_GL_FUNCDECL_RPL (posix_spawnp, int, + (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[]) + _GL_ARG_NONNULL ((2, 5, 6))); +_GL_CXXALIAS_RPL (posix_spawnp, int, + (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[])); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnp, int, + (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[]) + _GL_ARG_NONNULL ((2, 5, 6))); +# endif +_GL_CXXALIAS_SYS (posix_spawnp, int, + (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[])); +# endif +_GL_CXXALIASWARN (posix_spawnp); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnp +# if HAVE_RAW_DECL_POSIX_SPAWNP +_GL_WARN_ON_USE (posix_spawnp, "posix_spawnp is unportable - " + "use gnulib module posix_spawnp for portability"); +# endif +#endif + + +#if @GNULIB_POSIX_SPAWNATTR_INIT@ +/* Initialize data structure with attributes for 'spawn' to default values. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_init rpl_posix_spawnattr_init +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_init); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_init +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_INIT +_GL_WARN_ON_USE (posix_spawnattr_init, "posix_spawnattr_init is unportable - " + "use gnulib module posix_spawnattr_init for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_DESTROY@ +/* Free resources associated with ATTR. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_destroy rpl_posix_spawnattr_destroy +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_destroy); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_destroy +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_DESTROY +_GL_WARN_ON_USE (posix_spawnattr_destroy, + "posix_spawnattr_destroy is unportable - " + "use gnulib module posix_spawnattr_destroy for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@ +/* Store signal mask for signals with default handling from ATTR in + SIGDEFAULT. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getsigdefault, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigdefault) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getsigdefault, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigdefault)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_getsigdefault, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigdefault) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getsigdefault, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigdefault)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_getsigdefault); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getsigdefault +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGDEFAULT +_GL_WARN_ON_USE (posix_spawnattr_getsigdefault, + "posix_spawnattr_getsigdefault is unportable - " + "use gnulib module posix_spawnattr_getsigdefault for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@ +/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setsigdefault, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigdefault) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_setsigdefault, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigdefault)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_setsigdefault, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigdefault) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setsigdefault, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigdefault)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_setsigdefault); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setsigdefault +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGDEFAULT +_GL_WARN_ON_USE (posix_spawnattr_setsigdefault, + "posix_spawnattr_setsigdefault is unportable - " + "use gnulib module posix_spawnattr_setsigdefault for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@ +/* Store signal mask for the new process from ATTR in SIGMASK. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getsigmask, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigmask) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getsigmask, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigmask)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_getsigmask, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigmask) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getsigmask, int, + (const posix_spawnattr_t *_Restrict_ __attr, + sigset_t *_Restrict_ __sigmask)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_getsigmask); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getsigmask +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGMASK +_GL_WARN_ON_USE (posix_spawnattr_getsigmask, + "posix_spawnattr_getsigmask is unportable - " + "use gnulib module posix_spawnattr_getsigmask for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@ +/* Set signal mask for the new process in ATTR to SIGMASK. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setsigmask, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigmask) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_setsigmask, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigmask)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_setsigmask, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigmask) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setsigmask, int, + (posix_spawnattr_t *_Restrict_ __attr, + const sigset_t *_Restrict_ __sigmask)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_setsigmask); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setsigmask +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGMASK +_GL_WARN_ON_USE (posix_spawnattr_setsigmask, + "posix_spawnattr_setsigmask is unportable - " + "use gnulib module posix_spawnattr_setsigmask for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@ +/* Get flag word from the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getflags rpl_posix_spawnattr_getflags +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getflags, int, + (const posix_spawnattr_t *_Restrict_ __attr, + short int *_Restrict_ __flags) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getflags, int, + (const posix_spawnattr_t *_Restrict_ __attr, + short int *_Restrict_ __flags)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_getflags, int, + (const posix_spawnattr_t *_Restrict_ __attr, + short int *_Restrict_ __flags) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getflags, int, + (const posix_spawnattr_t *_Restrict_ __attr, + short int *_Restrict_ __flags)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_getflags); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getflags +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETFLAGS +_GL_WARN_ON_USE (posix_spawnattr_getflags, + "posix_spawnattr_getflags is unportable - " + "use gnulib module posix_spawnattr_getflags for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@ +/* Store flags in the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setflags rpl_posix_spawnattr_setflags +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setflags, int, + (posix_spawnattr_t *__attr, short int __flags) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawnattr_setflags, int, + (posix_spawnattr_t *__attr, short int __flags)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_setflags, int, + (posix_spawnattr_t *__attr, short int __flags) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setflags, int, + (posix_spawnattr_t *__attr, short int __flags)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_setflags); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setflags +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETFLAGS +_GL_WARN_ON_USE (posix_spawnattr_setflags, + "posix_spawnattr_setflags is unportable - " + "use gnulib module posix_spawnattr_setflags for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@ +/* Get process group ID from the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getpgroup, int, + (const posix_spawnattr_t *_Restrict_ __attr, + pid_t *_Restrict_ __pgroup) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getpgroup, int, + (const posix_spawnattr_t *_Restrict_ __attr, + pid_t *_Restrict_ __pgroup)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_getpgroup, int, + (const posix_spawnattr_t *_Restrict_ __attr, + pid_t *_Restrict_ __pgroup) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getpgroup, int, + (const posix_spawnattr_t *_Restrict_ __attr, + pid_t *_Restrict_ __pgroup)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_getpgroup); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getpgroup +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETPGROUP +_GL_WARN_ON_USE (posix_spawnattr_getpgroup, + "posix_spawnattr_getpgroup is unportable - " + "use gnulib module posix_spawnattr_getpgroup for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@ +/* Store process group ID in the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setpgroup, int, + (posix_spawnattr_t *__attr, pid_t __pgroup) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawnattr_setpgroup, int, + (posix_spawnattr_t *__attr, pid_t __pgroup)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawnattr_setpgroup, int, + (posix_spawnattr_t *__attr, pid_t __pgroup) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setpgroup, int, + (posix_spawnattr_t *__attr, pid_t __pgroup)); +# endif +_GL_CXXALIASWARN (posix_spawnattr_setpgroup); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setpgroup +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETPGROUP +_GL_WARN_ON_USE (posix_spawnattr_setpgroup, + "posix_spawnattr_setpgroup is unportable - " + "use gnulib module posix_spawnattr_setpgroup for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@ +/* Get scheduling policy from the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getschedpolicy, int, + (const posix_spawnattr_t *_Restrict_ __attr, + int *_Restrict_ __schedpolicy) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getschedpolicy, int, + (const posix_spawnattr_t *_Restrict_ __attr, + int *_Restrict_ __schedpolicy)); +# else +# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0 +_GL_FUNCDECL_SYS (posix_spawnattr_getschedpolicy, int, + (const posix_spawnattr_t *_Restrict_ __attr, + int *_Restrict_ __schedpolicy) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getschedpolicy, int, + (const posix_spawnattr_t *_Restrict_ __attr, + int *_Restrict_ __schedpolicy)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawnattr_getschedpolicy); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getschedpolicy +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPOLICY +_GL_WARN_ON_USE (posix_spawnattr_getschedpolicy, + "posix_spawnattr_getschedpolicy is unportable - " + "use gnulib module posix_spawnattr_getschedpolicy for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@ +/* Store scheduling policy in the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setschedpolicy, int, + (posix_spawnattr_t *__attr, int __schedpolicy) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawnattr_setschedpolicy, int, + (posix_spawnattr_t *__attr, int __schedpolicy)); +# else +# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0 +_GL_FUNCDECL_SYS (posix_spawnattr_setschedpolicy, int, + (posix_spawnattr_t *__attr, int __schedpolicy) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setschedpolicy, int, + (posix_spawnattr_t *__attr, int __schedpolicy)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawnattr_setschedpolicy); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setschedpolicy +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPOLICY +_GL_WARN_ON_USE (posix_spawnattr_setschedpolicy, + "posix_spawnattr_setschedpolicy is unportable - " + "use gnulib module posix_spawnattr_setschedpolicy for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@ +/* Get scheduling parameters from the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_getschedparam, int, + (const posix_spawnattr_t *_Restrict_ __attr, + struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_getschedparam, int, + (const posix_spawnattr_t *_Restrict_ __attr, + struct sched_param *_Restrict_ __schedparam)); +# else +# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0 +_GL_FUNCDECL_SYS (posix_spawnattr_getschedparam, int, + (const posix_spawnattr_t *_Restrict_ __attr, + struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_getschedparam, int, + (const posix_spawnattr_t *_Restrict_ __attr, + struct sched_param *_Restrict_ __schedparam)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawnattr_getschedparam); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_getschedparam +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPARAM +_GL_WARN_ON_USE (posix_spawnattr_getschedparam, + "posix_spawnattr_getschedparam is unportable - " + "use gnulib module posix_spawnattr_getschedparam for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@ +/* Store scheduling parameters in the attribute structure. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam +# endif +_GL_FUNCDECL_RPL (posix_spawnattr_setschedparam, int, + (posix_spawnattr_t *_Restrict_ __attr, + const struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawnattr_setschedparam, int, + (posix_spawnattr_t *_Restrict_ __attr, + const struct sched_param *_Restrict_ __schedparam)); +# else +# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0 +_GL_FUNCDECL_SYS (posix_spawnattr_setschedparam, int, + (posix_spawnattr_t *_Restrict_ __attr, + const struct sched_param *_Restrict_ __schedparam) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawnattr_setschedparam, int, + (posix_spawnattr_t *_Restrict_ __attr, + const struct sched_param *_Restrict_ __schedparam)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawnattr_setschedparam); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawnattr_setschedparam +# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPARAM +_GL_WARN_ON_USE (posix_spawnattr_setschedparam, + "posix_spawnattr_setschedparam is unportable - " + "use gnulib module posix_spawnattr_setschedparam for portability"); +# endif +#endif + + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@ +/* Initialize data structure for file attribute for 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_init, int, + (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_init, int, + (posix_spawn_file_actions_t *__file_actions)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_init, int, + (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_init, int, + (posix_spawn_file_actions_t *__file_actions)); +# endif +_GL_CXXALIASWARN (posix_spawn_file_actions_init); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_init +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_INIT +_GL_WARN_ON_USE (posix_spawn_file_actions_init, + "posix_spawn_file_actions_init is unportable - " + "use gnulib module posix_spawn_file_actions_init for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@ +/* Free resources associated with FILE-ACTIONS. */ +# if @REPLACE_POSIX_SPAWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_destroy, int, + (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_destroy, int, + (posix_spawn_file_actions_t *__file_actions)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_destroy, int, + (posix_spawn_file_actions_t *__file_actions) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_destroy, int, + (posix_spawn_file_actions_t *__file_actions)); +# endif +_GL_CXXALIASWARN (posix_spawn_file_actions_destroy); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_destroy +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_DESTROY +_GL_WARN_ON_USE (posix_spawn_file_actions_destroy, + "posix_spawn_file_actions_destroy is unportable - " + "use gnulib module posix_spawn_file_actions_destroy for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'open' for the given file during the 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_addopen, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd, + const char *_Restrict_ __path, int __oflag, mode_t __mode) + __THROW _GL_ARG_NONNULL ((1, 3))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_addopen, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd, + const char *_Restrict_ __path, int __oflag, mode_t __mode)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_addopen, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd, + const char *_Restrict_ __path, int __oflag, mode_t __mode) + __THROW _GL_ARG_NONNULL ((1, 3))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd, + const char *_Restrict_ __path, int __oflag, mode_t __mode)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawn_file_actions_addopen); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_addopen +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN +_GL_WARN_ON_USE (posix_spawn_file_actions_addopen, + "posix_spawn_file_actions_addopen is unportable - " + "use gnulib module posix_spawn_file_actions_addopen for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'close' for the given file descriptor during the 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_addclose, int, + (posix_spawn_file_actions_t *__file_actions, int __fd) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_addclose, int, + (posix_spawn_file_actions_t *__file_actions, int __fd)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int, + (posix_spawn_file_actions_t *__file_actions, int __fd) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int, + (posix_spawn_file_actions_t *__file_actions, int __fd)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawn_file_actions_addclose); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_addclose +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE +_GL_WARN_ON_USE (posix_spawn_file_actions_addclose, + "posix_spawn_file_actions_addclose is unportable - " + "use gnulib module posix_spawn_file_actions_addclose for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'dup2' for the given file descriptors during the 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2 +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_adddup2, int, + (posix_spawn_file_actions_t *__file_actions, + int __fd, int __newfd) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_adddup2, int, + (posix_spawn_file_actions_t *__file_actions, + int __fd, int __newfd)); +# else +# if !@HAVE_POSIX_SPAWN@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_adddup2, int, + (posix_spawn_file_actions_t *__file_actions, + int __fd, int __newfd) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int, + (posix_spawn_file_actions_t *__file_actions, + int __fd, int __newfd)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (posix_spawn_file_actions_adddup2); +# endif +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_adddup2 +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 +_GL_WARN_ON_USE (posix_spawn_file_actions_adddup2, + "posix_spawn_file_actions_adddup2 is unportable - " + "use gnulib module posix_spawn_file_actions_adddup2 for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'chdir' to the given directory during the 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_addchdir rpl_posix_spawn_file_actions_addchdir +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_addchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + const char *_Restrict_ __path) + __THROW _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_addchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + const char *_Restrict_ __path)); +# else +# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_addchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + const char *_Restrict_ __path) + __THROW _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_addchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + const char *_Restrict_ __path)); +# endif +_GL_CXXALIASWARN (posix_spawn_file_actions_addchdir); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_addchdir +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR +_GL_WARN_ON_USE (posix_spawn_file_actions_addchdir, + "posix_spawn_file_actions_addchdir is unportable - " + "use gnulib module posix_spawn_file_actions_addchdir for portability"); +# endif +#endif + +#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'fchdir' to the given directory during the 'spawn' call. */ +# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define posix_spawn_file_actions_addfchdir rpl_posix_spawn_file_actions_addfchdir +# endif +_GL_FUNCDECL_RPL (posix_spawn_file_actions_addfchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd) + __THROW _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (posix_spawn_file_actions_addfchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd)); +# else +# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ +_GL_FUNCDECL_SYS (posix_spawn_file_actions_addfchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd) + __THROW _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (posix_spawn_file_actions_addfchdir, int, + (posix_spawn_file_actions_t *_Restrict_ __file_actions, + int __fd)); +# endif +_GL_CXXALIASWARN (posix_spawn_file_actions_addfchdir); +#elif defined GNULIB_POSIXCHECK +# undef posix_spawn_file_actions_addfchdir +# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR +_GL_WARN_ON_USE (posix_spawn_file_actions_addfchdir, + "posix_spawn_file_actions_addfchdir is unportable - " + "use gnulib module posix_spawn_file_actions_addfchdir for portability"); +# endif +#endif + + +#endif /* _@GUARD_PREFIX@_SPAWN_H */ +#endif /* _@GUARD_PREFIX@_SPAWN_H */ diff --git a/lib/spawn_faction_addchdir.c b/lib/spawn_faction_addchdir.c new file mode 100644 index 00000000000..8fb6cb0f7d2 --- /dev/null +++ b/lib/spawn_faction_addchdir.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2018-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include + +#if REPLACE_POSIX_SPAWN +# include "spawn_int.h" +#endif + +/* Add an action to FILE-ACTIONS which tells the implementation to call + 'chdir' to the given directory during the 'spawn' call. */ +int +posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t *file_actions, + const char *path) +#undef posix_spawn_file_actions_addchdir +{ +#if !REPLACE_POSIX_SPAWN + return posix_spawn_file_actions_addchdir_np (file_actions, path); +#else + { + /* Copy PATH, because the caller may free it before calling posix_spawn() + or posix_spawnp(). */ + char *path_copy = strdup (path); + if (path_copy == NULL) + return ENOMEM; + + /* 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. */ + free (path_copy); + return ENOMEM; + } + + { + struct __spawn_action *rec; + + /* Add the new value. */ + rec = &file_actions->_actions[file_actions->_used]; + rec->tag = spawn_do_chdir; + rec->action.chdir_action.path = path_copy; + + /* Account for the new entry. */ + ++file_actions->_used; + + return 0; + } + } +#endif +} diff --git a/lib/spawn_faction_adddup2.c b/lib/spawn_faction_adddup2.c new file mode 100644 index 00000000000..c00b0b49668 --- /dev/null +++ b/lib/spawn_faction_adddup2.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include +#include + +#if !_LIBC +# define __sysconf(open_max) getdtablesize () +#endif + +#if REPLACE_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 !REPLACE_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/lib/spawn_faction_destroy.c b/lib/spawn_faction_destroy.c new file mode 100644 index 00000000000..e9985f4a0d4 --- /dev/null +++ b/lib/spawn_faction_destroy.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include + +#if REPLACE_POSIX_SPAWN +# include "spawn_int.h" +#endif + +/* Initialize data structure for file attribute for 'spawn' call. */ +int +posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions) +#undef posix_spawn_file_actions_destroy +{ +#if !REPLACE_POSIX_SPAWN + return posix_spawn_file_actions_destroy (file_actions); +#else + int i; + + /* Free the paths in the open actions. */ + for (i = 0; i < file_actions->_used; ++i) + { + struct __spawn_action *sa = &file_actions->_actions[i]; + switch (sa->tag) + { + case spawn_do_open: + free (sa->action.open_action.path); + break; + case spawn_do_chdir: + free (sa->action.chdir_action.path); + break; + default: + /* No cleanup required. */ + break; + } + } + + /* Free the array of actions. */ + free (file_actions->_actions); + + return 0; +#endif +} diff --git a/lib/spawn_faction_init.c b/lib/spawn_faction_init.c new file mode 100644 index 00000000000..135605fb8c6 --- /dev/null +++ b/lib/spawn_faction_init.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include + +#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/lib/spawn_int.h b/lib/spawn_int.h new file mode 100644 index 00000000000..60a94ddd55a --- /dev/null +++ b/lib/spawn_int.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2000, 2008-2020 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 . */ + +#include + +/* Data structure to contain the action information. */ +struct __spawn_action +{ + enum + { + spawn_do_close, + spawn_do_dup2, + spawn_do_open, + spawn_do_chdir, + spawn_do_fchdir + } tag; + + union + { + struct + { + int fd; + } close_action; + struct + { + int fd; + int newfd; + } dup2_action; + struct + { + int fd; + char *path; + int oflag; + mode_t mode; + } open_action; + struct + { + char *path; + } chdir_action; + struct + { + int fd; + } fchdir_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, const char *const argv[], + const char *const envp[], int use_path); diff --git a/lib/spawnattr_destroy.c b/lib/spawnattr_destroy.c new file mode 100644 index 00000000000..22a7d5a61a2 --- /dev/null +++ b/lib/spawnattr_destroy.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +/* 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/lib/spawnattr_init.c b/lib/spawnattr_init.c new file mode 100644 index 00000000000..99674488f81 --- /dev/null +++ b/lib/spawnattr_init.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include + +/* 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/lib/spawnattr_setdefault.c b/lib/spawnattr_setdefault.c new file mode 100644 index 00000000000..01c29e94847 --- /dev/null +++ b/lib/spawnattr_setdefault.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include + +/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */ +int +posix_spawnattr_setsigdefault (posix_spawnattr_t *attr, + const sigset_t *sigdefault) +{ + /* Copy the sigset_t data to the user buffer. */ + memcpy (&attr->_sd, sigdefault, sizeof (sigset_t)); + + return 0; +} diff --git a/lib/spawnattr_setflags.c b/lib/spawnattr_setflags.c new file mode 100644 index 00000000000..084d5bcea4c --- /dev/null +++ b/lib/spawnattr_setflags.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2000, 2004, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include +#include + +#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/lib/spawnattr_setpgroup.c b/lib/spawnattr_setpgroup.c new file mode 100644 index 00000000000..479457ad23e --- /dev/null +++ b/lib/spawnattr_setpgroup.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include + +/* Store process group ID in the attribute structure. */ +int +posix_spawnattr_setpgroup (posix_spawnattr_t *attr, pid_t pgroup) +{ + /* Store the process group ID. */ + attr->_pgrp = pgroup; + + return 0; +} diff --git a/lib/spawnattr_setsigmask.c b/lib/spawnattr_setsigmask.c new file mode 100644 index 00000000000..9b6f9ece38e --- /dev/null +++ b/lib/spawnattr_setsigmask.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000, 2009-2020 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 . */ + +#include + +/* Specification. */ +#include + +#include + +/* 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/lib/spawni.c b/lib/spawni.c new file mode 100644 index 00000000000..182d13ff24c --- /dev/null +++ b/lib/spawni.c @@ -0,0 +1,349 @@ +/* Guts of POSIX spawn interface. Generic POSIX.1 version. + Copyright (C) 2000-2006, 2008-2020 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 . */ + +#include + +/* Specification. */ +#include +#include "spawn_int.h" + +#include +#include + +#include +#ifndef O_LARGEFILE +# define O_LARGEFILE 0 +#endif + +#if _LIBC || HAVE_PATHS_H +# include +#else +# define _PATH_BSHELL BOURNE_SHELL +#endif + +#include +#include +#include +#include + +#if _LIBC +# include +#else +# define close_not_cancel close +# define open_not_cancel open +#endif + +#if _LIBC +# include +#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 +#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 __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, const char *const argv[], + const char *const envp[], int use_path) +{ + /* Not yet implemented. */ + return ENOSYS; +} + +#else + + +/* 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, const char *const argv[], + const 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; + + case spawn_do_chdir: + if (chdir (action->action.chdir_action.path) < 0) + /* The 'chdir' call failed. */ + _exit (SPAWN_ERROR); + break; + + case spawn_do_fchdir: + if (fchdir (action->action.fchdir_action.fd) < 0) + /* The 'fchdir' call failed. */ + _exit (SPAWN_ERROR); + break; + } + } + } + + if (! use_path || strchr (file, '/') != NULL) + { + /* The FILE parameter is actually a path. */ + execve (file, (char * const *) argv, (char * const *) 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, (char * const *) argv, (char * const *) 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/lib/strchrnul.c b/lib/strchrnul.c new file mode 100644 index 00000000000..858d66fab18 --- /dev/null +++ b/lib/strchrnul.c @@ -0,0 +1,142 @@ +/* Searching in a string. + Copyright (C) 2003, 2007-2020 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 . */ + +#include + +/* Specification. */ +#include + +/* Find the first occurrence of C in S or the final NUL byte. */ +char * +strchrnul (const char *s, int c_in) +{ + /* On 32-bit hardware, choosing longword to be a 32-bit unsigned + long instead of a 64-bit uintmax_t tends to give better + performance. On 64-bit hardware, unsigned long is generally 64 + bits already. Change this typedef to experiment with + performance. */ + typedef unsigned long int longword; + + const unsigned char *char_ptr; + const longword *longword_ptr; + longword repeated_one; + longword repeated_c; + unsigned char c; + + c = (unsigned char) c_in; + if (!c) + return rawmemchr (s, 0); + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + (size_t) char_ptr % sizeof (longword) != 0; + ++char_ptr) + if (!*char_ptr || *char_ptr == c) + return (char *) char_ptr; + + longword_ptr = (const longword *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + repeated_one = 0x01010101; + repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + } + + /* Instead of the traditional loop which tests each byte, we will + test a longword at a time. The tricky part is testing if *any of + the four* bytes in the longword in question are equal to NUL or + c. We first use an xor with repeated_c. This reduces the task + to testing whether *any of the four* bytes in longword1 or + longword2 is zero. + + Let's consider longword1. We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + The test whether any byte in longword1 or longword2 is zero is equivalent + to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine + this into a single test, whether (tmp1 | tmp2) is nonzero. + + This test can read more than one byte beyond the end of a string, + depending on where the terminating NUL is encountered. However, + this is considered safe since the initialization phase ensured + that the read will be aligned, therefore, the read will not cross + page boundaries and will not cause a fault. */ + + while (1) + { + longword longword1 = *longword_ptr ^ repeated_c; + longword longword2 = *longword_ptr; + + if (((((longword1 - repeated_one) & ~longword1) + | ((longword2 - repeated_one) & ~longword2)) + & (repeated_one << 7)) != 0) + break; + longword_ptr++; + } + + char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that one of the sizeof (longword) bytes + starting at char_ptr is == 0 or == c. On little-endian machines, + we could determine the first such byte without any further memory + accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. + Choose code that works in both cases. */ + + char_ptr = (unsigned char *) longword_ptr; + while (*char_ptr && (*char_ptr != c)) + char_ptr++; + return (char *) char_ptr; +} diff --git a/lib/strchrnul.valgrind b/lib/strchrnul.valgrind new file mode 100644 index 00000000000..a85608a7c76 --- /dev/null +++ b/lib/strchrnul.valgrind @@ -0,0 +1,28 @@ +# Suppress a valgrind message about use of uninitialized memory in strchrnul(). + +# Copyright (C) 2008-2020 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 . + +# This use is OK because it provides only a speedup. +{ + strchrnul-value4 + Memcheck:Value4 + fun:strchrnul +} +{ + strchrnul-value8 + Memcheck:Value8 + fun:strchrnul +} diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 0971636c33d..e2a44efe621 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -139,6 +139,18 @@ AC_DEFUN([gl_EARLY], # Code from module openat-h: # Code from module pathmax: # Code from module pipe2: + # Code from module posix_spawn: + # Code from module posix_spawn-internal: + # Code from module posix_spawn_file_actions_addchdir: + # Code from module posix_spawn_file_actions_adddup2: + # Code from module posix_spawn_file_actions_destroy: + # Code from module posix_spawn_file_actions_init: + # Code from module posix_spawnattr_destroy: + # Code from module posix_spawnattr_init: + # Code from module posix_spawnattr_setflags: + # Code from module posix_spawnattr_setpgroup: + # Code from module posix_spawnattr_setsigdefault: + # Code from module posix_spawnattr_setsigmask: # Code from module pselect: # Code from module pthread_sigmask: # Code from module qcopy-acl: @@ -147,7 +159,9 @@ AC_DEFUN([gl_EARLY], # Code from module readlinkat: # Code from module regex: # Code from module root-uid: + # Code from module sched: # Code from module scratch_buffer: + # Code from module sh-filename: # Code from module sig2str: # Code from module sigdescr_np: # Code from module signal-h: @@ -156,6 +170,7 @@ AC_DEFUN([gl_EARLY], # Code from module snippet/c++defs: # Code from module snippet/warn-on-use: # Code from module socklen: + # Code from module spawn: # Code from module ssize_t: # Code from module stat-time: # Code from module std-gnu11: @@ -165,6 +180,7 @@ AC_DEFUN([gl_EARLY], # Code from module stdio: # Code from module stdlib: # Code from module stpcpy: + # Code from module strchrnul: # Code from module string: # Code from module strnlen: # Code from module strtoimax: @@ -403,6 +419,61 @@ AC_DEFUN([gl_INIT], gl_PATHMAX gl_FUNC_PIPE2 gl_UNISTD_MODULE_INDICATOR([pipe2]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawn]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawn]) + gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 1; then + AC_LIBOBJ([spawn_faction_addchdir]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addchdir]) + gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then + AC_LIBOBJ([spawn_faction_adddup2]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_adddup2]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawn_faction_destroy]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_destroy]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawn_faction_init]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_init]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_destroy]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_destroy]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_init]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_init]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_setflags]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setflags]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_setpgroup]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setpgroup]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_setdefault]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setsigdefault]) + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawnattr_setsigmask]) + fi + gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setsigmask]) gl_FUNC_PSELECT if test $HAVE_PSELECT = 0 || test $REPLACE_PSELECT = 1; then AC_LIBOBJ([pselect]) @@ -430,6 +501,7 @@ AC_DEFUN([gl_INIT], AC_LIBOBJ([regex]) gl_PREREQ_REGEX fi + gl_SCHED_H gl_FUNC_SIG2STR if test $ac_cv_func_sig2str = no; then AC_LIBOBJ([sig2str]) @@ -442,6 +514,7 @@ AC_DEFUN([gl_INIT], gl_STRING_MODULE_INDICATOR([sigdescr_np]) gl_SIGNAL_H gl_TYPE_SOCKLEN_T + gl_SPAWN_H gt_TYPE_SSIZE_T gl_STAT_TIME gl_STAT_BIRTHTIME @@ -528,9 +601,12 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false gl_gnulib_enabled_open=false gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false + gl_gnulib_enabled_332607f759618fb73dfc3076748afea7=false gl_gnulib_enabled_rawmemchr=false gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false gl_gnulib_enabled_scratch_buffer=false + gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70=false + gl_gnulib_enabled_strchrnul=false gl_gnulib_enabled_strtoll=false gl_gnulib_enabled_utimens=false gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false @@ -685,6 +761,20 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true fi } + func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7 () + { + if ! $gl_gnulib_enabled_332607f759618fb73dfc3076748afea7; then + gl_POSIX_SPAWN + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + AC_LIBOBJ([spawni]) + gl_PREREQ_POSIX_SPAWN_INTERNAL + fi + gl_gnulib_enabled_332607f759618fb73dfc3076748afea7=true + func_gl_gnulib_m4code_open + func_gl_gnulib_m4code_cdeb0f2aaf9d280baa6526bfa1b07f70 + func_gl_gnulib_m4code_strchrnul + fi + } func_gl_gnulib_m4code_rawmemchr () { if ! $gl_gnulib_enabled_rawmemchr; then @@ -709,6 +799,28 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_scratch_buffer=true fi } + func_gl_gnulib_m4code_cdeb0f2aaf9d280baa6526bfa1b07f70 () + { + if ! $gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70; then + gl_SH_FILENAME + gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70=true + fi + } + func_gl_gnulib_m4code_strchrnul () + { + if ! $gl_gnulib_enabled_strchrnul; then + gl_FUNC_STRCHRNUL + if test $HAVE_STRCHRNUL = 0 || test $REPLACE_STRCHRNUL = 1; then + AC_LIBOBJ([strchrnul]) + gl_PREREQ_STRCHRNUL + fi + gl_STRING_MODULE_INDICATOR([strchrnul]) + gl_gnulib_enabled_strchrnul=true + if test $HAVE_STRCHRNUL = 0 || test $REPLACE_STRCHRNUL = 1; then + func_gl_gnulib_m4code_rawmemchr + fi + fi + } func_gl_gnulib_m4code_strtoll () { if ! $gl_gnulib_enabled_strtoll; then @@ -791,6 +903,12 @@ AC_DEFUN([gl_INIT], if case $host_os in mingw*) false;; *) test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1;; esac; then func_gl_gnulib_m4code_open fi + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then + func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7 + fi + if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then + func_gl_gnulib_m4code_getdtablesize + fi if test $HAVE_READLINKAT = 0 || test $REPLACE_READLINKAT = 1; then func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b fi @@ -830,9 +948,12 @@ AC_DEFUN([gl_INIT], AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31]) AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open]) AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7], [$gl_gnulib_enabled_332607f759618fb73dfc3076748afea7]) AM_CONDITIONAL([gl_GNULIB_ENABLED_rawmemchr], [$gl_gnulib_enabled_rawmemchr]) AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) AM_CONDITIONAL([gl_GNULIB_ENABLED_scratch_buffer], [$gl_gnulib_enabled_scratch_buffer]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70], [$gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_strchrnul], [$gl_gnulib_enabled_strchrnul]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) AM_CONDITIONAL([gl_GNULIB_ENABLED_utimens], [$gl_gnulib_enabled_utimens]) AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) @@ -1113,6 +1234,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/regex_internal.h lib/regexec.c lib/root-uid.h + lib/sched.in.h lib/scratch_buffer.h lib/set-permissions.c lib/sha1.c @@ -1125,6 +1247,20 @@ AC_DEFUN([gl_FILE_LIST], [ lib/sig2str.h lib/sigdescr_np.c lib/signal.in.h + lib/spawn.c + lib/spawn.in.h + lib/spawn_faction_addchdir.c + lib/spawn_faction_adddup2.c + lib/spawn_faction_destroy.c + lib/spawn_faction_init.c + lib/spawn_int.h + lib/spawnattr_destroy.c + lib/spawnattr_init.c + lib/spawnattr_setdefault.c + lib/spawnattr_setflags.c + lib/spawnattr_setpgroup.c + lib/spawnattr_setsigmask.c + lib/spawni.c lib/stat-time.c lib/stat-time.h lib/stdalign.in.h @@ -1135,6 +1271,8 @@ AC_DEFUN([gl_FILE_LIST], [ lib/stdlib.in.h lib/stpcpy.c lib/str-two-way.h + lib/strchrnul.c + lib/strchrnul.valgrind lib/strftime.h lib/string.in.h lib/strnlen.c @@ -1248,12 +1386,16 @@ AC_DEFUN([gl_FILE_LIST], [ m4/pathmax.m4 m4/pid_t.m4 m4/pipe2.m4 + m4/posix_spawn.m4 + m4/posix_spawn_faction_addchdir.m4 m4/pselect.m4 m4/pthread_sigmask.m4 m4/rawmemchr.m4 m4/readlink.m4 m4/readlinkat.m4 m4/regex.m4 + m4/sched_h.m4 + m4/sh-filename.m4 m4/sha1.m4 m4/sha256.m4 m4/sha512.m4 @@ -1261,6 +1403,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/sigdescr_np.m4 m4/signal_h.m4 m4/socklen.m4 + m4/spawn_h.m4 m4/ssize_t.m4 m4/stat-time.m4 m4/std-gnu11.m4 @@ -1270,6 +1413,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/stdio_h.m4 m4/stdlib_h.m4 m4/stpcpy.m4 + m4/strchrnul.m4 m4/string_h.m4 m4/strnlen.m4 m4/strtoimax.m4 diff --git a/m4/posix_spawn.m4 b/m4/posix_spawn.m4 new file mode 100644 index 00000000000..59e56fcb5f2 --- /dev/null +++ b/m4/posix_spawn.m4 @@ -0,0 +1,678 @@ +# posix_spawn.m4 serial 19 +dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Tests whether the entire posix_spawn facility is available. +AC_DEFUN([gl_POSIX_SPAWN], +[ + AC_REQUIRE([gl_POSIX_SPAWN_BODY]) +]) + +AC_DEFUN([gl_POSIX_SPAWN_BODY], +[ + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + AC_REQUIRE([gl_HAVE_POSIX_SPAWN]) + dnl Assume that when the main function exists, all the others, + dnl except posix_spawnattr_{get,set}sched*, are available as well. + dnl AC_CHECK_FUNCS_ONCE([posix_spawnp]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_init]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addclose]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_adddup2]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addopen]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_destroy]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_init]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getflags]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setflags]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getpgroup]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setpgroup]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigdefault]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigdefault]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigmask]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigmask]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_destroy]) + if test $ac_cv_func_posix_spawn = yes; then + m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR], + [dnl Module 'posix_spawn_file_actions_addchdir' is present. + AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir_np]) + if test $ac_cv_func_posix_spawn_file_actions_addchdir_np = no; then + dnl In order to implement the posix_spawn_file_actions_addchdir + dnl function, we need to replace the entire posix_spawn facility. + REPLACE_POSIX_SPAWN=1 + fi + ]) + m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR], + [dnl Module 'posix_spawn_file_actions_addfchdir' is present. + AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addfchdir_np]) + if test $ac_cv_func_posix_spawn_file_actions_addfchdir_np = no; then + dnl In order to implement the posix_spawn_file_actions_addfchdir + dnl function, we need to replace the entire posix_spawn facility. + REPLACE_POSIX_SPAWN=1 + fi + ]) + if test $REPLACE_POSIX_SPAWN = 0; then + gl_POSIX_SPAWN_WORKS + case "$gl_cv_func_posix_spawn_works" in + *yes) ;; + *) REPLACE_POSIX_SPAWN=1 ;; + esac + fi + if test $REPLACE_POSIX_SPAWN = 0; then + gl_POSIX_SPAWN_SECURE + case "$gl_cv_func_posix_spawn_secure_exec" in + *yes) ;; + *) REPLACE_POSIX_SPAWN=1 ;; + esac + case "$gl_cv_func_posix_spawnp_secure_exec" in + *yes) ;; + *) REPLACE_POSIX_SPAWN=1 ;; + esac + fi + if test $REPLACE_POSIX_SPAWN = 0; then + dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDULER + dnl evaluates to nonzero. + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedpolicy]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedpolicy]) + AC_CACHE_CHECK([whether posix_spawnattr_setschedpolicy is supported], + [gl_cv_func_spawnattr_setschedpolicy], + [AC_EGREP_CPP([POSIX scheduling supported], [ +#include +#if POSIX_SPAWN_SETSCHEDULER + POSIX scheduling supported +#endif +], + [gl_cv_func_spawnattr_setschedpolicy=yes], + [gl_cv_func_spawnattr_setschedpolicy=no]) + ]) + dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDPARAM + dnl evaluates to nonzero. + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedparam]) + dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedparam]) + AC_CACHE_CHECK([whether posix_spawnattr_setschedparam is supported], + [gl_cv_func_spawnattr_setschedparam], + [AC_EGREP_CPP([POSIX scheduling supported], [ +#include +#if POSIX_SPAWN_SETSCHEDPARAM + POSIX scheduling supported +#endif +], + [gl_cv_func_spawnattr_setschedparam=yes], + [gl_cv_func_spawnattr_setschedparam=no]) + ]) + fi + fi + if test $ac_cv_func_posix_spawn != yes || test $REPLACE_POSIX_SPAWN = 1; then + AC_DEFINE([REPLACE_POSIX_SPAWN], [1], + [Define if gnulib uses its own posix_spawn and posix_spawnp functions.]) + fi +]) + +dnl Test whether posix_spawn actually works. +dnl posix_spawn on AIX 5.3..6.1 has two bugs: +dnl 1) When it fails to execute the program, the child process exits with +dnl exit() rather than _exit(), which causes the stdio buffers to be +dnl flushed. Reported by Rainer Tammer. +dnl 2) The posix_spawn_file_actions_addopen function does not support file +dnl names that contain a '*'. +dnl posix_spawn on AIX 5.3..6.1 has also a third bug: It does not work +dnl when POSIX threads are used. But we don't test against this bug here. +AC_DEFUN([gl_POSIX_SPAWN_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether posix_spawn works], [gl_cv_func_posix_spawn_works], + [if test $cross_compiling = no; then + AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +]GL_MDA_DEFINES[ + +extern char **environ; + +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +#ifndef WTERMSIG +# define WTERMSIG(x) ((x) & 0x7f) +#endif +#ifndef WIFEXITED +# define WIFEXITED(x) (WTERMSIG (x) == 0) +#endif +#ifndef WEXITSTATUS +# define WEXITSTATUS(x) (((x) >> 8) & 0xff) +#endif + +#define CHILD_PROGRAM_FILENAME "/non/exist/ent" + +static int +fd_safer (int fd) +{ + if (0 <= fd && fd <= 2) + { + int f = fd_safer (dup (fd)); + int e = errno; + close (fd); + errno = e; + fd = f; + } + + return fd; +} + +int +main () +{ + char *argv[2] = { CHILD_PROGRAM_FILENAME, NULL }; + int ofd[2]; + sigset_t blocked_signals; + sigset_t fatal_signal_set; + posix_spawn_file_actions_t actions; + bool actions_allocated; + posix_spawnattr_t attrs; + bool attrs_allocated; + int err; + pid_t child; + int status; + int exitstatus; + + setvbuf (stdout, NULL, _IOFBF, 0); + puts ("This should be seen only once."); + if (pipe (ofd) < 0 || (ofd[1] = fd_safer (ofd[1])) < 0) + { + perror ("cannot create pipe"); + exit (1); + } + sigprocmask (SIG_SETMASK, NULL, &blocked_signals); + sigemptyset (&fatal_signal_set); + sigaddset (&fatal_signal_set, SIGINT); + sigaddset (&fatal_signal_set, SIGTERM); + sigaddset (&fatal_signal_set, SIGHUP); + sigaddset (&fatal_signal_set, SIGPIPE); + sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL); + actions_allocated = false; + attrs_allocated = false; + if ((err = posix_spawn_file_actions_init (&actions)) != 0 + || (actions_allocated = true, + (err = posix_spawn_file_actions_adddup2 (&actions, ofd[0], STDIN_FILENO)) != 0 + || (err = posix_spawn_file_actions_addclose (&actions, ofd[0])) != 0 + || (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0 + || (err = posix_spawnattr_init (&attrs)) != 0 + || (attrs_allocated = true, + (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0 + || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0) + || (err = posix_spawnp (&child, CHILD_PROGRAM_FILENAME, &actions, &attrs, argv, environ)) != 0)) + { + if (actions_allocated) + posix_spawn_file_actions_destroy (&actions); + if (attrs_allocated) + posix_spawnattr_destroy (&attrs); + sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); + if (err == ENOENT) + return 0; + else + { + errno = err; + perror ("subprocess failed"); + exit (1); + } + } + posix_spawn_file_actions_destroy (&actions); + posix_spawnattr_destroy (&attrs); + sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); + close (ofd[0]); + close (ofd[1]); + status = 0; + while (waitpid (child, &status, 0) != child) + ; + if (!WIFEXITED (status)) + { + fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status); + exit (1); + } + exitstatus = WEXITSTATUS (status); + if (exitstatus != 127) + { + fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus); + exit (1); + } + return 0; +} +]])], + [if test -s conftest$ac_exeext \ + && ./conftest$ac_exeext > conftest.out \ + && echo 'This should be seen only once.' > conftest.ok \ + && cmp conftest.out conftest.ok >/dev/null 2>&1; then + gl_cv_func_posix_spawn_works=yes + else + gl_cv_func_posix_spawn_works=no + fi], + [gl_cv_func_posix_spawn_works=no]) + if test $gl_cv_func_posix_spawn_works = yes; then + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +/* Test whether posix_spawn_file_actions_addopen supports filename arguments + that contain special characters such as '*'. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +]GL_MDA_DEFINES[ + +extern char **environ; + +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +#ifndef WTERMSIG +# define WTERMSIG(x) ((x) & 0x7f) +#endif +#ifndef WIFEXITED +# define WIFEXITED(x) (WTERMSIG (x) == 0) +#endif +#ifndef WEXITSTATUS +# define WEXITSTATUS(x) (((x) >> 8) & 0xff) +#endif + +#define CHILD_PROGRAM_FILENAME "conftest" +#define DATA_FILENAME "conftest%=*#?" + +static int +parent_main (void) +{ + FILE *fp; + char *argv[3] = { CHILD_PROGRAM_FILENAME, "-child", NULL }; + posix_spawn_file_actions_t actions; + bool actions_allocated; + int err; + pid_t child; + int status; + int exitstatus; + + /* Create a data file with specific contents. */ + fp = fopen (DATA_FILENAME, "wb"); + if (fp == NULL) + { + perror ("cannot create data file"); + return 1; + } + fwrite ("Halle Potta", 1, 11, fp); + if (fflush (fp) || fclose (fp)) + { + perror ("cannot prepare data file"); + return 2; + } + + /* Avoid reading from our stdin, as it could block. */ + freopen ("/dev/null", "rb", stdin); + + /* Test whether posix_spawn_file_actions_addopen with this file name + actually works, but spawning a child that reads from this file. */ + actions_allocated = false; + if ((err = posix_spawn_file_actions_init (&actions)) != 0 + || (actions_allocated = true, + (err = posix_spawn_file_actions_addopen (&actions, STDIN_FILENO, DATA_FILENAME, O_RDONLY, 0600)) != 0 + || (err = posix_spawn (&child, CHILD_PROGRAM_FILENAME, &actions, NULL, argv, environ)) != 0)) + { + if (actions_allocated) + posix_spawn_file_actions_destroy (&actions); + errno = err; + perror ("subprocess failed"); + return 3; + } + posix_spawn_file_actions_destroy (&actions); + status = 0; + while (waitpid (child, &status, 0) != child) + ; + if (!WIFEXITED (status)) + { + fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status); + return 4; + } + exitstatus = WEXITSTATUS (status); + if (exitstatus != 0) + { + fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus); + return 5; + } + return 0; +} + +static int +child_main (void) +{ + char buf[1024]; + + /* See if reading from STDIN_FILENO yields the expected contents. */ + if (fread (buf, 1, sizeof (buf), stdin) == 11 + && memcmp (buf, "Halle Potta", 11) == 0) + return 0; + else + return 8; +} + +static void +cleanup_then_die (int sig) +{ + /* Clean up data file. */ + unlink (DATA_FILENAME); + + /* Re-raise the signal and die from it. */ + signal (sig, SIG_DFL); + raise (sig); +} + +int +main (int argc, char *argv[]) +{ + int exitstatus; + + if (!(argc > 1 && strcmp (argv[1], "-child") == 0)) + { + /* This is the parent process. */ + signal (SIGINT, cleanup_then_die); + signal (SIGTERM, cleanup_then_die); + #ifdef SIGHUP + signal (SIGHUP, cleanup_then_die); + #endif + + exitstatus = parent_main (); + } + else + { + /* This is the child process. */ + + exitstatus = child_main (); + } + unlink (DATA_FILENAME); + return exitstatus; +} +]])], + [], + [gl_cv_func_posix_spawn_works=no]) + fi + else + case "$host_os" in + aix*) gl_cv_func_posix_spawn_works="guessing no";; + *) gl_cv_func_posix_spawn_works="guessing yes";; + esac + fi + ]) +]) + +dnl Test whether posix_spawn and posix_spawnp are secure. +AC_DEFUN([gl_POSIX_SPAWN_SECURE], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + dnl On many platforms, posix_spawn or posix_spawnp allow executing a + dnl script without a '#!' marker as a shell script. This is unsecure. + AC_CACHE_CHECK([whether posix_spawn rejects scripts without shebang], + [gl_cv_func_posix_spawn_secure_exec], + [echo ':' > conftest.scr + chmod a+x conftest.scr + AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include + #include + #include + #include + #include + int + main () + { + const char *prog_path = "./conftest.scr"; + const char *prog_argv[2] = { prog_path, NULL }; + const char *environment[2] = { "PATH=.", NULL }; + pid_t child; + int status; + int err = posix_spawn (&child, prog_path, NULL, NULL, + (char **) prog_argv, (char **) environment); + if (err == ENOEXEC) + return 0; + if (err != 0) + return 1; + status = 0; + while (waitpid (child, &status, 0) != child) + ; + if (!WIFEXITED (status)) + return 2; + if (WEXITSTATUS (status) != 127) + return 3; + return 0; + } + ]])], + [gl_cv_func_posix_spawn_secure_exec=yes], + [gl_cv_func_posix_spawn_secure_exec=no], + [case "$host_os" in + # Guess no on GNU/Hurd. + gnu*) + gl_cv_func_posix_spawn_secure_exec="guessing no" ;; + # Guess yes on all other platforms. + *) + gl_cv_func_posix_spawn_secure_exec="guessing yes" ;; + esac + ]) + rm -f conftest.scr + ]) + AC_CACHE_CHECK([whether posix_spawnp rejects scripts without shebang], + [gl_cv_func_posix_spawnp_secure_exec], + [echo ':' > conftest.scr + chmod a+x conftest.scr + AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include + #include + #include + #include + #include + int + main () + { + const char *prog_path = "./conftest.scr"; + const char *prog_argv[2] = { prog_path, NULL }; + const char *environment[2] = { "PATH=.", NULL }; + pid_t child; + int status; + int err = posix_spawnp (&child, prog_path, NULL, NULL, + (char **) prog_argv, (char **) environment); + if (err == ENOEXEC) + return 0; + if (err != 0) + return 1; + status = 0; + while (waitpid (child, &status, 0) != child) + ; + if (!WIFEXITED (status)) + return 2; + if (WEXITSTATUS (status) != 127) + return 3; + return 0; + } + ]])], + [gl_cv_func_posix_spawnp_secure_exec=yes], + [gl_cv_func_posix_spawnp_secure_exec=no], + [case "$host_os" in + # Guess yes on glibc systems (glibc >= 2.15 actually) except GNU/Hurd, + # musl libc, NetBSD. + *-gnu* | *-musl* | netbsd*) + gl_cv_func_posix_spawnp_secure_exec="guessing yes" ;; + # Guess no on GNU/Hurd, macOS, FreeBSD, OpenBSD, AIX, Solaris, Cygwin. + gnu* | darwin* | freebsd* | dragonfly* | openbsd* | aix* | solaris* | cygwin*) + gl_cv_func_posix_spawnp_secure_exec="guessing no" ;; + # If we don't know, obey --enable-cross-guesses. + *) + gl_cv_func_posix_spawnp_secure_exec="$gl_cross_guess_normal" ;; + esac + ]) + rm -f conftest.scr + ]) +]) + +# Prerequisites of lib/spawni.c. +AC_DEFUN([gl_PREREQ_POSIX_SPAWN_INTERNAL], +[ + AC_CHECK_HEADERS([paths.h]) + AC_CHECK_FUNCS([confstr sched_setparam sched_setscheduler setegid seteuid vfork]) +]) + +AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE], +[ + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + gl_POSIX_SPAWN + if test $REPLACE_POSIX_SPAWN = 1; then + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1 + else + dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_addclose + dnl succeeds even if the fd argument is out of range. + AC_CACHE_CHECK([whether posix_spawn_file_actions_addclose works], + [gl_cv_func_posix_spawn_file_actions_addclose_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +int main () +{ + posix_spawn_file_actions_t actions; + if (posix_spawn_file_actions_init (&actions) != 0) + return 1; + if (posix_spawn_file_actions_addclose (&actions, 10000000) == 0) + return 2; + return 0; +}]])], + [gl_cv_func_posix_spawn_file_actions_addclose_works=yes], + [gl_cv_func_posix_spawn_file_actions_addclose_works=no], + [# Guess no on musl libc and Solaris, yes otherwise. + case "$host_os" in + *-musl*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; + solaris*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; + # Guess no on native Windows. + mingw*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; + *) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_posix_spawn_file_actions_addclose_works" in + *yes) ;; + *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1 ;; + esac + fi +]) + +AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2], +[ + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + gl_POSIX_SPAWN + if test $REPLACE_POSIX_SPAWN = 1; then + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1 + else + dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_adddup2 + dnl succeeds even if the fd argument is out of range. + AC_CACHE_CHECK([whether posix_spawn_file_actions_adddup2 works], + [gl_cv_func_posix_spawn_file_actions_adddup2_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +int main () +{ + posix_spawn_file_actions_t actions; + if (posix_spawn_file_actions_init (&actions) != 0) + return 1; + if (posix_spawn_file_actions_adddup2 (&actions, 10000000, 2) == 0) + return 2; + return 0; +}]])], + [gl_cv_func_posix_spawn_file_actions_adddup2_works=yes], + [gl_cv_func_posix_spawn_file_actions_adddup2_works=no], + [# Guess no on musl libc and Solaris, yes otherwise. + case "$host_os" in + *-musl*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";; + solaris*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";; + # Guess no on native Windows. + mingw*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no" ;; + *) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing yes";; + esac + ]) + ]) + case "$gl_cv_func_posix_spawn_file_actions_adddup2_works" in + *yes) ;; + *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1 ;; + esac + fi +]) + +AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN], +[ + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + gl_POSIX_SPAWN + if test $REPLACE_POSIX_SPAWN = 1; then + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1 + else + dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_addopen + dnl succeeds even if the fd argument is out of range. + AC_CACHE_CHECK([whether posix_spawn_file_actions_addopen works], + [gl_cv_func_posix_spawn_file_actions_addopen_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +int main () +{ + posix_spawn_file_actions_t actions; + if (posix_spawn_file_actions_init (&actions) != 0) + return 1; + if (posix_spawn_file_actions_addopen (&actions, 10000000, "foo", 0, O_RDONLY) + == 0) + return 2; + return 0; +}]])], + [gl_cv_func_posix_spawn_file_actions_addopen_works=yes], + [gl_cv_func_posix_spawn_file_actions_addopen_works=no], + [# Guess no on musl libc and Solaris, yes otherwise. + case "$host_os" in + *-musl*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";; + solaris*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";; + # Guess no on native Windows. + mingw*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no" ;; + *) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing yes";; + esac + ]) + ]) + case "$gl_cv_func_posix_spawn_file_actions_addopen_works" in + *yes) ;; + *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1 ;; + esac + fi +]) diff --git a/m4/posix_spawn_faction_addchdir.m4 b/m4/posix_spawn_faction_addchdir.m4 new file mode 100644 index 00000000000..1ce7153d1d1 --- /dev/null +++ b/m4/posix_spawn_faction_addchdir.m4 @@ -0,0 +1,20 @@ +# posix_spawn_faction_addchdir.m4 serial 1 +dnl Copyright (C) 2018-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR], +[ + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + gl_POSIX_SPAWN + AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir posix_spawn_file_actions_addchdir_np]) + if test $ac_cv_func_posix_spawn_file_actions_addchdir = yes; then + dnl This function is not yet standardized. Therefore override the + dnl system's implementation always. + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1 + else + HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0 + fi +]) diff --git a/m4/sched_h.m4 b/m4/sched_h.m4 new file mode 100644 index 00000000000..af0c43de079 --- /dev/null +++ b/m4/sched_h.m4 @@ -0,0 +1,91 @@ +# sched_h.m4 serial 12 +dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Bruno Haible. + +AC_DEFUN([gl_SCHED_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_SCHED_H_DEFAULTS]) + + AC_REQUIRE([AC_CANONICAL_HOST]) + + AC_CHECK_HEADERS_ONCE([sys/cdefs.h]) + AC_CHECK_HEADERS([sched.h], [], [], + [[#if HAVE_SYS_CDEFS_H + #include + #endif + ]]) + gl_NEXT_HEADERS([sched.h]) + + if test "$ac_cv_header_sched_h" = yes; then + HAVE_SCHED_H=1 + else + HAVE_SCHED_H=0 + fi + AC_SUBST([HAVE_SCHED_H]) + + if test "$HAVE_SCHED_H" = 1; then + AC_CHECK_TYPE([struct sched_param], + [HAVE_STRUCT_SCHED_PARAM=1], [HAVE_STRUCT_SCHED_PARAM=0], + [[#if HAVE_SYS_CDEFS_H + #include + #endif + #include + ]]) + else + HAVE_STRUCT_SCHED_PARAM=0 + case "$host_os" in + os2*) + dnl On OS/2 kLIBC, struct sched_param is in spawn.h. + AC_CHECK_TYPE([struct sched_param], + [HAVE_STRUCT_SCHED_PARAM=1], [], + [#include ]) + ;; + vms) + dnl On OpenVMS 7.2 or newer, struct sched_param is in pthread.h. + AC_CHECK_TYPE([struct sched_param], + [HAVE_STRUCT_SCHED_PARAM=1], [], + [#include ]) + ;; + esac + fi + AC_SUBST([HAVE_STRUCT_SCHED_PARAM]) + + if test "$ac_cv_header_sys_cdefs_h" = yes; then + HAVE_SYS_CDEFS_H=1 + else + HAVE_SYS_CDEFS_H=0 + fi + AC_SUBST([HAVE_SYS_CDEFS_H]) + + dnl Ensure the type pid_t gets defined. + AC_REQUIRE([AC_TYPE_PID_T]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, if it is not common + dnl enough to be declared everywhere. + gl_WARN_ON_USE_PREPARE([[#include + ]], [sched_yield]) +]) + +AC_DEFUN([gl_SCHED_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_SCHED_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_SCHED_H_DEFAULTS], +[ + GNULIB_SCHED_YIELD=0; AC_SUBST([GNULIB_SCHED_YIELD]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_SCHED_YIELD=1; AC_SUBST([HAVE_SCHED_YIELD]) + REPLACE_SCHED_YIELD=0; AC_SUBST([REPLACE_SCHED_YIELD]) +]) diff --git a/m4/sh-filename.m4 b/m4/sh-filename.m4 new file mode 100644 index 00000000000..f7b31548e0d --- /dev/null +++ b/m4/sh-filename.m4 @@ -0,0 +1,22 @@ +# sh-filename.m4 serial 2 +dnl Copyright (C) 2018-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gl_SH_FILENAME], +[ + AH_VERBATIM([SH_FILENAME], +[/* File name of the Bourne shell. */ +#if defined __CYGWIN__ || defined __ANDROID__ +/* Omit the directory part because + - For 32-bit Cygwin programs in a 64-bit Cygwin environment, the Cygwin + mounts are not visible. + - On Android, /bin/sh does not exist. It's /system/bin/sh instead. */ +# define BOURNE_SHELL "sh" +#else +# define BOURNE_SHELL "/bin/sh" +#endif]) +]) diff --git a/m4/spawn_h.m4 b/m4/spawn_h.m4 new file mode 100644 index 00000000000..781f9f49652 --- /dev/null +++ b/m4/spawn_h.m4 @@ -0,0 +1,136 @@ +# spawn_h.m4 serial 18 +dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Bruno Haible. + +AC_DEFUN([gl_SPAWN_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_CHECK_NEXT_HEADERS([spawn.h]) + + if test $ac_cv_header_spawn_h = yes; then + HAVE_SPAWN_H=1 + AC_CHECK_TYPES([posix_spawnattr_t], [], [HAVE_POSIX_SPAWNATTR_T=0], [[ +#include + ]]) + AC_CHECK_TYPES([posix_spawn_file_actions_t], [], + [HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0], [[ +#include + ]]) + else + HAVE_SPAWN_H=0 + HAVE_POSIX_SPAWNATTR_T=0 + HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0 + fi + AC_SUBST([HAVE_SPAWN_H]) + + dnl Ensure the type pid_t gets defined. + AC_REQUIRE([AC_TYPE_PID_T]) + + dnl Ensure the type mode_t gets defined. + AC_REQUIRE([AC_TYPE_MODE_T]) + + AC_REQUIRE([gl_HAVE_POSIX_SPAWN]) + + AC_REQUIRE([AC_C_RESTRICT]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include + ]], [posix_spawn posix_spawnp posix_spawnattr_init posix_spawnattr_destroy + posix_spawnattr_getsigdefault posix_spawnattr_setsigdefault + posix_spawnattr_getsigmask posix_spawnattr_setsigmask + posix_spawnattr_getflags posix_spawnattr_setflags + posix_spawnattr_getpgroup posix_spawnattr_setpgroup + posix_spawnattr_getschedpolicy posix_spawnattr_setschedpolicy + posix_spawnattr_getschedparam posix_spawnattr_setschedparam + posix_spawn_file_actions_init posix_spawn_file_actions_destroy + posix_spawn_file_actions_addopen posix_spawn_file_actions_addclose + posix_spawn_file_actions_adddup2 posix_spawn_file_actions_addchdir + posix_spawn_file_actions_addfchdir]) +]) + +dnl Checks whether the system has the functions posix_spawn. +dnl Sets ac_cv_func_posix_spawn and HAVE_POSIX_SPAWN. +AC_DEFUN([gl_HAVE_POSIX_SPAWN], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + + LIB_POSIX_SPAWN= + AC_SUBST([LIB_POSIX_SPAWN]) + gl_saved_libs=$LIBS + AC_SEARCH_LIBS([posix_spawn], [rt], + [test "$ac_cv_search_posix_spawn" = "none required" || + LIB_POSIX_SPAWN=$ac_cv_search_posix_spawn]) + AC_CHECK_FUNCS([posix_spawn]) + LIBS=$gl_saved_libs + + if test $ac_cv_func_posix_spawn != yes; then + HAVE_POSIX_SPAWN=0 + fi +]) + +AC_DEFUN([gl_SPAWN_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_SPAWN_H_DEFAULTS], +[ + GNULIB_POSIX_SPAWN=0; AC_SUBST([GNULIB_POSIX_SPAWN]) + GNULIB_POSIX_SPAWNP=0; AC_SUBST([GNULIB_POSIX_SPAWNP]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN]) + GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY]) + GNULIB_POSIX_SPAWNATTR_INIT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_INIT]) + GNULIB_POSIX_SPAWNATTR_GETFLAGS=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETFLAGS]) + GNULIB_POSIX_SPAWNATTR_SETFLAGS=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETFLAGS]) + GNULIB_POSIX_SPAWNATTR_GETPGROUP=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETPGROUP]) + GNULIB_POSIX_SPAWNATTR_SETPGROUP=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETPGROUP]) + GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM]) + GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM]) + GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY]) + GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY]) + GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT]) + GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT]) + GNULIB_POSIX_SPAWNATTR_GETSIGMASK=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSIGMASK]) + GNULIB_POSIX_SPAWNATTR_SETSIGMASK=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSIGMASK]) + GNULIB_POSIX_SPAWNATTR_DESTROY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_DESTROY]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_POSIX_SPAWN=1; AC_SUBST([HAVE_POSIX_SPAWN]) + HAVE_POSIX_SPAWNATTR_T=1; AC_SUBST([HAVE_POSIX_SPAWNATTR_T]) + HAVE_POSIX_SPAWN_FILE_ACTIONS_T=1; + AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_T]) + HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1; + AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) + HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=1; + AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) + REPLACE_POSIX_SPAWN=0; AC_SUBST([REPLACE_POSIX_SPAWN]) + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0; + AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0; + AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]) + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0; + AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2]) + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0; + AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) + REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0; + AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN]) +]) diff --git a/m4/strchrnul.m4 b/m4/strchrnul.m4 new file mode 100644 index 00000000000..a18f0935a51 --- /dev/null +++ b/m4/strchrnul.m4 @@ -0,0 +1,50 @@ +# strchrnul.m4 serial 9 +dnl Copyright (C) 2003, 2007, 2009-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRCHRNUL], +[ + dnl Persuade glibc to declare strchrnul(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([strchrnul]) + if test $ac_cv_func_strchrnul = no; then + HAVE_STRCHRNUL=0 + else + AC_CACHE_CHECK([whether strchrnul works], + [gl_cv_func_strchrnul_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include /* for strchrnul */ +]], [[const char *buf = "a"; + return strchrnul (buf, 'b') != buf + 1; + ]])], + [gl_cv_func_strchrnul_works=yes], + [gl_cv_func_strchrnul_works=no], + [dnl Cygwin 1.7.9 introduced strchrnul, but it was broken until 1.7.10 + AC_EGREP_CPP([Lucky user], + [ +#if defined __CYGWIN__ + #include + #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 9) + Lucky user + #endif +#else + Lucky user +#endif + ], + [gl_cv_func_strchrnul_works="guessing yes"], + [gl_cv_func_strchrnul_works="guessing no"]) + ]) + ]) + case "$gl_cv_func_strchrnul_works" in + *yes) ;; + *) REPLACE_STRCHRNUL=1 ;; + esac + fi +]) + +# Prerequisites of lib/strchrnul.c. +AC_DEFUN([gl_PREREQ_STRCHRNUL], [:]) -- cgit v1.2.1 From 2c79a8f9210db01c86b0e5f236adeb0509519d30 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Fri, 25 Dec 2020 11:39:09 +0100 Subject: Use posix_spawn if possible. posix_spawn is less error-prone than vfork + execve, and can make better use of system-specific enhancements like 'clone' on Linux. Use it if we don't need to configure a pseudoterminal. * src/Makefile.in (LIB_POSIX_SPAWN): New variable. (LIBES): Use it. * src/callproc.c (emacs_spawn): Use posix_spawn on Unix-like system if we don't need to set up a pseudoterminal. --- src/Makefile.in | 4 +- src/callproc.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 150 insertions(+), 2 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index 39c0f12fe6c..aa93b604b07 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -239,6 +239,8 @@ LCMS2_CFLAGS = @LCMS2_CFLAGS@ LIBZ = @LIBZ@ +LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@ + ## system-specific libs for dynamic modules, else empty LIBMODULES = @LIBMODULES@ ## dynlib.o emacs-module.o if modules enabled, else empty @@ -535,7 +537,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(HARFBUZZ_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) $(LCMS2_LIBS) \ $(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) $(LIBMODULES) $(LIBSYSTEMD_LIBS) \ - $(JSON_LIBS) $(LIBGMP) + $(JSON_LIBS) $(LIBGMP) $(LIB_POSIX_SPAWN) ## FORCE it so that admin/unidata can decide whether this file is ## up-to-date. Although since charprop depends on bootstrap-emacs, diff --git a/src/callproc.c b/src/callproc.c index 3ecd6880274..a5056531e0b 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -27,6 +27,7 @@ along with GNU Emacs. If not, see . */ #include #include +#include #include "lisp.h" @@ -1228,12 +1229,156 @@ int emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, char **argv, char **envp, const char *cwd, const char *pty) { + /* `posix_spawn' is available on all Unix systems, either natively + or through Gnulib. Gnulib defines `posix_spawn' on Windows as + well, but doesn't implement it yet. So we fall back to our own + code on Windows. Because Gnulib always defines `posix_spawn', we + don't need to use conditional compilation here. */ + +#ifdef DOS_NT + enum { can_use_posix_spawn = false }; +#else + enum { can_use_posix_spawn = true }; +#endif + + /* `posix_spawn' doesn't yet support setting up pseudoterminals, so + we fall back to `vfork' if we're supposed to use a + pseudoterminal. */ + + bool use_posix_spawn = can_use_posix_spawn && pty == NULL; + + posix_spawn_file_actions_t actions; + posix_spawnattr_t attributes; + + if (use_posix_spawn) + { + /* Initialize optional attributes before blocking. */ + bool destroy_actions = false; + bool destroy_attributes = false; + + int error = posix_spawn_file_actions_init (&actions); + if (error != 0) + goto posix_spawn_init_failed; + destroy_actions = true; + + error = posix_spawnattr_init (&attributes); + if (error != 0) + goto posix_spawn_init_failed; + destroy_attributes = true; + + error = posix_spawn_file_actions_adddup2 (&actions, std_in, + STDIN_FILENO); + if (error != 0) + goto posix_spawn_init_failed; + + error = posix_spawn_file_actions_adddup2 (&actions, std_out, + STDOUT_FILENO); + if (error != 0) + goto posix_spawn_init_failed; + + error = posix_spawn_file_actions_adddup2 (&actions, + std_err < 0 ? std_out + : std_err, + STDERR_FILENO); + if (error != 0) + goto posix_spawn_init_failed; + + error = posix_spawn_file_actions_addchdir (&actions, cwd); + if (error != 0) + goto posix_spawn_init_failed; + + error = posix_spawnattr_setflags (&attributes, + POSIX_SPAWN_SETPGROUP + | POSIX_SPAWN_SETSIGDEF + | POSIX_SPAWN_SETSIGMASK); + if (error != 0) + goto posix_spawn_init_failed; + + error = posix_spawnattr_setpgroup (&attributes, 0); + if (error != 0) + goto posix_spawn_init_failed; + + sigset_t sigdefault; + sigemptyset (&sigdefault); + +#ifdef DARWIN_OS + /* Work around a macOS bug, where SIGCHLD is apparently + delivered to a vforked child instead of to its parent. See: + https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html + */ + sigaddset (&sigdefault, SIGCHLD); +#endif + + sigaddset (&sigdefault, SIGINT); + sigaddset (&sigdefault, SIGQUIT); +#ifdef SIGPROF + sigaddset (&sigdefault, SIGPROF); +#endif + + /* Emacs ignores SIGPIPE, but the child should not. */ + sigaddset (&sigdefault, SIGPIPE); + /* Likewise for SIGPROF. */ +#ifdef SIGPROF + sigaddset (&sigdefault, SIGPROF); +#endif + + error + = posix_spawnattr_setsigdefault (&attributes, &sigdefault); + if (error != 0) + goto posix_spawn_init_failed; + + /* Stop blocking SIGCHLD in the child. */ + sigset_t oldset; + error = pthread_sigmask (SIG_SETMASK, NULL, &oldset); + if (error != 0) + goto posix_spawn_init_failed; + error = posix_spawnattr_setsigmask (&attributes, &oldset); + if (error != 0) + goto posix_spawn_init_failed; + + goto next; + + posix_spawn_init_failed: + if (destroy_actions) + posix_spawn_file_actions_destroy (&actions); + if (destroy_attributes) + posix_spawnattr_destroy (&attributes); + eassert (0 < error); + return error; + } + sigset_t oldset; int pid; + int vfork_error; + next: block_input (); block_child_signal (&oldset); + if (use_posix_spawn) + { + vfork_error = posix_spawn (&pid, argv[0], &actions, &attributes, + argv, envp); + if (vfork_error != 0) + pid = -1; + + int error = posix_spawn_file_actions_destroy (&actions); + if (error != 0) + { + errno = error; + emacs_perror ("posix_spawn_file_actions_destroy"); + } + + error = posix_spawnattr_destroy (&attributes); + if (error != 0) + { + errno = error; + emacs_perror ("posix_spawnattr_destroy"); + } + + goto fork_done; + } + #ifndef WINDOWSNT /* vfork, and prevent local vars from being clobbered by the vfork. */ pid_t *volatile newpid_volatile = newpid; @@ -1375,8 +1520,9 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, /* Back in the parent process. */ - int vfork_error = pid < 0 ? errno : 0; + vfork_error = pid < 0 ? errno : 0; + fork_done: /* Stop blocking in the parent. */ unblock_child_signal (&oldset); unblock_input (); -- cgit v1.2.1 From e387371497d313f05b94e3bf42fe6685184605d1 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 14:50:25 +0200 Subject: Revert "Use posix_spawn if possible." This reverts commit 2c79a8f9210db01c86b0e5f236adeb0509519d30. It breaks the MinGW build in too many ways, and should be first tested on a branch. --- src/Makefile.in | 4 +- src/callproc.c | 148 +------------------------------------------------------- 2 files changed, 2 insertions(+), 150 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index aa93b604b07..39c0f12fe6c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -239,8 +239,6 @@ LCMS2_CFLAGS = @LCMS2_CFLAGS@ LIBZ = @LIBZ@ -LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@ - ## system-specific libs for dynamic modules, else empty LIBMODULES = @LIBMODULES@ ## dynlib.o emacs-module.o if modules enabled, else empty @@ -537,7 +535,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(HARFBUZZ_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(GETADDRINFO_A_LIBS) $(LCMS2_LIBS) \ $(NOTIFY_LIBS) $(LIB_MATH) $(LIBZ) $(LIBMODULES) $(LIBSYSTEMD_LIBS) \ - $(JSON_LIBS) $(LIBGMP) $(LIB_POSIX_SPAWN) + $(JSON_LIBS) $(LIBGMP) ## FORCE it so that admin/unidata can decide whether this file is ## up-to-date. Although since charprop depends on bootstrap-emacs, diff --git a/src/callproc.c b/src/callproc.c index a5056531e0b..3ecd6880274 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -27,7 +27,6 @@ along with GNU Emacs. If not, see . */ #include #include -#include #include "lisp.h" @@ -1229,156 +1228,12 @@ int emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, char **argv, char **envp, const char *cwd, const char *pty) { - /* `posix_spawn' is available on all Unix systems, either natively - or through Gnulib. Gnulib defines `posix_spawn' on Windows as - well, but doesn't implement it yet. So we fall back to our own - code on Windows. Because Gnulib always defines `posix_spawn', we - don't need to use conditional compilation here. */ - -#ifdef DOS_NT - enum { can_use_posix_spawn = false }; -#else - enum { can_use_posix_spawn = true }; -#endif - - /* `posix_spawn' doesn't yet support setting up pseudoterminals, so - we fall back to `vfork' if we're supposed to use a - pseudoterminal. */ - - bool use_posix_spawn = can_use_posix_spawn && pty == NULL; - - posix_spawn_file_actions_t actions; - posix_spawnattr_t attributes; - - if (use_posix_spawn) - { - /* Initialize optional attributes before blocking. */ - bool destroy_actions = false; - bool destroy_attributes = false; - - int error = posix_spawn_file_actions_init (&actions); - if (error != 0) - goto posix_spawn_init_failed; - destroy_actions = true; - - error = posix_spawnattr_init (&attributes); - if (error != 0) - goto posix_spawn_init_failed; - destroy_attributes = true; - - error = posix_spawn_file_actions_adddup2 (&actions, std_in, - STDIN_FILENO); - if (error != 0) - goto posix_spawn_init_failed; - - error = posix_spawn_file_actions_adddup2 (&actions, std_out, - STDOUT_FILENO); - if (error != 0) - goto posix_spawn_init_failed; - - error = posix_spawn_file_actions_adddup2 (&actions, - std_err < 0 ? std_out - : std_err, - STDERR_FILENO); - if (error != 0) - goto posix_spawn_init_failed; - - error = posix_spawn_file_actions_addchdir (&actions, cwd); - if (error != 0) - goto posix_spawn_init_failed; - - error = posix_spawnattr_setflags (&attributes, - POSIX_SPAWN_SETPGROUP - | POSIX_SPAWN_SETSIGDEF - | POSIX_SPAWN_SETSIGMASK); - if (error != 0) - goto posix_spawn_init_failed; - - error = posix_spawnattr_setpgroup (&attributes, 0); - if (error != 0) - goto posix_spawn_init_failed; - - sigset_t sigdefault; - sigemptyset (&sigdefault); - -#ifdef DARWIN_OS - /* Work around a macOS bug, where SIGCHLD is apparently - delivered to a vforked child instead of to its parent. See: - https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html - */ - sigaddset (&sigdefault, SIGCHLD); -#endif - - sigaddset (&sigdefault, SIGINT); - sigaddset (&sigdefault, SIGQUIT); -#ifdef SIGPROF - sigaddset (&sigdefault, SIGPROF); -#endif - - /* Emacs ignores SIGPIPE, but the child should not. */ - sigaddset (&sigdefault, SIGPIPE); - /* Likewise for SIGPROF. */ -#ifdef SIGPROF - sigaddset (&sigdefault, SIGPROF); -#endif - - error - = posix_spawnattr_setsigdefault (&attributes, &sigdefault); - if (error != 0) - goto posix_spawn_init_failed; - - /* Stop blocking SIGCHLD in the child. */ - sigset_t oldset; - error = pthread_sigmask (SIG_SETMASK, NULL, &oldset); - if (error != 0) - goto posix_spawn_init_failed; - error = posix_spawnattr_setsigmask (&attributes, &oldset); - if (error != 0) - goto posix_spawn_init_failed; - - goto next; - - posix_spawn_init_failed: - if (destroy_actions) - posix_spawn_file_actions_destroy (&actions); - if (destroy_attributes) - posix_spawnattr_destroy (&attributes); - eassert (0 < error); - return error; - } - sigset_t oldset; int pid; - int vfork_error; - next: block_input (); block_child_signal (&oldset); - if (use_posix_spawn) - { - vfork_error = posix_spawn (&pid, argv[0], &actions, &attributes, - argv, envp); - if (vfork_error != 0) - pid = -1; - - int error = posix_spawn_file_actions_destroy (&actions); - if (error != 0) - { - errno = error; - emacs_perror ("posix_spawn_file_actions_destroy"); - } - - error = posix_spawnattr_destroy (&attributes); - if (error != 0) - { - errno = error; - emacs_perror ("posix_spawnattr_destroy"); - } - - goto fork_done; - } - #ifndef WINDOWSNT /* vfork, and prevent local vars from being clobbered by the vfork. */ pid_t *volatile newpid_volatile = newpid; @@ -1520,9 +1375,8 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err, /* Back in the parent process. */ - vfork_error = pid < 0 ? errno : 0; + int vfork_error = pid < 0 ? errno : 0; - fork_done: /* Stop blocking in the parent. */ unblock_child_signal (&oldset); unblock_input (); -- cgit v1.2.1 From ecf84a22ee002112c265b028263f1db81e3271e1 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 14:51:20 +0200 Subject: Revert "Import posix_spawn from Gnulib." This reverts commit 3ba34141da77a24c251ee6530f3f72a366fe556e. It breaks the MinGW build and should be first tested on a branch. --- .gitignore | 2 - admin/merge-gnulib | 9 +- lib/gnulib.mk.in | 302 ------------ lib/sched.in.h | 99 ---- lib/spawn.c | 34 -- lib/spawn.in.h | 974 ------------------------------------- lib/spawn_faction_addchdir.c | 70 --- lib/spawn_faction_adddup2.c | 70 --- lib/spawn_faction_destroy.c | 61 --- lib/spawn_faction_init.c | 56 --- lib/spawn_int.h | 72 --- lib/spawnattr_destroy.c | 28 -- lib/spawnattr_init.c | 33 -- lib/spawnattr_setdefault.c | 33 -- lib/spawnattr_setflags.c | 45 -- lib/spawnattr_setpgroup.c | 32 -- lib/spawnattr_setsigmask.c | 33 -- lib/spawni.c | 349 ------------- lib/strchrnul.c | 142 ------ lib/strchrnul.valgrind | 28 -- m4/gnulib-comp.m4 | 144 ------ m4/posix_spawn.m4 | 678 -------------------------- m4/posix_spawn_faction_addchdir.m4 | 20 - m4/sched_h.m4 | 91 ---- m4/sh-filename.m4 | 22 - m4/spawn_h.m4 | 136 ------ m4/strchrnul.m4 | 50 -- 27 files changed, 1 insertion(+), 3612 deletions(-) delete mode 100644 lib/sched.in.h delete mode 100644 lib/spawn.c delete mode 100644 lib/spawn.in.h delete mode 100644 lib/spawn_faction_addchdir.c delete mode 100644 lib/spawn_faction_adddup2.c delete mode 100644 lib/spawn_faction_destroy.c delete mode 100644 lib/spawn_faction_init.c delete mode 100644 lib/spawn_int.h delete mode 100644 lib/spawnattr_destroy.c delete mode 100644 lib/spawnattr_init.c delete mode 100644 lib/spawnattr_setdefault.c delete mode 100644 lib/spawnattr_setflags.c delete mode 100644 lib/spawnattr_setpgroup.c delete mode 100644 lib/spawnattr_setsigmask.c delete mode 100644 lib/spawni.c delete mode 100644 lib/strchrnul.c delete mode 100644 lib/strchrnul.valgrind delete mode 100644 m4/posix_spawn.m4 delete mode 100644 m4/posix_spawn_faction_addchdir.m4 delete mode 100644 m4/sched_h.m4 delete mode 100644 m4/sh-filename.m4 delete mode 100644 m4/spawn_h.m4 delete mode 100644 m4/strchrnul.m4 diff --git a/.gitignore b/.gitignore index f9c0fae4f60..bf7e9349813 100644 --- a/.gitignore +++ b/.gitignore @@ -65,9 +65,7 @@ lib/ieee754.h lib/inttypes.h lib/libgnu.a lib/limits.h -lib/sched.h lib/signal.h -lib/spawn.h lib/std*.h !lib/std*.in.h !lib/stdio-impl.h diff --git a/admin/merge-gnulib b/admin/merge-gnulib index f1ed2da69e5..880dc5eef53 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -39,14 +39,7 @@ GNULIB_MODULES=' getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog ieee754-h ignore-value intprops largefile libgmp lstat manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime - pathmax pipe2 - posix_spawn posix_spawn_file_actions_addchdir - posix_spawn_file_actions_adddup2 posix_spawn_file_actions_destroy - posix_spawn_file_actions_init - posix_spawnattr_destroy posix_spawnattr_init - posix_spawnattr_setflags posix_spawnattr_setpgroup - posix_spawnattr_setsigdefault posix_spawnattr_setsigmask - pselect pthread_sigmask + pathmax pipe2 pselect pthread_sigmask qcopy-acl readlink readlinkat regex sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strnlen strtoimax symlink sys_stat sys_time diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 209c7eef299..a37f9278a31 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -130,17 +130,6 @@ # nstrftime \ # pathmax \ # pipe2 \ -# posix_spawn \ -# posix_spawn_file_actions_addchdir \ -# posix_spawn_file_actions_adddup2 \ -# posix_spawn_file_actions_destroy \ -# posix_spawn_file_actions_init \ -# posix_spawnattr_destroy \ -# posix_spawnattr_init \ -# posix_spawnattr_setflags \ -# posix_spawnattr_setpgroup \ -# posix_spawnattr_setsigdefault \ -# posix_spawnattr_setsigmask \ # pselect \ # pthread_sigmask \ # qcopy-acl \ @@ -404,29 +393,6 @@ GNULIB_PIPE2 = @GNULIB_PIPE2@ GNULIB_POPEN = @GNULIB_POPEN@ GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@ GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@ -GNULIB_POSIX_SPAWN = @GNULIB_POSIX_SPAWN@ -GNULIB_POSIX_SPAWNATTR_DESTROY = @GNULIB_POSIX_SPAWNATTR_DESTROY@ -GNULIB_POSIX_SPAWNATTR_GETFLAGS = @GNULIB_POSIX_SPAWNATTR_GETFLAGS@ -GNULIB_POSIX_SPAWNATTR_GETPGROUP = @GNULIB_POSIX_SPAWNATTR_GETPGROUP@ -GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@ -GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@ -GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@ -GNULIB_POSIX_SPAWNATTR_GETSIGMASK = @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@ -GNULIB_POSIX_SPAWNATTR_INIT = @GNULIB_POSIX_SPAWNATTR_INIT@ -GNULIB_POSIX_SPAWNATTR_SETFLAGS = @GNULIB_POSIX_SPAWNATTR_SETFLAGS@ -GNULIB_POSIX_SPAWNATTR_SETPGROUP = @GNULIB_POSIX_SPAWNATTR_SETPGROUP@ -GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@ -GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@ -GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@ -GNULIB_POSIX_SPAWNATTR_SETSIGMASK = @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@ -GNULIB_POSIX_SPAWNP = @GNULIB_POSIX_SPAWNP@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@ -GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@ GNULIB_PREAD = @GNULIB_PREAD@ GNULIB_PRINTF = @GNULIB_PRINTF@ GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@ @@ -459,7 +425,6 @@ GNULIB_RMDIR = @GNULIB_RMDIR@ GNULIB_RPMATCH = @GNULIB_RPMATCH@ GNULIB_SCANDIR = @GNULIB_SCANDIR@ GNULIB_SCANF = @GNULIB_SCANF@ -GNULIB_SCHED_YIELD = @GNULIB_SCHED_YIELD@ GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@ GNULIB_SELECT = @GNULIB_SELECT@ GNULIB_SETENV = @GNULIB_SETENV@ @@ -669,11 +634,6 @@ HAVE_POPEN = @HAVE_POPEN@ HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ -HAVE_POSIX_SPAWN = @HAVE_POSIX_SPAWN@ -HAVE_POSIX_SPAWNATTR_T = @HAVE_POSIX_SPAWNATTR_T@ -HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -HAVE_POSIX_SPAWN_FILE_ACTIONS_T = @HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ HAVE_PREAD = @HAVE_PREAD@ HAVE_PSELECT = @HAVE_PSELECT@ HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@ @@ -695,8 +655,6 @@ HAVE_RENAMEAT = @HAVE_RENAMEAT@ HAVE_REWINDDIR = @HAVE_REWINDDIR@ HAVE_RPMATCH = @HAVE_RPMATCH@ HAVE_SCANDIR = @HAVE_SCANDIR@ -HAVE_SCHED_H = @HAVE_SCHED_H@ -HAVE_SCHED_YIELD = @HAVE_SCHED_YIELD@ HAVE_SECURE_GETENV = @HAVE_SECURE_GETENV@ HAVE_SETENV = @HAVE_SETENV@ HAVE_SETHOSTNAME = @HAVE_SETHOSTNAME@ @@ -711,7 +669,6 @@ HAVE_SIGNED_WCHAR_T = @HAVE_SIGNED_WCHAR_T@ HAVE_SIGNED_WINT_T = @HAVE_SIGNED_WINT_T@ HAVE_SIGSET_T = @HAVE_SIGSET_T@ HAVE_SLEEP = @HAVE_SLEEP@ -HAVE_SPAWN_H = @HAVE_SPAWN_H@ HAVE_STDINT_H = @HAVE_STDINT_H@ HAVE_STPCPY = @HAVE_STPCPY@ HAVE_STPNCPY = @HAVE_STPNCPY@ @@ -726,7 +683,6 @@ HAVE_STRTOLD = @HAVE_STRTOLD@ HAVE_STRTOLL = @HAVE_STRTOLL@ HAVE_STRTOULL = @HAVE_STRTOULL@ HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@ -HAVE_STRUCT_SCHED_PARAM = @HAVE_STRUCT_SCHED_PARAM@ HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@ HAVE_STRUCT_TIMEVAL = @HAVE_STRUCT_TIMEVAL@ HAVE_STRVERSCMP = @HAVE_STRVERSCMP@ @@ -826,7 +782,6 @@ LIB_EACCESS = @LIB_EACCESS@ LIB_EXECINFO = @LIB_EXECINFO@ LIB_GETRANDOM = @LIB_GETRANDOM@ LIB_MATH = @LIB_MATH@ -LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@ LIB_PTHREAD = @LIB_PTHREAD@ LIB_PTHREAD_SIGMASK = @LIB_PTHREAD_SIGMASK@ LIB_TIMER_TIME = @LIB_TIMER_TIME@ @@ -850,9 +805,7 @@ NEXT_AS_FIRST_DIRECTIVE_FCNTL_H = @NEXT_AS_FIRST_DIRECTIVE_FCNTL_H@ NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@ NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@ NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@ -NEXT_AS_FIRST_DIRECTIVE_SCHED_H = @NEXT_AS_FIRST_DIRECTIVE_SCHED_H@ NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@ -NEXT_AS_FIRST_DIRECTIVE_SPAWN_H = @NEXT_AS_FIRST_DIRECTIVE_SPAWN_H@ NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ NEXT_AS_FIRST_DIRECTIVE_STDINT_H = @NEXT_AS_FIRST_DIRECTIVE_STDINT_H@ NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@ @@ -871,9 +824,7 @@ NEXT_FCNTL_H = @NEXT_FCNTL_H@ NEXT_GETOPT_H = @NEXT_GETOPT_H@ NEXT_INTTYPES_H = @NEXT_INTTYPES_H@ NEXT_LIMITS_H = @NEXT_LIMITS_H@ -NEXT_SCHED_H = @NEXT_SCHED_H@ NEXT_SIGNAL_H = @NEXT_SIGNAL_H@ -NEXT_SPAWN_H = @NEXT_SPAWN_H@ NEXT_STDDEF_H = @NEXT_STDDEF_H@ NEXT_STDINT_H = @NEXT_STDINT_H@ NEXT_STDIO_H = @NEXT_STDIO_H@ @@ -995,12 +946,6 @@ REPLACE_OPENDIR = @REPLACE_OPENDIR@ REPLACE_PERROR = @REPLACE_PERROR@ REPLACE_POPEN = @REPLACE_POPEN@ REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ -REPLACE_POSIX_SPAWN = @REPLACE_POSIX_SPAWN@ -REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ -REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ -REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PRINTF = @REPLACE_PRINTF@ REPLACE_PSELECT = @REPLACE_PSELECT@ @@ -1022,7 +967,6 @@ REPLACE_REMOVE = @REPLACE_REMOVE@ REPLACE_RENAME = @REPLACE_RENAME@ REPLACE_RENAMEAT = @REPLACE_RENAMEAT@ REPLACE_RMDIR = @REPLACE_RMDIR@ -REPLACE_SCHED_YIELD = @REPLACE_SCHED_YIELD@ REPLACE_SELECT = @REPLACE_SELECT@ REPLACE_SETENV = @REPLACE_SETENV@ REPLACE_SETSTATE = @REPLACE_SETSTATE@ @@ -1164,13 +1108,11 @@ gamegroup = @gamegroup@ gameuser = @gameuser@ gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7 = @gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7@ gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b = @gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b@ -gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7 = @gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7@ gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31 = @gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31@ gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c = @gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c@ gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec = @gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec@ gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1@ gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@ -gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70 = @gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70@ gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@ gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@ gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@ @@ -1182,7 +1124,6 @@ gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@ gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@ gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@ gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@ -gl_GNULIB_ENABLED_strchrnul = @gl_GNULIB_ENABLED_strchrnul@ gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@ gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@ gl_LIBOBJS = @gl_LIBOBJS@ @@ -2329,140 +2270,6 @@ libgnu_a_SOURCES += pipe2.c endif ## end gnulib module pipe2 -## begin gnulib module posix_spawn -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn)) - - -EXTRA_DIST += spawn.c - -EXTRA_libgnu_a_SOURCES += spawn.c - -endif -## end gnulib module posix_spawn - -## begin gnulib module posix_spawn-internal -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn-internal)) - -ifneq (,$(gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7)) - -endif -EXTRA_DIST += spawn_int.h spawni.c - -EXTRA_libgnu_a_SOURCES += spawni.c - -endif -## end gnulib module posix_spawn-internal - -## begin gnulib module posix_spawn_file_actions_addchdir -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_addchdir)) - - -EXTRA_DIST += spawn_faction_addchdir.c spawn_int.h - -EXTRA_libgnu_a_SOURCES += spawn_faction_addchdir.c - -endif -## end gnulib module posix_spawn_file_actions_addchdir - -## begin gnulib module posix_spawn_file_actions_adddup2 -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_adddup2)) - - -EXTRA_DIST += spawn_faction_adddup2.c spawn_int.h - -EXTRA_libgnu_a_SOURCES += spawn_faction_adddup2.c - -endif -## end gnulib module posix_spawn_file_actions_adddup2 - -## begin gnulib module posix_spawn_file_actions_destroy -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_destroy)) - - -EXTRA_DIST += spawn_faction_destroy.c - -EXTRA_libgnu_a_SOURCES += spawn_faction_destroy.c - -endif -## end gnulib module posix_spawn_file_actions_destroy - -## begin gnulib module posix_spawn_file_actions_init -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_init)) - - -EXTRA_DIST += spawn_faction_init.c spawn_int.h - -EXTRA_libgnu_a_SOURCES += spawn_faction_init.c - -endif -## end gnulib module posix_spawn_file_actions_init - -## begin gnulib module posix_spawnattr_destroy -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_destroy)) - - -EXTRA_DIST += spawnattr_destroy.c - -EXTRA_libgnu_a_SOURCES += spawnattr_destroy.c - -endif -## end gnulib module posix_spawnattr_destroy - -## begin gnulib module posix_spawnattr_init -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_init)) - - -EXTRA_DIST += spawnattr_init.c - -EXTRA_libgnu_a_SOURCES += spawnattr_init.c - -endif -## end gnulib module posix_spawnattr_init - -## begin gnulib module posix_spawnattr_setflags -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setflags)) - - -EXTRA_DIST += spawnattr_setflags.c - -EXTRA_libgnu_a_SOURCES += spawnattr_setflags.c - -endif -## end gnulib module posix_spawnattr_setflags - -## begin gnulib module posix_spawnattr_setpgroup -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setpgroup)) - - -EXTRA_DIST += spawnattr_setpgroup.c - -EXTRA_libgnu_a_SOURCES += spawnattr_setpgroup.c - -endif -## end gnulib module posix_spawnattr_setpgroup - -## begin gnulib module posix_spawnattr_setsigdefault -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigdefault)) - - -EXTRA_DIST += spawnattr_setdefault.c - -EXTRA_libgnu_a_SOURCES += spawnattr_setdefault.c - -endif -## end gnulib module posix_spawnattr_setsigdefault - -## begin gnulib module posix_spawnattr_setsigmask -ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigmask)) - - -EXTRA_DIST += spawnattr_setsigmask.c - -EXTRA_libgnu_a_SOURCES += spawnattr_setsigmask.c - -endif -## end gnulib module posix_spawnattr_setsigmask - ## begin gnulib module pselect ifeq (,$(OMIT_GNULIB_MODULE_pselect)) @@ -2550,39 +2357,6 @@ EXTRA_DIST += root-uid.h endif ## end gnulib module root-uid -## begin gnulib module sched -ifeq (,$(OMIT_GNULIB_MODULE_sched)) - -BUILT_SOURCES += sched.h - -# We need the following in order to create a replacement for when -# the system doesn't have one. -sched.h: sched.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) - $(AM_V_GEN)rm -f $@-t $@ && \ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''GUARD_PREFIX''@|GL|g' \ - -e 's|@''HAVE_SCHED_H''@|$(HAVE_SCHED_H)|g' \ - -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \ - -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ - -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ - -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ - -e 's|@''NEXT_SCHED_H''@|$(NEXT_SCHED_H)|g' \ - -e 's|@''HAVE_STRUCT_SCHED_PARAM''@|$(HAVE_STRUCT_SCHED_PARAM)|g' \ - -e 's/@''GNULIB_SCHED_YIELD''@/$(GNULIB_SCHED_YIELD)/g' \ - -e 's|@''HAVE_SCHED_YIELD''@|$(HAVE_SCHED_YIELD)|g' \ - -e 's|@''REPLACE_SCHED_YIELD''@|$(REPLACE_SCHED_YIELD)|g' \ - -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ - -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ - < $(srcdir)/sched.in.h; \ - } > $@-t && \ - mv $@-t $@ -MOSTLYCLEANFILES += sched.h sched.h-t - -EXTRA_DIST += sched.in.h - -endif -## end gnulib module sched - ## begin gnulib module scratch_buffer ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer)) @@ -2717,69 +2491,6 @@ EXTRA_DIST += warn-on-use.h endif ## end gnulib module snippet/warn-on-use -## begin gnulib module spawn -ifeq (,$(OMIT_GNULIB_MODULE_spawn)) - -BUILT_SOURCES += spawn.h - -# We need the following in order to create a replacement for when -# the system doesn't have one. -spawn.h: spawn.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) - $(AM_V_GEN)rm -f $@-t $@ && \ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''GUARD_PREFIX''@|GL|g' \ - -e 's|@''HAVE_SPAWN_H''@|$(HAVE_SPAWN_H)|g' \ - -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ - -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ - -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ - -e 's|@''NEXT_SPAWN_H''@|$(NEXT_SPAWN_H)|g' \ - -e 's/@''GNULIB_POSIX_SPAWN''@/$(GNULIB_POSIX_SPAWN)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNP''@/$(GNULIB_POSIX_SPAWNP)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)/g' \ - -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_INIT''@/$(GNULIB_POSIX_SPAWNATTR_INIT)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_GETFLAGS)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_SETFLAGS)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_GETPGROUP)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_SETPGROUP)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGMASK)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGMASK)/g' \ - -e 's/@''GNULIB_POSIX_SPAWNATTR_DESTROY''@/$(GNULIB_POSIX_SPAWNATTR_DESTROY)/g' \ - -e 's|@''HAVE_POSIX_SPAWN''@|$(HAVE_POSIX_SPAWN)|g' \ - -e 's|@''HAVE_POSIX_SPAWNATTR_T''@|$(HAVE_POSIX_SPAWNATTR_T)|g' \ - -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_T''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_T)|g' \ - -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \ - -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN''@|$(REPLACE_POSIX_SPAWN)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \ - -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)|g' \ - -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ - -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ - -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ - < $(srcdir)/spawn.in.h; \ - } > $@-t && \ - mv $@-t $@ -MOSTLYCLEANFILES += spawn.h spawn.h-t - -EXTRA_DIST += spawn.in.h - -endif -## end gnulib module spawn - ## begin gnulib module stat-time ifeq (,$(OMIT_GNULIB_MODULE_stat-time)) @@ -3174,19 +2885,6 @@ EXTRA_libgnu_a_SOURCES += stpcpy.c endif ## end gnulib module stpcpy -## begin gnulib module strchrnul -ifeq (,$(OMIT_GNULIB_MODULE_strchrnul)) - -ifneq (,$(gl_GNULIB_ENABLED_strchrnul)) - -endif -EXTRA_DIST += strchrnul.c strchrnul.valgrind - -EXTRA_libgnu_a_SOURCES += strchrnul.c - -endif -## end gnulib module strchrnul - ## begin gnulib module string ifeq (,$(OMIT_GNULIB_MODULE_string)) diff --git a/lib/sched.in.h b/lib/sched.in.h deleted file mode 100644 index 4ee9defe82b..00000000000 --- a/lib/sched.in.h +++ /dev/null @@ -1,99 +0,0 @@ -/* A GNU-like . - Copyright (C) 2008-2020 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 . */ - -#ifndef _@GUARD_PREFIX@_SCHED_H - -#if __GNUC__ >= 3 -@PRAGMA_SYSTEM_HEADER@ -#endif -@PRAGMA_COLUMNS@ - -/* The include_next requires a split double-inclusion guard. */ -#if @HAVE_SCHED_H@ -# if @HAVE_SYS_CDEFS_H@ -# include -# endif -# @INCLUDE_NEXT@ @NEXT_SCHED_H@ -#endif - -#ifndef _@GUARD_PREFIX@_SCHED_H -#define _@GUARD_PREFIX@_SCHED_H - -/* Get pid_t. - This is needed on glibc 2.11 (see - glibc bug ) - and Mac OS X 10.5. */ -#include - -#ifdef __KLIBC__ -/* On OS/2 kLIBC, struct sched_param is in spawn.h. */ -# include -#endif - -#ifdef __VMS -/* On OpenVMS, struct sched_param is in . */ -# include -#endif - -/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ - -/* The definition of _GL_WARN_ON_USE is copied here. */ - -#if !@HAVE_STRUCT_SCHED_PARAM@ - -# if !GNULIB_defined_struct_sched_param -struct sched_param -{ - int sched_priority; -}; -# define GNULIB_defined_struct_sched_param 1 -# endif - -#endif - -#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER) -# define SCHED_FIFO 1 -# define SCHED_RR 2 -# define SCHED_OTHER 0 -#endif - -#if @GNULIB_SCHED_YIELD@ -# if @REPLACE_SCHED_YIELD@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef sched_yield -# define sched_yield rpl_sched_yield -# endif -_GL_FUNCDECL_RPL (sched_yield, int, (void)); -_GL_CXXALIAS_RPL (sched_yield, int, (void)); -# else -# if !@HAVE_SCHED_YIELD@ -_GL_FUNCDECL_SYS (sched_yield, int, (void)); -# endif -_GL_CXXALIAS_SYS (sched_yield, int, (void)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (sched_yield); -# endif -#elif defined GNULIB_POSIXCHECK -# undef sched_yield -# if HAVE_RAW_DECL_SCHED_YIELD -_GL_WARN_ON_USE (sched_yield, "sched_yield is not portable - " - "use gnulib module sched_yield for portability"); -# endif -#endif - -#endif /* _@GUARD_PREFIX@_SCHED_H */ -#endif /* _@GUARD_PREFIX@_SCHED_H */ diff --git a/lib/spawn.c b/lib/spawn.c deleted file mode 100644 index b658453a10f..00000000000 --- a/lib/spawn.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include "spawn_int.h" - -/* Spawn a new process executing PATH with the attributes describes in *ATTRP. - Before running the process perform the actions described in FILE-ACTIONS. */ -int -posix_spawn (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[]) -{ - return __spawni (pid, path, file_actions, attrp, - (const char * const *) argv, (const char * const *) envp, 0); -} diff --git a/lib/spawn.in.h b/lib/spawn.in.h deleted file mode 100644 index 537fac7dbc5..00000000000 --- a/lib/spawn.in.h +++ /dev/null @@ -1,974 +0,0 @@ -/* Definitions for POSIX spawn interface. - Copyright (C) 2000, 2003-2004, 2008-2020 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 . */ - -#ifndef _@GUARD_PREFIX@_SPAWN_H - -#if __GNUC__ >= 3 -@PRAGMA_SYSTEM_HEADER@ -#endif -@PRAGMA_COLUMNS@ - -/* The include_next requires a split double-inclusion guard. */ -#if @HAVE_SPAWN_H@ -# @INCLUDE_NEXT@ @NEXT_SPAWN_H@ -#endif - -#ifndef _@GUARD_PREFIX@_SPAWN_H -#define _@GUARD_PREFIX@_SPAWN_H - -/* Get definitions of 'struct sched_param' and 'sigset_t'. - But avoid namespace pollution on glibc systems. */ -#if !(defined __GLIBC__ && !defined __UCLIBC__) -# include -# include -#endif - -#include - -#ifndef __THROW -# define __THROW -#endif - -/* For plain 'restrict', use glibc's __restrict if defined. - Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have - "restrict", and "configure" may have defined "restrict". - Other compilers use __restrict, __restrict__, and _Restrict, and - 'configure' might #define 'restrict' to those words, so pick a - different name. */ -#ifndef _Restrict_ -# if defined __restrict \ - || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \ - || __clang_major__ >= 3 -# define _Restrict_ __restrict -# elif 199901L <= __STDC_VERSION__ || defined restrict -# define _Restrict_ restrict -# else -# define _Restrict_ -# endif -#endif -/* For the ISO C99 syntax - array_name[restrict] - use glibc's __restrict_arr if available. - Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode). - Other ISO C99 compilers support it as well. */ -#ifndef _Restrict_arr_ -# ifdef __restrict_arr -# define _Restrict_arr_ __restrict_arr -# elif ((199901L <= __STDC_VERSION__ \ - || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \ - || __clang_major__ >= 3) \ - && !defined __cplusplus) -# define _Restrict_arr_ _Restrict_ -# else -# define _Restrict_arr_ -# endif -#endif - -/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ - -/* The definition of _GL_ARG_NONNULL is copied here. */ - -/* The definition of _GL_WARN_ON_USE is copied here. */ - - -/* Data structure to contain attributes for thread creation. */ -#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWNATTR_T@ && !@HAVE_POSIX_SPAWN@) -# define posix_spawnattr_t rpl_posix_spawnattr_t -#endif -#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWNATTR_T@ || !@HAVE_POSIX_SPAWN@ -# if !GNULIB_defined_posix_spawnattr_t -typedef struct -{ - short int _flags; - pid_t _pgrp; - sigset_t _sd; - sigset_t _ss; - struct sched_param _sp; - int _policy; - int __pad[16]; -} posix_spawnattr_t; -# define GNULIB_defined_posix_spawnattr_t 1 -# endif -#endif - - -/* Data structure to contain information about the actions to be - performed in the new process with respect to file descriptors. */ -#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ && !@HAVE_POSIX_SPAWN@) -# define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t -#endif -#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ || !@HAVE_POSIX_SPAWN@ -# if !GNULIB_defined_posix_spawn_file_actions_t -typedef struct -{ - int _allocated; - int _used; - struct __spawn_action *_actions; - int __pad[16]; -} posix_spawn_file_actions_t; -# define GNULIB_defined_posix_spawn_file_actions_t 1 -# endif -#endif - - -/* Flags to be set in the 'posix_spawnattr_t'. */ -#if @HAVE_POSIX_SPAWN@ -/* Use the values from the system, but provide the missing ones. */ -# ifndef POSIX_SPAWN_SETSCHEDPARAM -# define POSIX_SPAWN_SETSCHEDPARAM 0 -# endif -# ifndef POSIX_SPAWN_SETSCHEDULER -# define POSIX_SPAWN_SETSCHEDULER 0 -# endif -#else -# if @REPLACE_POSIX_SPAWN@ -/* Use the values from the system, for better compatibility. */ -/* But this implementation does not support AIX extensions. */ -# undef POSIX_SPAWN_FORK_HANDLERS -# else -# define POSIX_SPAWN_RESETIDS 0x01 -# define POSIX_SPAWN_SETPGROUP 0x02 -# define POSIX_SPAWN_SETSIGDEF 0x04 -# define POSIX_SPAWN_SETSIGMASK 0x08 -# define POSIX_SPAWN_SETSCHEDPARAM 0x10 -# define POSIX_SPAWN_SETSCHEDULER 0x20 -# endif -#endif -/* A GNU extension. Use the next free bit position. */ -#ifndef POSIX_SPAWN_USEVFORK -# define POSIX_SPAWN_USEVFORK \ - ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \ - | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \ - | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \ - | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \ - | POSIX_SPAWN_SETSCHEDPARAM \ - | (POSIX_SPAWN_SETSCHEDPARAM > 0 ? POSIX_SPAWN_SETSCHEDPARAM - 1 : 0) \ - | POSIX_SPAWN_SETSCHEDULER \ - | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0)) \ - + 1) -#endif -#if !GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap -typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap - [(((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP - | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK - | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER) - & POSIX_SPAWN_USEVFORK) - == 0) - ? 1 : -1]; -# define GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap 1 -#endif - - -#if @GNULIB_POSIX_SPAWN@ -/* Spawn a new process executing PATH with the attributes describes in *ATTRP. - Before running the process perform the actions described in FILE-ACTIONS. - - This function is a possible cancellation points and therefore not - marked with __THROW. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn rpl_posix_spawn -# endif -_GL_FUNCDECL_RPL (posix_spawn, int, - (pid_t *_Restrict_ __pid, - const char *_Restrict_ __path, - const posix_spawn_file_actions_t *_Restrict_ __file_actions, - const posix_spawnattr_t *_Restrict_ __attrp, - char *const argv[_Restrict_arr_], - char *const envp[_Restrict_arr_]) - _GL_ARG_NONNULL ((2, 5, 6))); -_GL_CXXALIAS_RPL (posix_spawn, int, - (pid_t *_Restrict_ __pid, - const char *_Restrict_ __path, - const posix_spawn_file_actions_t *_Restrict_ __file_actions, - const posix_spawnattr_t *_Restrict_ __attrp, - char *const argv[_Restrict_arr_], - char *const envp[_Restrict_arr_])); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn, int, - (pid_t *_Restrict_ __pid, - const char *_Restrict_ __path, - const posix_spawn_file_actions_t *_Restrict_ __file_actions, - const posix_spawnattr_t *_Restrict_ __attrp, - char *const argv[_Restrict_arr_], - char *const envp[_Restrict_arr_]) - _GL_ARG_NONNULL ((2, 5, 6))); -# endif -_GL_CXXALIAS_SYS (posix_spawn, int, - (pid_t *_Restrict_ __pid, - const char *_Restrict_ __path, - const posix_spawn_file_actions_t *_Restrict_ __file_actions, - const posix_spawnattr_t *_Restrict_ __attrp, - char *const argv[_Restrict_arr_], - char *const envp[_Restrict_arr_])); -# endif -_GL_CXXALIASWARN (posix_spawn); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn -# if HAVE_RAW_DECL_POSIX_SPAWN -_GL_WARN_ON_USE (posix_spawn, "posix_spawn is unportable - " - "use gnulib module posix_spawn for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNP@ -/* Similar to 'posix_spawn' but search for FILE in the PATH. - - This function is a possible cancellation points and therefore not - marked with __THROW. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnp rpl_posix_spawnp -# endif -_GL_FUNCDECL_RPL (posix_spawnp, int, - (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[]) - _GL_ARG_NONNULL ((2, 5, 6))); -_GL_CXXALIAS_RPL (posix_spawnp, int, - (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[])); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnp, int, - (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[]) - _GL_ARG_NONNULL ((2, 5, 6))); -# endif -_GL_CXXALIAS_SYS (posix_spawnp, int, - (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[])); -# endif -_GL_CXXALIASWARN (posix_spawnp); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnp -# if HAVE_RAW_DECL_POSIX_SPAWNP -_GL_WARN_ON_USE (posix_spawnp, "posix_spawnp is unportable - " - "use gnulib module posix_spawnp for portability"); -# endif -#endif - - -#if @GNULIB_POSIX_SPAWNATTR_INIT@ -/* Initialize data structure with attributes for 'spawn' to default values. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_init rpl_posix_spawnattr_init -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_init); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_init -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_INIT -_GL_WARN_ON_USE (posix_spawnattr_init, "posix_spawnattr_init is unportable - " - "use gnulib module posix_spawnattr_init for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_DESTROY@ -/* Free resources associated with ATTR. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_destroy rpl_posix_spawnattr_destroy -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_destroy); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_destroy -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_DESTROY -_GL_WARN_ON_USE (posix_spawnattr_destroy, - "posix_spawnattr_destroy is unportable - " - "use gnulib module posix_spawnattr_destroy for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@ -/* Store signal mask for signals with default handling from ATTR in - SIGDEFAULT. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getsigdefault, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigdefault) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getsigdefault, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigdefault)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_getsigdefault, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigdefault) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getsigdefault, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigdefault)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_getsigdefault); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getsigdefault -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGDEFAULT -_GL_WARN_ON_USE (posix_spawnattr_getsigdefault, - "posix_spawnattr_getsigdefault is unportable - " - "use gnulib module posix_spawnattr_getsigdefault for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@ -/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setsigdefault, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigdefault) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_setsigdefault, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigdefault)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_setsigdefault, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigdefault) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setsigdefault, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigdefault)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_setsigdefault); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setsigdefault -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGDEFAULT -_GL_WARN_ON_USE (posix_spawnattr_setsigdefault, - "posix_spawnattr_setsigdefault is unportable - " - "use gnulib module posix_spawnattr_setsigdefault for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@ -/* Store signal mask for the new process from ATTR in SIGMASK. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getsigmask, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getsigmask, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_getsigmask, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getsigmask, int, - (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_getsigmask); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getsigmask -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGMASK -_GL_WARN_ON_USE (posix_spawnattr_getsigmask, - "posix_spawnattr_getsigmask is unportable - " - "use gnulib module posix_spawnattr_getsigmask for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@ -/* Set signal mask for the new process in ATTR to SIGMASK. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setsigmask, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigmask) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_setsigmask, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigmask)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_setsigmask, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigmask) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setsigmask, int, - (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigmask)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_setsigmask); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setsigmask -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGMASK -_GL_WARN_ON_USE (posix_spawnattr_setsigmask, - "posix_spawnattr_setsigmask is unportable - " - "use gnulib module posix_spawnattr_setsigmask for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@ -/* Get flag word from the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getflags rpl_posix_spawnattr_getflags -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getflags, int, - (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getflags, int, - (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_getflags, int, - (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getflags, int, - (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_getflags); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getflags -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETFLAGS -_GL_WARN_ON_USE (posix_spawnattr_getflags, - "posix_spawnattr_getflags is unportable - " - "use gnulib module posix_spawnattr_getflags for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@ -/* Store flags in the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setflags rpl_posix_spawnattr_setflags -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setflags, int, - (posix_spawnattr_t *__attr, short int __flags) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawnattr_setflags, int, - (posix_spawnattr_t *__attr, short int __flags)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_setflags, int, - (posix_spawnattr_t *__attr, short int __flags) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setflags, int, - (posix_spawnattr_t *__attr, short int __flags)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_setflags); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setflags -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETFLAGS -_GL_WARN_ON_USE (posix_spawnattr_setflags, - "posix_spawnattr_setflags is unportable - " - "use gnulib module posix_spawnattr_setflags for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@ -/* Get process group ID from the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getpgroup, int, - (const posix_spawnattr_t *_Restrict_ __attr, - pid_t *_Restrict_ __pgroup) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getpgroup, int, - (const posix_spawnattr_t *_Restrict_ __attr, - pid_t *_Restrict_ __pgroup)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_getpgroup, int, - (const posix_spawnattr_t *_Restrict_ __attr, - pid_t *_Restrict_ __pgroup) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getpgroup, int, - (const posix_spawnattr_t *_Restrict_ __attr, - pid_t *_Restrict_ __pgroup)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_getpgroup); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getpgroup -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETPGROUP -_GL_WARN_ON_USE (posix_spawnattr_getpgroup, - "posix_spawnattr_getpgroup is unportable - " - "use gnulib module posix_spawnattr_getpgroup for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@ -/* Store process group ID in the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setpgroup, int, - (posix_spawnattr_t *__attr, pid_t __pgroup) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawnattr_setpgroup, int, - (posix_spawnattr_t *__attr, pid_t __pgroup)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawnattr_setpgroup, int, - (posix_spawnattr_t *__attr, pid_t __pgroup) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setpgroup, int, - (posix_spawnattr_t *__attr, pid_t __pgroup)); -# endif -_GL_CXXALIASWARN (posix_spawnattr_setpgroup); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setpgroup -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETPGROUP -_GL_WARN_ON_USE (posix_spawnattr_setpgroup, - "posix_spawnattr_setpgroup is unportable - " - "use gnulib module posix_spawnattr_setpgroup for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@ -/* Get scheduling policy from the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getschedpolicy, int, - (const posix_spawnattr_t *_Restrict_ __attr, - int *_Restrict_ __schedpolicy) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getschedpolicy, int, - (const posix_spawnattr_t *_Restrict_ __attr, - int *_Restrict_ __schedpolicy)); -# else -# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0 -_GL_FUNCDECL_SYS (posix_spawnattr_getschedpolicy, int, - (const posix_spawnattr_t *_Restrict_ __attr, - int *_Restrict_ __schedpolicy) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getschedpolicy, int, - (const posix_spawnattr_t *_Restrict_ __attr, - int *_Restrict_ __schedpolicy)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawnattr_getschedpolicy); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getschedpolicy -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPOLICY -_GL_WARN_ON_USE (posix_spawnattr_getschedpolicy, - "posix_spawnattr_getschedpolicy is unportable - " - "use gnulib module posix_spawnattr_getschedpolicy for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@ -/* Store scheduling policy in the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setschedpolicy, int, - (posix_spawnattr_t *__attr, int __schedpolicy) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawnattr_setschedpolicy, int, - (posix_spawnattr_t *__attr, int __schedpolicy)); -# else -# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0 -_GL_FUNCDECL_SYS (posix_spawnattr_setschedpolicy, int, - (posix_spawnattr_t *__attr, int __schedpolicy) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setschedpolicy, int, - (posix_spawnattr_t *__attr, int __schedpolicy)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawnattr_setschedpolicy); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setschedpolicy -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPOLICY -_GL_WARN_ON_USE (posix_spawnattr_setschedpolicy, - "posix_spawnattr_setschedpolicy is unportable - " - "use gnulib module posix_spawnattr_setschedpolicy for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@ -/* Get scheduling parameters from the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_getschedparam, int, - (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_getschedparam, int, - (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam)); -# else -# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0 -_GL_FUNCDECL_SYS (posix_spawnattr_getschedparam, int, - (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_getschedparam, int, - (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawnattr_getschedparam); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_getschedparam -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPARAM -_GL_WARN_ON_USE (posix_spawnattr_getschedparam, - "posix_spawnattr_getschedparam is unportable - " - "use gnulib module posix_spawnattr_getschedparam for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@ -/* Store scheduling parameters in the attribute structure. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam -# endif -_GL_FUNCDECL_RPL (posix_spawnattr_setschedparam, int, - (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawnattr_setschedparam, int, - (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam)); -# else -# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0 -_GL_FUNCDECL_SYS (posix_spawnattr_setschedparam, int, - (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawnattr_setschedparam, int, - (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawnattr_setschedparam); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawnattr_setschedparam -# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPARAM -_GL_WARN_ON_USE (posix_spawnattr_setschedparam, - "posix_spawnattr_setschedparam is unportable - " - "use gnulib module posix_spawnattr_setschedparam for portability"); -# endif -#endif - - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@ -/* Initialize data structure for file attribute for 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_init, int, - (posix_spawn_file_actions_t *__file_actions) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_init, int, - (posix_spawn_file_actions_t *__file_actions)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_init, int, - (posix_spawn_file_actions_t *__file_actions) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_init, int, - (posix_spawn_file_actions_t *__file_actions)); -# endif -_GL_CXXALIASWARN (posix_spawn_file_actions_init); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_init -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_INIT -_GL_WARN_ON_USE (posix_spawn_file_actions_init, - "posix_spawn_file_actions_init is unportable - " - "use gnulib module posix_spawn_file_actions_init for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@ -/* Free resources associated with FILE-ACTIONS. */ -# if @REPLACE_POSIX_SPAWN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_destroy, int, - (posix_spawn_file_actions_t *__file_actions) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_destroy, int, - (posix_spawn_file_actions_t *__file_actions)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_destroy, int, - (posix_spawn_file_actions_t *__file_actions) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_destroy, int, - (posix_spawn_file_actions_t *__file_actions)); -# endif -_GL_CXXALIASWARN (posix_spawn_file_actions_destroy); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_destroy -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_DESTROY -_GL_WARN_ON_USE (posix_spawn_file_actions_destroy, - "posix_spawn_file_actions_destroy is unportable - " - "use gnulib module posix_spawn_file_actions_destroy for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'open' for the given file during the 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_addopen, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd, - const char *_Restrict_ __path, int __oflag, mode_t __mode) - __THROW _GL_ARG_NONNULL ((1, 3))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_addopen, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd, - const char *_Restrict_ __path, int __oflag, mode_t __mode)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_addopen, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd, - const char *_Restrict_ __path, int __oflag, mode_t __mode) - __THROW _GL_ARG_NONNULL ((1, 3))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd, - const char *_Restrict_ __path, int __oflag, mode_t __mode)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawn_file_actions_addopen); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_addopen -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN -_GL_WARN_ON_USE (posix_spawn_file_actions_addopen, - "posix_spawn_file_actions_addopen is unportable - " - "use gnulib module posix_spawn_file_actions_addopen for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'close' for the given file descriptor during the 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_addclose, int, - (posix_spawn_file_actions_t *__file_actions, int __fd) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_addclose, int, - (posix_spawn_file_actions_t *__file_actions, int __fd)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int, - (posix_spawn_file_actions_t *__file_actions, int __fd) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int, - (posix_spawn_file_actions_t *__file_actions, int __fd)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawn_file_actions_addclose); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_addclose -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE -_GL_WARN_ON_USE (posix_spawn_file_actions_addclose, - "posix_spawn_file_actions_addclose is unportable - " - "use gnulib module posix_spawn_file_actions_addclose for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'dup2' for the given file descriptors during the 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2 -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_adddup2, int, - (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_adddup2, int, - (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd)); -# else -# if !@HAVE_POSIX_SPAWN@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_adddup2, int, - (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int, - (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd)); -# endif -# if __GLIBC__ >= 2 -_GL_CXXALIASWARN (posix_spawn_file_actions_adddup2); -# endif -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_adddup2 -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 -_GL_WARN_ON_USE (posix_spawn_file_actions_adddup2, - "posix_spawn_file_actions_adddup2 is unportable - " - "use gnulib module posix_spawn_file_actions_adddup2 for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'chdir' to the given directory during the 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_addchdir rpl_posix_spawn_file_actions_addchdir -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_addchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - const char *_Restrict_ __path) - __THROW _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_addchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - const char *_Restrict_ __path)); -# else -# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_addchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - const char *_Restrict_ __path) - __THROW _GL_ARG_NONNULL ((1, 2))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_addchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - const char *_Restrict_ __path)); -# endif -_GL_CXXALIASWARN (posix_spawn_file_actions_addchdir); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_addchdir -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR -_GL_WARN_ON_USE (posix_spawn_file_actions_addchdir, - "posix_spawn_file_actions_addchdir is unportable - " - "use gnulib module posix_spawn_file_actions_addchdir for portability"); -# endif -#endif - -#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'fchdir' to the given directory during the 'spawn' call. */ -# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# define posix_spawn_file_actions_addfchdir rpl_posix_spawn_file_actions_addfchdir -# endif -_GL_FUNCDECL_RPL (posix_spawn_file_actions_addfchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd) - __THROW _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (posix_spawn_file_actions_addfchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd)); -# else -# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@ -_GL_FUNCDECL_SYS (posix_spawn_file_actions_addfchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd) - __THROW _GL_ARG_NONNULL ((1))); -# endif -_GL_CXXALIAS_SYS (posix_spawn_file_actions_addfchdir, int, - (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd)); -# endif -_GL_CXXALIASWARN (posix_spawn_file_actions_addfchdir); -#elif defined GNULIB_POSIXCHECK -# undef posix_spawn_file_actions_addfchdir -# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR -_GL_WARN_ON_USE (posix_spawn_file_actions_addfchdir, - "posix_spawn_file_actions_addfchdir is unportable - " - "use gnulib module posix_spawn_file_actions_addfchdir for portability"); -# endif -#endif - - -#endif /* _@GUARD_PREFIX@_SPAWN_H */ -#endif /* _@GUARD_PREFIX@_SPAWN_H */ diff --git a/lib/spawn_faction_addchdir.c b/lib/spawn_faction_addchdir.c deleted file mode 100644 index 8fb6cb0f7d2..00000000000 --- a/lib/spawn_faction_addchdir.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (C) 2018-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include -#include -#include - -#if REPLACE_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Add an action to FILE-ACTIONS which tells the implementation to call - 'chdir' to the given directory during the 'spawn' call. */ -int -posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t *file_actions, - const char *path) -#undef posix_spawn_file_actions_addchdir -{ -#if !REPLACE_POSIX_SPAWN - return posix_spawn_file_actions_addchdir_np (file_actions, path); -#else - { - /* Copy PATH, because the caller may free it before calling posix_spawn() - or posix_spawnp(). */ - char *path_copy = strdup (path); - if (path_copy == NULL) - return ENOMEM; - - /* 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. */ - free (path_copy); - return ENOMEM; - } - - { - struct __spawn_action *rec; - - /* Add the new value. */ - rec = &file_actions->_actions[file_actions->_used]; - rec->tag = spawn_do_chdir; - rec->action.chdir_action.path = path_copy; - - /* Account for the new entry. */ - ++file_actions->_used; - - return 0; - } - } -#endif -} diff --git a/lib/spawn_faction_adddup2.c b/lib/spawn_faction_adddup2.c deleted file mode 100644 index c00b0b49668..00000000000 --- a/lib/spawn_faction_adddup2.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include -#include - -#if !_LIBC -# define __sysconf(open_max) getdtablesize () -#endif - -#if REPLACE_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 !REPLACE_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/lib/spawn_faction_destroy.c b/lib/spawn_faction_destroy.c deleted file mode 100644 index e9985f4a0d4..00000000000 --- a/lib/spawn_faction_destroy.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include - -#if REPLACE_POSIX_SPAWN -# include "spawn_int.h" -#endif - -/* Initialize data structure for file attribute for 'spawn' call. */ -int -posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions) -#undef posix_spawn_file_actions_destroy -{ -#if !REPLACE_POSIX_SPAWN - return posix_spawn_file_actions_destroy (file_actions); -#else - int i; - - /* Free the paths in the open actions. */ - for (i = 0; i < file_actions->_used; ++i) - { - struct __spawn_action *sa = &file_actions->_actions[i]; - switch (sa->tag) - { - case spawn_do_open: - free (sa->action.open_action.path); - break; - case spawn_do_chdir: - free (sa->action.chdir_action.path); - break; - default: - /* No cleanup required. */ - break; - } - } - - /* Free the array of actions. */ - free (file_actions->_actions); - - return 0; -#endif -} diff --git a/lib/spawn_faction_init.c b/lib/spawn_faction_init.c deleted file mode 100644 index 135605fb8c6..00000000000 --- a/lib/spawn_faction_init.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include -#include -#include - -#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/lib/spawn_int.h b/lib/spawn_int.h deleted file mode 100644 index 60a94ddd55a..00000000000 --- a/lib/spawn_int.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright (C) 2000, 2008-2020 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 . */ - -#include - -/* Data structure to contain the action information. */ -struct __spawn_action -{ - enum - { - spawn_do_close, - spawn_do_dup2, - spawn_do_open, - spawn_do_chdir, - spawn_do_fchdir - } tag; - - union - { - struct - { - int fd; - } close_action; - struct - { - int fd; - int newfd; - } dup2_action; - struct - { - int fd; - char *path; - int oflag; - mode_t mode; - } open_action; - struct - { - char *path; - } chdir_action; - struct - { - int fd; - } fchdir_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, const char *const argv[], - const char *const envp[], int use_path); diff --git a/lib/spawnattr_destroy.c b/lib/spawnattr_destroy.c deleted file mode 100644 index 22a7d5a61a2..00000000000 --- a/lib/spawnattr_destroy.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -/* 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/lib/spawnattr_init.c b/lib/spawnattr_init.c deleted file mode 100644 index 99674488f81..00000000000 --- a/lib/spawnattr_init.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include - -/* 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/lib/spawnattr_setdefault.c b/lib/spawnattr_setdefault.c deleted file mode 100644 index 01c29e94847..00000000000 --- a/lib/spawnattr_setdefault.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include - -/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */ -int -posix_spawnattr_setsigdefault (posix_spawnattr_t *attr, - const sigset_t *sigdefault) -{ - /* Copy the sigset_t data to the user buffer. */ - memcpy (&attr->_sd, sigdefault, sizeof (sigset_t)); - - return 0; -} diff --git a/lib/spawnattr_setflags.c b/lib/spawnattr_setflags.c deleted file mode 100644 index 084d5bcea4c..00000000000 --- a/lib/spawnattr_setflags.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2000, 2004, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include -#include - -#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/lib/spawnattr_setpgroup.c b/lib/spawnattr_setpgroup.c deleted file mode 100644 index 479457ad23e..00000000000 --- a/lib/spawnattr_setpgroup.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include - -/* Store process group ID in the attribute structure. */ -int -posix_spawnattr_setpgroup (posix_spawnattr_t *attr, pid_t pgroup) -{ - /* Store the process group ID. */ - attr->_pgrp = pgroup; - - return 0; -} diff --git a/lib/spawnattr_setsigmask.c b/lib/spawnattr_setsigmask.c deleted file mode 100644 index 9b6f9ece38e..00000000000 --- a/lib/spawnattr_setsigmask.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000, 2009-2020 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 . */ - -#include - -/* Specification. */ -#include - -#include - -/* 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/lib/spawni.c b/lib/spawni.c deleted file mode 100644 index 182d13ff24c..00000000000 --- a/lib/spawni.c +++ /dev/null @@ -1,349 +0,0 @@ -/* Guts of POSIX spawn interface. Generic POSIX.1 version. - Copyright (C) 2000-2006, 2008-2020 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 . */ - -#include - -/* Specification. */ -#include -#include "spawn_int.h" - -#include -#include - -#include -#ifndef O_LARGEFILE -# define O_LARGEFILE 0 -#endif - -#if _LIBC || HAVE_PATHS_H -# include -#else -# define _PATH_BSHELL BOURNE_SHELL -#endif - -#include -#include -#include -#include - -#if _LIBC -# include -#else -# define close_not_cancel close -# define open_not_cancel open -#endif - -#if _LIBC -# include -#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 -#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 __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, const char *const argv[], - const char *const envp[], int use_path) -{ - /* Not yet implemented. */ - return ENOSYS; -} - -#else - - -/* 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, const char *const argv[], - const 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; - - case spawn_do_chdir: - if (chdir (action->action.chdir_action.path) < 0) - /* The 'chdir' call failed. */ - _exit (SPAWN_ERROR); - break; - - case spawn_do_fchdir: - if (fchdir (action->action.fchdir_action.fd) < 0) - /* The 'fchdir' call failed. */ - _exit (SPAWN_ERROR); - break; - } - } - } - - if (! use_path || strchr (file, '/') != NULL) - { - /* The FILE parameter is actually a path. */ - execve (file, (char * const *) argv, (char * const *) 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, (char * const *) argv, (char * const *) 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/lib/strchrnul.c b/lib/strchrnul.c deleted file mode 100644 index 858d66fab18..00000000000 --- a/lib/strchrnul.c +++ /dev/null @@ -1,142 +0,0 @@ -/* Searching in a string. - Copyright (C) 2003, 2007-2020 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 . */ - -#include - -/* Specification. */ -#include - -/* Find the first occurrence of C in S or the final NUL byte. */ -char * -strchrnul (const char *s, int c_in) -{ - /* On 32-bit hardware, choosing longword to be a 32-bit unsigned - long instead of a 64-bit uintmax_t tends to give better - performance. On 64-bit hardware, unsigned long is generally 64 - bits already. Change this typedef to experiment with - performance. */ - typedef unsigned long int longword; - - const unsigned char *char_ptr; - const longword *longword_ptr; - longword repeated_one; - longword repeated_c; - unsigned char c; - - c = (unsigned char) c_in; - if (!c) - return rawmemchr (s, 0); - - /* Handle the first few bytes by reading one byte at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - (size_t) char_ptr % sizeof (longword) != 0; - ++char_ptr) - if (!*char_ptr || *char_ptr == c) - return (char *) char_ptr; - - longword_ptr = (const longword *) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to any size longwords. */ - - /* Compute auxiliary longword values: - repeated_one is a value which has a 1 in every byte. - repeated_c has c in every byte. */ - repeated_one = 0x01010101; - repeated_c = c | (c << 8); - repeated_c |= repeated_c << 16; - if (0xffffffffU < (longword) -1) - { - repeated_one |= repeated_one << 31 << 1; - repeated_c |= repeated_c << 31 << 1; - if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } - } - - /* Instead of the traditional loop which tests each byte, we will - test a longword at a time. The tricky part is testing if *any of - the four* bytes in the longword in question are equal to NUL or - c. We first use an xor with repeated_c. This reduces the task - to testing whether *any of the four* bytes in longword1 or - longword2 is zero. - - Let's consider longword1. We compute tmp = - ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). - That is, we perform the following operations: - 1. Subtract repeated_one. - 2. & ~longword1. - 3. & a mask consisting of 0x80 in every byte. - Consider what happens in each byte: - - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, - and step 3 transforms it into 0x80. A carry can also be propagated - to more significant bytes. - - If a byte of longword1 is nonzero, let its lowest 1 bit be at - position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, - the byte ends in a single bit of value 0 and k bits of value 1. - After step 2, the result is just k bits of value 1: 2^k - 1. After - step 3, the result is 0. And no carry is produced. - So, if longword1 has only non-zero bytes, tmp is zero. - Whereas if longword1 has a zero byte, call j the position of the least - significant zero byte. Then the result has a zero at positions 0, ..., - j-1 and a 0x80 at position j. We cannot predict the result at the more - significant bytes (positions j+1..3), but it does not matter since we - already have a non-zero bit at position 8*j+7. - - The test whether any byte in longword1 or longword2 is zero is equivalent - to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine - this into a single test, whether (tmp1 | tmp2) is nonzero. - - This test can read more than one byte beyond the end of a string, - depending on where the terminating NUL is encountered. However, - this is considered safe since the initialization phase ensured - that the read will be aligned, therefore, the read will not cross - page boundaries and will not cause a fault. */ - - while (1) - { - longword longword1 = *longword_ptr ^ repeated_c; - longword longword2 = *longword_ptr; - - if (((((longword1 - repeated_one) & ~longword1) - | ((longword2 - repeated_one) & ~longword2)) - & (repeated_one << 7)) != 0) - break; - longword_ptr++; - } - - char_ptr = (const unsigned char *) longword_ptr; - - /* At this point, we know that one of the sizeof (longword) bytes - starting at char_ptr is == 0 or == c. On little-endian machines, - we could determine the first such byte without any further memory - accesses, just by looking at the tmp result from the last loop - iteration. But this does not work on big-endian machines. - Choose code that works in both cases. */ - - char_ptr = (unsigned char *) longword_ptr; - while (*char_ptr && (*char_ptr != c)) - char_ptr++; - return (char *) char_ptr; -} diff --git a/lib/strchrnul.valgrind b/lib/strchrnul.valgrind deleted file mode 100644 index a85608a7c76..00000000000 --- a/lib/strchrnul.valgrind +++ /dev/null @@ -1,28 +0,0 @@ -# Suppress a valgrind message about use of uninitialized memory in strchrnul(). - -# Copyright (C) 2008-2020 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 . - -# This use is OK because it provides only a speedup. -{ - strchrnul-value4 - Memcheck:Value4 - fun:strchrnul -} -{ - strchrnul-value8 - Memcheck:Value8 - fun:strchrnul -} diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index e2a44efe621..0971636c33d 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -139,18 +139,6 @@ AC_DEFUN([gl_EARLY], # Code from module openat-h: # Code from module pathmax: # Code from module pipe2: - # Code from module posix_spawn: - # Code from module posix_spawn-internal: - # Code from module posix_spawn_file_actions_addchdir: - # Code from module posix_spawn_file_actions_adddup2: - # Code from module posix_spawn_file_actions_destroy: - # Code from module posix_spawn_file_actions_init: - # Code from module posix_spawnattr_destroy: - # Code from module posix_spawnattr_init: - # Code from module posix_spawnattr_setflags: - # Code from module posix_spawnattr_setpgroup: - # Code from module posix_spawnattr_setsigdefault: - # Code from module posix_spawnattr_setsigmask: # Code from module pselect: # Code from module pthread_sigmask: # Code from module qcopy-acl: @@ -159,9 +147,7 @@ AC_DEFUN([gl_EARLY], # Code from module readlinkat: # Code from module regex: # Code from module root-uid: - # Code from module sched: # Code from module scratch_buffer: - # Code from module sh-filename: # Code from module sig2str: # Code from module sigdescr_np: # Code from module signal-h: @@ -170,7 +156,6 @@ AC_DEFUN([gl_EARLY], # Code from module snippet/c++defs: # Code from module snippet/warn-on-use: # Code from module socklen: - # Code from module spawn: # Code from module ssize_t: # Code from module stat-time: # Code from module std-gnu11: @@ -180,7 +165,6 @@ AC_DEFUN([gl_EARLY], # Code from module stdio: # Code from module stdlib: # Code from module stpcpy: - # Code from module strchrnul: # Code from module string: # Code from module strnlen: # Code from module strtoimax: @@ -419,61 +403,6 @@ AC_DEFUN([gl_INIT], gl_PATHMAX gl_FUNC_PIPE2 gl_UNISTD_MODULE_INDICATOR([pipe2]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawn]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawn]) - gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 1; then - AC_LIBOBJ([spawn_faction_addchdir]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addchdir]) - gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then - AC_LIBOBJ([spawn_faction_adddup2]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_adddup2]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawn_faction_destroy]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_destroy]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawn_faction_init]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_init]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_destroy]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_destroy]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_init]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_init]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_setflags]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setflags]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_setpgroup]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setpgroup]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_setdefault]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setsigdefault]) - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawnattr_setsigmask]) - fi - gl_SPAWN_MODULE_INDICATOR([posix_spawnattr_setsigmask]) gl_FUNC_PSELECT if test $HAVE_PSELECT = 0 || test $REPLACE_PSELECT = 1; then AC_LIBOBJ([pselect]) @@ -501,7 +430,6 @@ AC_DEFUN([gl_INIT], AC_LIBOBJ([regex]) gl_PREREQ_REGEX fi - gl_SCHED_H gl_FUNC_SIG2STR if test $ac_cv_func_sig2str = no; then AC_LIBOBJ([sig2str]) @@ -514,7 +442,6 @@ AC_DEFUN([gl_INIT], gl_STRING_MODULE_INDICATOR([sigdescr_np]) gl_SIGNAL_H gl_TYPE_SOCKLEN_T - gl_SPAWN_H gt_TYPE_SSIZE_T gl_STAT_TIME gl_STAT_BIRTHTIME @@ -601,12 +528,9 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31=false gl_gnulib_enabled_open=false gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=false - gl_gnulib_enabled_332607f759618fb73dfc3076748afea7=false gl_gnulib_enabled_rawmemchr=false gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false gl_gnulib_enabled_scratch_buffer=false - gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70=false - gl_gnulib_enabled_strchrnul=false gl_gnulib_enabled_strtoll=false gl_gnulib_enabled_utimens=false gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false @@ -761,20 +685,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7=true fi } - func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7 () - { - if ! $gl_gnulib_enabled_332607f759618fb73dfc3076748afea7; then - gl_POSIX_SPAWN - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - AC_LIBOBJ([spawni]) - gl_PREREQ_POSIX_SPAWN_INTERNAL - fi - gl_gnulib_enabled_332607f759618fb73dfc3076748afea7=true - func_gl_gnulib_m4code_open - func_gl_gnulib_m4code_cdeb0f2aaf9d280baa6526bfa1b07f70 - func_gl_gnulib_m4code_strchrnul - fi - } func_gl_gnulib_m4code_rawmemchr () { if ! $gl_gnulib_enabled_rawmemchr; then @@ -799,28 +709,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_scratch_buffer=true fi } - func_gl_gnulib_m4code_cdeb0f2aaf9d280baa6526bfa1b07f70 () - { - if ! $gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70; then - gl_SH_FILENAME - gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70=true - fi - } - func_gl_gnulib_m4code_strchrnul () - { - if ! $gl_gnulib_enabled_strchrnul; then - gl_FUNC_STRCHRNUL - if test $HAVE_STRCHRNUL = 0 || test $REPLACE_STRCHRNUL = 1; then - AC_LIBOBJ([strchrnul]) - gl_PREREQ_STRCHRNUL - fi - gl_STRING_MODULE_INDICATOR([strchrnul]) - gl_gnulib_enabled_strchrnul=true - if test $HAVE_STRCHRNUL = 0 || test $REPLACE_STRCHRNUL = 1; then - func_gl_gnulib_m4code_rawmemchr - fi - fi - } func_gl_gnulib_m4code_strtoll () { if ! $gl_gnulib_enabled_strtoll; then @@ -903,12 +791,6 @@ AC_DEFUN([gl_INIT], if case $host_os in mingw*) false;; *) test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1;; esac; then func_gl_gnulib_m4code_open fi - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1; then - func_gl_gnulib_m4code_332607f759618fb73dfc3076748afea7 - fi - if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then - func_gl_gnulib_m4code_getdtablesize - fi if test $HAVE_READLINKAT = 0 || test $REPLACE_READLINKAT = 1; then func_gl_gnulib_m4code_260941c0e5dc67ec9e87d1fb321c300b fi @@ -948,12 +830,9 @@ AC_DEFUN([gl_INIT], AM_CONDITIONAL([gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31], [$gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31]) AM_CONDITIONAL([gl_GNULIB_ENABLED_open], [$gl_gnulib_enabled_open]) AM_CONDITIONAL([gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7], [$gl_gnulib_enabled_03e0aaad4cb89ca757653bd367a6ccb7]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7], [$gl_gnulib_enabled_332607f759618fb73dfc3076748afea7]) AM_CONDITIONAL([gl_GNULIB_ENABLED_rawmemchr], [$gl_gnulib_enabled_rawmemchr]) AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) AM_CONDITIONAL([gl_GNULIB_ENABLED_scratch_buffer], [$gl_gnulib_enabled_scratch_buffer]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70], [$gl_gnulib_enabled_cdeb0f2aaf9d280baa6526bfa1b07f70]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_strchrnul], [$gl_gnulib_enabled_strchrnul]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) AM_CONDITIONAL([gl_GNULIB_ENABLED_utimens], [$gl_gnulib_enabled_utimens]) AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) @@ -1234,7 +1113,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/regex_internal.h lib/regexec.c lib/root-uid.h - lib/sched.in.h lib/scratch_buffer.h lib/set-permissions.c lib/sha1.c @@ -1247,20 +1125,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/sig2str.h lib/sigdescr_np.c lib/signal.in.h - lib/spawn.c - lib/spawn.in.h - lib/spawn_faction_addchdir.c - lib/spawn_faction_adddup2.c - lib/spawn_faction_destroy.c - lib/spawn_faction_init.c - lib/spawn_int.h - lib/spawnattr_destroy.c - lib/spawnattr_init.c - lib/spawnattr_setdefault.c - lib/spawnattr_setflags.c - lib/spawnattr_setpgroup.c - lib/spawnattr_setsigmask.c - lib/spawni.c lib/stat-time.c lib/stat-time.h lib/stdalign.in.h @@ -1271,8 +1135,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/stdlib.in.h lib/stpcpy.c lib/str-two-way.h - lib/strchrnul.c - lib/strchrnul.valgrind lib/strftime.h lib/string.in.h lib/strnlen.c @@ -1386,16 +1248,12 @@ AC_DEFUN([gl_FILE_LIST], [ m4/pathmax.m4 m4/pid_t.m4 m4/pipe2.m4 - m4/posix_spawn.m4 - m4/posix_spawn_faction_addchdir.m4 m4/pselect.m4 m4/pthread_sigmask.m4 m4/rawmemchr.m4 m4/readlink.m4 m4/readlinkat.m4 m4/regex.m4 - m4/sched_h.m4 - m4/sh-filename.m4 m4/sha1.m4 m4/sha256.m4 m4/sha512.m4 @@ -1403,7 +1261,6 @@ AC_DEFUN([gl_FILE_LIST], [ m4/sigdescr_np.m4 m4/signal_h.m4 m4/socklen.m4 - m4/spawn_h.m4 m4/ssize_t.m4 m4/stat-time.m4 m4/std-gnu11.m4 @@ -1413,7 +1270,6 @@ AC_DEFUN([gl_FILE_LIST], [ m4/stdio_h.m4 m4/stdlib_h.m4 m4/stpcpy.m4 - m4/strchrnul.m4 m4/string_h.m4 m4/strnlen.m4 m4/strtoimax.m4 diff --git a/m4/posix_spawn.m4 b/m4/posix_spawn.m4 deleted file mode 100644 index 59e56fcb5f2..00000000000 --- a/m4/posix_spawn.m4 +++ /dev/null @@ -1,678 +0,0 @@ -# posix_spawn.m4 serial 19 -dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Tests whether the entire posix_spawn facility is available. -AC_DEFUN([gl_POSIX_SPAWN], -[ - AC_REQUIRE([gl_POSIX_SPAWN_BODY]) -]) - -AC_DEFUN([gl_POSIX_SPAWN_BODY], -[ - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - AC_REQUIRE([gl_HAVE_POSIX_SPAWN]) - dnl Assume that when the main function exists, all the others, - dnl except posix_spawnattr_{get,set}sched*, are available as well. - dnl AC_CHECK_FUNCS_ONCE([posix_spawnp]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_init]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addclose]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_adddup2]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addopen]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_destroy]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_init]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getflags]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setflags]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getpgroup]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setpgroup]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigdefault]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigdefault]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigmask]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigmask]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_destroy]) - if test $ac_cv_func_posix_spawn = yes; then - m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR], - [dnl Module 'posix_spawn_file_actions_addchdir' is present. - AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir_np]) - if test $ac_cv_func_posix_spawn_file_actions_addchdir_np = no; then - dnl In order to implement the posix_spawn_file_actions_addchdir - dnl function, we need to replace the entire posix_spawn facility. - REPLACE_POSIX_SPAWN=1 - fi - ]) - m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR], - [dnl Module 'posix_spawn_file_actions_addfchdir' is present. - AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addfchdir_np]) - if test $ac_cv_func_posix_spawn_file_actions_addfchdir_np = no; then - dnl In order to implement the posix_spawn_file_actions_addfchdir - dnl function, we need to replace the entire posix_spawn facility. - REPLACE_POSIX_SPAWN=1 - fi - ]) - if test $REPLACE_POSIX_SPAWN = 0; then - gl_POSIX_SPAWN_WORKS - case "$gl_cv_func_posix_spawn_works" in - *yes) ;; - *) REPLACE_POSIX_SPAWN=1 ;; - esac - fi - if test $REPLACE_POSIX_SPAWN = 0; then - gl_POSIX_SPAWN_SECURE - case "$gl_cv_func_posix_spawn_secure_exec" in - *yes) ;; - *) REPLACE_POSIX_SPAWN=1 ;; - esac - case "$gl_cv_func_posix_spawnp_secure_exec" in - *yes) ;; - *) REPLACE_POSIX_SPAWN=1 ;; - esac - fi - if test $REPLACE_POSIX_SPAWN = 0; then - dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDULER - dnl evaluates to nonzero. - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedpolicy]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedpolicy]) - AC_CACHE_CHECK([whether posix_spawnattr_setschedpolicy is supported], - [gl_cv_func_spawnattr_setschedpolicy], - [AC_EGREP_CPP([POSIX scheduling supported], [ -#include -#if POSIX_SPAWN_SETSCHEDULER - POSIX scheduling supported -#endif -], - [gl_cv_func_spawnattr_setschedpolicy=yes], - [gl_cv_func_spawnattr_setschedpolicy=no]) - ]) - dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDPARAM - dnl evaluates to nonzero. - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedparam]) - dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedparam]) - AC_CACHE_CHECK([whether posix_spawnattr_setschedparam is supported], - [gl_cv_func_spawnattr_setschedparam], - [AC_EGREP_CPP([POSIX scheduling supported], [ -#include -#if POSIX_SPAWN_SETSCHEDPARAM - POSIX scheduling supported -#endif -], - [gl_cv_func_spawnattr_setschedparam=yes], - [gl_cv_func_spawnattr_setschedparam=no]) - ]) - fi - fi - if test $ac_cv_func_posix_spawn != yes || test $REPLACE_POSIX_SPAWN = 1; then - AC_DEFINE([REPLACE_POSIX_SPAWN], [1], - [Define if gnulib uses its own posix_spawn and posix_spawnp functions.]) - fi -]) - -dnl Test whether posix_spawn actually works. -dnl posix_spawn on AIX 5.3..6.1 has two bugs: -dnl 1) When it fails to execute the program, the child process exits with -dnl exit() rather than _exit(), which causes the stdio buffers to be -dnl flushed. Reported by Rainer Tammer. -dnl 2) The posix_spawn_file_actions_addopen function does not support file -dnl names that contain a '*'. -dnl posix_spawn on AIX 5.3..6.1 has also a third bug: It does not work -dnl when POSIX threads are used. But we don't test against this bug here. -AC_DEFUN([gl_POSIX_SPAWN_WORKS], -[ - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - AC_CACHE_CHECK([whether posix_spawn works], [gl_cv_func_posix_spawn_works], - [if test $cross_compiling = no; then - AC_LINK_IFELSE([AC_LANG_SOURCE([[ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -]GL_MDA_DEFINES[ - -extern char **environ; - -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - -#ifndef WTERMSIG -# define WTERMSIG(x) ((x) & 0x7f) -#endif -#ifndef WIFEXITED -# define WIFEXITED(x) (WTERMSIG (x) == 0) -#endif -#ifndef WEXITSTATUS -# define WEXITSTATUS(x) (((x) >> 8) & 0xff) -#endif - -#define CHILD_PROGRAM_FILENAME "/non/exist/ent" - -static int -fd_safer (int fd) -{ - if (0 <= fd && fd <= 2) - { - int f = fd_safer (dup (fd)); - int e = errno; - close (fd); - errno = e; - fd = f; - } - - return fd; -} - -int -main () -{ - char *argv[2] = { CHILD_PROGRAM_FILENAME, NULL }; - int ofd[2]; - sigset_t blocked_signals; - sigset_t fatal_signal_set; - posix_spawn_file_actions_t actions; - bool actions_allocated; - posix_spawnattr_t attrs; - bool attrs_allocated; - int err; - pid_t child; - int status; - int exitstatus; - - setvbuf (stdout, NULL, _IOFBF, 0); - puts ("This should be seen only once."); - if (pipe (ofd) < 0 || (ofd[1] = fd_safer (ofd[1])) < 0) - { - perror ("cannot create pipe"); - exit (1); - } - sigprocmask (SIG_SETMASK, NULL, &blocked_signals); - sigemptyset (&fatal_signal_set); - sigaddset (&fatal_signal_set, SIGINT); - sigaddset (&fatal_signal_set, SIGTERM); - sigaddset (&fatal_signal_set, SIGHUP); - sigaddset (&fatal_signal_set, SIGPIPE); - sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL); - actions_allocated = false; - attrs_allocated = false; - if ((err = posix_spawn_file_actions_init (&actions)) != 0 - || (actions_allocated = true, - (err = posix_spawn_file_actions_adddup2 (&actions, ofd[0], STDIN_FILENO)) != 0 - || (err = posix_spawn_file_actions_addclose (&actions, ofd[0])) != 0 - || (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0 - || (err = posix_spawnattr_init (&attrs)) != 0 - || (attrs_allocated = true, - (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0 - || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0) - || (err = posix_spawnp (&child, CHILD_PROGRAM_FILENAME, &actions, &attrs, argv, environ)) != 0)) - { - if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); - if (attrs_allocated) - posix_spawnattr_destroy (&attrs); - sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); - if (err == ENOENT) - return 0; - else - { - errno = err; - perror ("subprocess failed"); - exit (1); - } - } - posix_spawn_file_actions_destroy (&actions); - posix_spawnattr_destroy (&attrs); - sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); - close (ofd[0]); - close (ofd[1]); - status = 0; - while (waitpid (child, &status, 0) != child) - ; - if (!WIFEXITED (status)) - { - fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status); - exit (1); - } - exitstatus = WEXITSTATUS (status); - if (exitstatus != 127) - { - fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus); - exit (1); - } - return 0; -} -]])], - [if test -s conftest$ac_exeext \ - && ./conftest$ac_exeext > conftest.out \ - && echo 'This should be seen only once.' > conftest.ok \ - && cmp conftest.out conftest.ok >/dev/null 2>&1; then - gl_cv_func_posix_spawn_works=yes - else - gl_cv_func_posix_spawn_works=no - fi], - [gl_cv_func_posix_spawn_works=no]) - if test $gl_cv_func_posix_spawn_works = yes; then - AC_RUN_IFELSE([AC_LANG_SOURCE([[ -/* Test whether posix_spawn_file_actions_addopen supports filename arguments - that contain special characters such as '*'. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -]GL_MDA_DEFINES[ - -extern char **environ; - -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - -#ifndef WTERMSIG -# define WTERMSIG(x) ((x) & 0x7f) -#endif -#ifndef WIFEXITED -# define WIFEXITED(x) (WTERMSIG (x) == 0) -#endif -#ifndef WEXITSTATUS -# define WEXITSTATUS(x) (((x) >> 8) & 0xff) -#endif - -#define CHILD_PROGRAM_FILENAME "conftest" -#define DATA_FILENAME "conftest%=*#?" - -static int -parent_main (void) -{ - FILE *fp; - char *argv[3] = { CHILD_PROGRAM_FILENAME, "-child", NULL }; - posix_spawn_file_actions_t actions; - bool actions_allocated; - int err; - pid_t child; - int status; - int exitstatus; - - /* Create a data file with specific contents. */ - fp = fopen (DATA_FILENAME, "wb"); - if (fp == NULL) - { - perror ("cannot create data file"); - return 1; - } - fwrite ("Halle Potta", 1, 11, fp); - if (fflush (fp) || fclose (fp)) - { - perror ("cannot prepare data file"); - return 2; - } - - /* Avoid reading from our stdin, as it could block. */ - freopen ("/dev/null", "rb", stdin); - - /* Test whether posix_spawn_file_actions_addopen with this file name - actually works, but spawning a child that reads from this file. */ - actions_allocated = false; - if ((err = posix_spawn_file_actions_init (&actions)) != 0 - || (actions_allocated = true, - (err = posix_spawn_file_actions_addopen (&actions, STDIN_FILENO, DATA_FILENAME, O_RDONLY, 0600)) != 0 - || (err = posix_spawn (&child, CHILD_PROGRAM_FILENAME, &actions, NULL, argv, environ)) != 0)) - { - if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); - errno = err; - perror ("subprocess failed"); - return 3; - } - posix_spawn_file_actions_destroy (&actions); - status = 0; - while (waitpid (child, &status, 0) != child) - ; - if (!WIFEXITED (status)) - { - fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status); - return 4; - } - exitstatus = WEXITSTATUS (status); - if (exitstatus != 0) - { - fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus); - return 5; - } - return 0; -} - -static int -child_main (void) -{ - char buf[1024]; - - /* See if reading from STDIN_FILENO yields the expected contents. */ - if (fread (buf, 1, sizeof (buf), stdin) == 11 - && memcmp (buf, "Halle Potta", 11) == 0) - return 0; - else - return 8; -} - -static void -cleanup_then_die (int sig) -{ - /* Clean up data file. */ - unlink (DATA_FILENAME); - - /* Re-raise the signal and die from it. */ - signal (sig, SIG_DFL); - raise (sig); -} - -int -main (int argc, char *argv[]) -{ - int exitstatus; - - if (!(argc > 1 && strcmp (argv[1], "-child") == 0)) - { - /* This is the parent process. */ - signal (SIGINT, cleanup_then_die); - signal (SIGTERM, cleanup_then_die); - #ifdef SIGHUP - signal (SIGHUP, cleanup_then_die); - #endif - - exitstatus = parent_main (); - } - else - { - /* This is the child process. */ - - exitstatus = child_main (); - } - unlink (DATA_FILENAME); - return exitstatus; -} -]])], - [], - [gl_cv_func_posix_spawn_works=no]) - fi - else - case "$host_os" in - aix*) gl_cv_func_posix_spawn_works="guessing no";; - *) gl_cv_func_posix_spawn_works="guessing yes";; - esac - fi - ]) -]) - -dnl Test whether posix_spawn and posix_spawnp are secure. -AC_DEFUN([gl_POSIX_SPAWN_SECURE], -[ - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - dnl On many platforms, posix_spawn or posix_spawnp allow executing a - dnl script without a '#!' marker as a shell script. This is unsecure. - AC_CACHE_CHECK([whether posix_spawn rejects scripts without shebang], - [gl_cv_func_posix_spawn_secure_exec], - [echo ':' > conftest.scr - chmod a+x conftest.scr - AC_RUN_IFELSE([AC_LANG_SOURCE([[ - #include - #include - #include - #include - #include - int - main () - { - const char *prog_path = "./conftest.scr"; - const char *prog_argv[2] = { prog_path, NULL }; - const char *environment[2] = { "PATH=.", NULL }; - pid_t child; - int status; - int err = posix_spawn (&child, prog_path, NULL, NULL, - (char **) prog_argv, (char **) environment); - if (err == ENOEXEC) - return 0; - if (err != 0) - return 1; - status = 0; - while (waitpid (child, &status, 0) != child) - ; - if (!WIFEXITED (status)) - return 2; - if (WEXITSTATUS (status) != 127) - return 3; - return 0; - } - ]])], - [gl_cv_func_posix_spawn_secure_exec=yes], - [gl_cv_func_posix_spawn_secure_exec=no], - [case "$host_os" in - # Guess no on GNU/Hurd. - gnu*) - gl_cv_func_posix_spawn_secure_exec="guessing no" ;; - # Guess yes on all other platforms. - *) - gl_cv_func_posix_spawn_secure_exec="guessing yes" ;; - esac - ]) - rm -f conftest.scr - ]) - AC_CACHE_CHECK([whether posix_spawnp rejects scripts without shebang], - [gl_cv_func_posix_spawnp_secure_exec], - [echo ':' > conftest.scr - chmod a+x conftest.scr - AC_RUN_IFELSE([AC_LANG_SOURCE([[ - #include - #include - #include - #include - #include - int - main () - { - const char *prog_path = "./conftest.scr"; - const char *prog_argv[2] = { prog_path, NULL }; - const char *environment[2] = { "PATH=.", NULL }; - pid_t child; - int status; - int err = posix_spawnp (&child, prog_path, NULL, NULL, - (char **) prog_argv, (char **) environment); - if (err == ENOEXEC) - return 0; - if (err != 0) - return 1; - status = 0; - while (waitpid (child, &status, 0) != child) - ; - if (!WIFEXITED (status)) - return 2; - if (WEXITSTATUS (status) != 127) - return 3; - return 0; - } - ]])], - [gl_cv_func_posix_spawnp_secure_exec=yes], - [gl_cv_func_posix_spawnp_secure_exec=no], - [case "$host_os" in - # Guess yes on glibc systems (glibc >= 2.15 actually) except GNU/Hurd, - # musl libc, NetBSD. - *-gnu* | *-musl* | netbsd*) - gl_cv_func_posix_spawnp_secure_exec="guessing yes" ;; - # Guess no on GNU/Hurd, macOS, FreeBSD, OpenBSD, AIX, Solaris, Cygwin. - gnu* | darwin* | freebsd* | dragonfly* | openbsd* | aix* | solaris* | cygwin*) - gl_cv_func_posix_spawnp_secure_exec="guessing no" ;; - # If we don't know, obey --enable-cross-guesses. - *) - gl_cv_func_posix_spawnp_secure_exec="$gl_cross_guess_normal" ;; - esac - ]) - rm -f conftest.scr - ]) -]) - -# Prerequisites of lib/spawni.c. -AC_DEFUN([gl_PREREQ_POSIX_SPAWN_INTERNAL], -[ - AC_CHECK_HEADERS([paths.h]) - AC_CHECK_FUNCS([confstr sched_setparam sched_setscheduler setegid seteuid vfork]) -]) - -AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE], -[ - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - gl_POSIX_SPAWN - if test $REPLACE_POSIX_SPAWN = 1; then - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1 - else - dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_addclose - dnl succeeds even if the fd argument is out of range. - AC_CACHE_CHECK([whether posix_spawn_file_actions_addclose works], - [gl_cv_func_posix_spawn_file_actions_addclose_works], - [AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ -#include -int main () -{ - posix_spawn_file_actions_t actions; - if (posix_spawn_file_actions_init (&actions) != 0) - return 1; - if (posix_spawn_file_actions_addclose (&actions, 10000000) == 0) - return 2; - return 0; -}]])], - [gl_cv_func_posix_spawn_file_actions_addclose_works=yes], - [gl_cv_func_posix_spawn_file_actions_addclose_works=no], - [# Guess no on musl libc and Solaris, yes otherwise. - case "$host_os" in - *-musl*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; - solaris*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; - # Guess no on native Windows. - mingw*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;; - *) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing yes" ;; - esac - ]) - ]) - case "$gl_cv_func_posix_spawn_file_actions_addclose_works" in - *yes) ;; - *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1 ;; - esac - fi -]) - -AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2], -[ - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - gl_POSIX_SPAWN - if test $REPLACE_POSIX_SPAWN = 1; then - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1 - else - dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_adddup2 - dnl succeeds even if the fd argument is out of range. - AC_CACHE_CHECK([whether posix_spawn_file_actions_adddup2 works], - [gl_cv_func_posix_spawn_file_actions_adddup2_works], - [AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ -#include -int main () -{ - posix_spawn_file_actions_t actions; - if (posix_spawn_file_actions_init (&actions) != 0) - return 1; - if (posix_spawn_file_actions_adddup2 (&actions, 10000000, 2) == 0) - return 2; - return 0; -}]])], - [gl_cv_func_posix_spawn_file_actions_adddup2_works=yes], - [gl_cv_func_posix_spawn_file_actions_adddup2_works=no], - [# Guess no on musl libc and Solaris, yes otherwise. - case "$host_os" in - *-musl*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";; - solaris*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";; - # Guess no on native Windows. - mingw*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no" ;; - *) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing yes";; - esac - ]) - ]) - case "$gl_cv_func_posix_spawn_file_actions_adddup2_works" in - *yes) ;; - *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1 ;; - esac - fi -]) - -AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN], -[ - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - gl_POSIX_SPAWN - if test $REPLACE_POSIX_SPAWN = 1; then - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1 - else - dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_addopen - dnl succeeds even if the fd argument is out of range. - AC_CACHE_CHECK([whether posix_spawn_file_actions_addopen works], - [gl_cv_func_posix_spawn_file_actions_addopen_works], - [AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ -#include -#include -int main () -{ - posix_spawn_file_actions_t actions; - if (posix_spawn_file_actions_init (&actions) != 0) - return 1; - if (posix_spawn_file_actions_addopen (&actions, 10000000, "foo", 0, O_RDONLY) - == 0) - return 2; - return 0; -}]])], - [gl_cv_func_posix_spawn_file_actions_addopen_works=yes], - [gl_cv_func_posix_spawn_file_actions_addopen_works=no], - [# Guess no on musl libc and Solaris, yes otherwise. - case "$host_os" in - *-musl*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";; - solaris*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";; - # Guess no on native Windows. - mingw*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no" ;; - *) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing yes";; - esac - ]) - ]) - case "$gl_cv_func_posix_spawn_file_actions_addopen_works" in - *yes) ;; - *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1 ;; - esac - fi -]) diff --git a/m4/posix_spawn_faction_addchdir.m4 b/m4/posix_spawn_faction_addchdir.m4 deleted file mode 100644 index 1ce7153d1d1..00000000000 --- a/m4/posix_spawn_faction_addchdir.m4 +++ /dev/null @@ -1,20 +0,0 @@ -# posix_spawn_faction_addchdir.m4 serial 1 -dnl Copyright (C) 2018-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR], -[ - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - AC_REQUIRE([AC_PROG_CC]) - gl_POSIX_SPAWN - AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir posix_spawn_file_actions_addchdir_np]) - if test $ac_cv_func_posix_spawn_file_actions_addchdir = yes; then - dnl This function is not yet standardized. Therefore override the - dnl system's implementation always. - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1 - else - HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0 - fi -]) diff --git a/m4/sched_h.m4 b/m4/sched_h.m4 deleted file mode 100644 index af0c43de079..00000000000 --- a/m4/sched_h.m4 +++ /dev/null @@ -1,91 +0,0 @@ -# sched_h.m4 serial 12 -dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Written by Bruno Haible. - -AC_DEFUN([gl_SCHED_H], -[ - dnl Use AC_REQUIRE here, so that the default behavior below is expanded - dnl once only, before all statements that occur in other macros. - AC_REQUIRE([gl_SCHED_H_DEFAULTS]) - - AC_REQUIRE([AC_CANONICAL_HOST]) - - AC_CHECK_HEADERS_ONCE([sys/cdefs.h]) - AC_CHECK_HEADERS([sched.h], [], [], - [[#if HAVE_SYS_CDEFS_H - #include - #endif - ]]) - gl_NEXT_HEADERS([sched.h]) - - if test "$ac_cv_header_sched_h" = yes; then - HAVE_SCHED_H=1 - else - HAVE_SCHED_H=0 - fi - AC_SUBST([HAVE_SCHED_H]) - - if test "$HAVE_SCHED_H" = 1; then - AC_CHECK_TYPE([struct sched_param], - [HAVE_STRUCT_SCHED_PARAM=1], [HAVE_STRUCT_SCHED_PARAM=0], - [[#if HAVE_SYS_CDEFS_H - #include - #endif - #include - ]]) - else - HAVE_STRUCT_SCHED_PARAM=0 - case "$host_os" in - os2*) - dnl On OS/2 kLIBC, struct sched_param is in spawn.h. - AC_CHECK_TYPE([struct sched_param], - [HAVE_STRUCT_SCHED_PARAM=1], [], - [#include ]) - ;; - vms) - dnl On OpenVMS 7.2 or newer, struct sched_param is in pthread.h. - AC_CHECK_TYPE([struct sched_param], - [HAVE_STRUCT_SCHED_PARAM=1], [], - [#include ]) - ;; - esac - fi - AC_SUBST([HAVE_STRUCT_SCHED_PARAM]) - - if test "$ac_cv_header_sys_cdefs_h" = yes; then - HAVE_SYS_CDEFS_H=1 - else - HAVE_SYS_CDEFS_H=0 - fi - AC_SUBST([HAVE_SYS_CDEFS_H]) - - dnl Ensure the type pid_t gets defined. - AC_REQUIRE([AC_TYPE_PID_T]) - - dnl Check for declarations of anything we want to poison if the - dnl corresponding gnulib module is not in use, if it is not common - dnl enough to be declared everywhere. - gl_WARN_ON_USE_PREPARE([[#include - ]], [sched_yield]) -]) - -AC_DEFUN([gl_SCHED_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_SCHED_H_DEFAULTS]) - gl_MODULE_INDICATOR_SET_VARIABLE([$1]) - dnl Define it also as a C macro, for the benefit of the unit tests. - gl_MODULE_INDICATOR_FOR_TESTS([$1]) -]) - -AC_DEFUN([gl_SCHED_H_DEFAULTS], -[ - GNULIB_SCHED_YIELD=0; AC_SUBST([GNULIB_SCHED_YIELD]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_SCHED_YIELD=1; AC_SUBST([HAVE_SCHED_YIELD]) - REPLACE_SCHED_YIELD=0; AC_SUBST([REPLACE_SCHED_YIELD]) -]) diff --git a/m4/sh-filename.m4 b/m4/sh-filename.m4 deleted file mode 100644 index f7b31548e0d..00000000000 --- a/m4/sh-filename.m4 +++ /dev/null @@ -1,22 +0,0 @@ -# sh-filename.m4 serial 2 -dnl Copyright (C) 2018-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -AC_DEFUN([gl_SH_FILENAME], -[ - AH_VERBATIM([SH_FILENAME], -[/* File name of the Bourne shell. */ -#if defined __CYGWIN__ || defined __ANDROID__ -/* Omit the directory part because - - For 32-bit Cygwin programs in a 64-bit Cygwin environment, the Cygwin - mounts are not visible. - - On Android, /bin/sh does not exist. It's /system/bin/sh instead. */ -# define BOURNE_SHELL "sh" -#else -# define BOURNE_SHELL "/bin/sh" -#endif]) -]) diff --git a/m4/spawn_h.m4 b/m4/spawn_h.m4 deleted file mode 100644 index 781f9f49652..00000000000 --- a/m4/spawn_h.m4 +++ /dev/null @@ -1,136 +0,0 @@ -# spawn_h.m4 serial 18 -dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Written by Bruno Haible. - -AC_DEFUN([gl_SPAWN_H], -[ - dnl Use AC_REQUIRE here, so that the default behavior below is expanded - dnl once only, before all statements that occur in other macros. - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - - dnl is always overridden, because of GNULIB_POSIXCHECK. - gl_CHECK_NEXT_HEADERS([spawn.h]) - - if test $ac_cv_header_spawn_h = yes; then - HAVE_SPAWN_H=1 - AC_CHECK_TYPES([posix_spawnattr_t], [], [HAVE_POSIX_SPAWNATTR_T=0], [[ -#include - ]]) - AC_CHECK_TYPES([posix_spawn_file_actions_t], [], - [HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0], [[ -#include - ]]) - else - HAVE_SPAWN_H=0 - HAVE_POSIX_SPAWNATTR_T=0 - HAVE_POSIX_SPAWN_FILE_ACTIONS_T=0 - fi - AC_SUBST([HAVE_SPAWN_H]) - - dnl Ensure the type pid_t gets defined. - AC_REQUIRE([AC_TYPE_PID_T]) - - dnl Ensure the type mode_t gets defined. - AC_REQUIRE([AC_TYPE_MODE_T]) - - AC_REQUIRE([gl_HAVE_POSIX_SPAWN]) - - AC_REQUIRE([AC_C_RESTRICT]) - - dnl Check for declarations of anything we want to poison if the - dnl corresponding gnulib module is not in use. - gl_WARN_ON_USE_PREPARE([[#include - ]], [posix_spawn posix_spawnp posix_spawnattr_init posix_spawnattr_destroy - posix_spawnattr_getsigdefault posix_spawnattr_setsigdefault - posix_spawnattr_getsigmask posix_spawnattr_setsigmask - posix_spawnattr_getflags posix_spawnattr_setflags - posix_spawnattr_getpgroup posix_spawnattr_setpgroup - posix_spawnattr_getschedpolicy posix_spawnattr_setschedpolicy - posix_spawnattr_getschedparam posix_spawnattr_setschedparam - posix_spawn_file_actions_init posix_spawn_file_actions_destroy - posix_spawn_file_actions_addopen posix_spawn_file_actions_addclose - posix_spawn_file_actions_adddup2 posix_spawn_file_actions_addchdir - posix_spawn_file_actions_addfchdir]) -]) - -dnl Checks whether the system has the functions posix_spawn. -dnl Sets ac_cv_func_posix_spawn and HAVE_POSIX_SPAWN. -AC_DEFUN([gl_HAVE_POSIX_SPAWN], -[ - dnl Use AC_REQUIRE here, so that the default behavior below is expanded - dnl once only, before all statements that occur in other macros. - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - - LIB_POSIX_SPAWN= - AC_SUBST([LIB_POSIX_SPAWN]) - gl_saved_libs=$LIBS - AC_SEARCH_LIBS([posix_spawn], [rt], - [test "$ac_cv_search_posix_spawn" = "none required" || - LIB_POSIX_SPAWN=$ac_cv_search_posix_spawn]) - AC_CHECK_FUNCS([posix_spawn]) - LIBS=$gl_saved_libs - - if test $ac_cv_func_posix_spawn != yes; then - HAVE_POSIX_SPAWN=0 - fi -]) - -AC_DEFUN([gl_SPAWN_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_SPAWN_H_DEFAULTS]) - gl_MODULE_INDICATOR_SET_VARIABLE([$1]) - dnl Define it also as a C macro, for the benefit of the unit tests. - gl_MODULE_INDICATOR_FOR_TESTS([$1]) -]) - -AC_DEFUN([gl_SPAWN_H_DEFAULTS], -[ - GNULIB_POSIX_SPAWN=0; AC_SUBST([GNULIB_POSIX_SPAWN]) - GNULIB_POSIX_SPAWNP=0; AC_SUBST([GNULIB_POSIX_SPAWNP]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN]) - GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY]) - GNULIB_POSIX_SPAWNATTR_INIT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_INIT]) - GNULIB_POSIX_SPAWNATTR_GETFLAGS=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETFLAGS]) - GNULIB_POSIX_SPAWNATTR_SETFLAGS=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETFLAGS]) - GNULIB_POSIX_SPAWNATTR_GETPGROUP=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETPGROUP]) - GNULIB_POSIX_SPAWNATTR_SETPGROUP=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETPGROUP]) - GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM]) - GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM]) - GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY]) - GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY]) - GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT]) - GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT]) - GNULIB_POSIX_SPAWNATTR_GETSIGMASK=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_GETSIGMASK]) - GNULIB_POSIX_SPAWNATTR_SETSIGMASK=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_SETSIGMASK]) - GNULIB_POSIX_SPAWNATTR_DESTROY=0; AC_SUBST([GNULIB_POSIX_SPAWNATTR_DESTROY]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_POSIX_SPAWN=1; AC_SUBST([HAVE_POSIX_SPAWN]) - HAVE_POSIX_SPAWNATTR_T=1; AC_SUBST([HAVE_POSIX_SPAWNATTR_T]) - HAVE_POSIX_SPAWN_FILE_ACTIONS_T=1; - AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_T]) - HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1; - AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) - HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=1; - AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) - REPLACE_POSIX_SPAWN=0; AC_SUBST([REPLACE_POSIX_SPAWN]) - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0; - AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR]) - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0; - AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE]) - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0; - AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2]) - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR=0; - AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR]) - REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0; - AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN]) -]) diff --git a/m4/strchrnul.m4 b/m4/strchrnul.m4 deleted file mode 100644 index a18f0935a51..00000000000 --- a/m4/strchrnul.m4 +++ /dev/null @@ -1,50 +0,0 @@ -# strchrnul.m4 serial 9 -dnl Copyright (C) 2003, 2007, 2009-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_STRCHRNUL], -[ - dnl Persuade glibc to declare strchrnul(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_CHECK_FUNCS([strchrnul]) - if test $ac_cv_func_strchrnul = no; then - HAVE_STRCHRNUL=0 - else - AC_CACHE_CHECK([whether strchrnul works], - [gl_cv_func_strchrnul_works], - [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -#include /* for strchrnul */ -]], [[const char *buf = "a"; - return strchrnul (buf, 'b') != buf + 1; - ]])], - [gl_cv_func_strchrnul_works=yes], - [gl_cv_func_strchrnul_works=no], - [dnl Cygwin 1.7.9 introduced strchrnul, but it was broken until 1.7.10 - AC_EGREP_CPP([Lucky user], - [ -#if defined __CYGWIN__ - #include - #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 9) - Lucky user - #endif -#else - Lucky user -#endif - ], - [gl_cv_func_strchrnul_works="guessing yes"], - [gl_cv_func_strchrnul_works="guessing no"]) - ]) - ]) - case "$gl_cv_func_strchrnul_works" in - *yes) ;; - *) REPLACE_STRCHRNUL=1 ;; - esac - fi -]) - -# Prerequisites of lib/strchrnul.c. -AC_DEFUN([gl_PREREQ_STRCHRNUL], [:]) -- cgit v1.2.1 From 64513abf3eb5f845f56250ff8dc0ab8a9d193956 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 15:17:19 +0200 Subject: Don't compile Gnulib's 'free' on MinGW * nt/mingw-cfg.site (gl_cv_func_free_preserves_errno): Set to "yes" to avoid compiling Gnulib's free.c in the MinGW build. --- nt/mingw-cfg.site | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site index a9ca20cb155..96300774871 100644 --- a/nt/mingw-cfg.site +++ b/nt/mingw-cfg.site @@ -158,3 +158,7 @@ gl_cv_func_copy_file_range=yes # We don't want to build Emacs so it depends on bcrypt.dll, since then # it will refuse to start on systems where that DLL is absent. gl_cv_lib_assume_bcrypt=no +# Don't build the Gnulib free.c: it is not needed, since the w32 +# implementation of 'free' doesn't touch errno, and it emits a +# compilation warning. +gl_cv_func_free_preserves_errno=yes -- cgit v1.2.1 From c3c1863d9504dd04ca6d5f169de2d0348ea78d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Myyr=C3=A4?= Date: Thu, 24 Dec 2020 17:29:49 +0200 Subject: Add support for more EBCDIC code pages IBM2XX There was already charset file present in etc/charsets for IBM2XX character sets but there wasn't definitions for them in Emacs. Add character set and coding system definitions for them. * lisp/language/japanese.el (ibm281, ibm290): * lisp/language/european.el (ibm256, ibm273, ibm274, ibm277) (ibm278, ibm280, ibm284, ibm285, ibm297): * lisp/language/english.el (ibm275): New coding systems. * lisp/international/mule-conf.el (ibm256, ibm273, ibm274) (ibm275, ibm277, ibm278, ibm280, ibm281, ibm284, ibm285, ibm290) (ibm297): New charsets. --- lisp/international/mule-conf.el | 109 ++++++++++++++++++++++++++++++++++++++++ lisp/language/english.el | 8 +++ lisp/language/european.el | 73 +++++++++++++++++++++++++++ lisp/language/japanese.el | 16 ++++++ 4 files changed, 206 insertions(+) diff --git a/lisp/international/mule-conf.el b/lisp/international/mule-conf.el index 99449ad359f..dd6d0326d73 100644 --- a/lisp/international/mule-conf.el +++ b/lisp/international/mule-conf.el @@ -1075,6 +1075,115 @@ (define-charset-alias 'ebcdic-int 'ibm038) (define-charset-alias 'cp038 'ibm038) +(define-charset 'ibm256 + "Netherlands version of EBCDIC" + :short-name "IBM256" + :code-space [0 255] + :mime-charset 'ibm256 + :map "IBM256") +(define-charset-alias 'ebcdic-int1 'ibm256) +(define-charset-alias 'cp256 'ibm256) + +(define-charset 'ibm273 + "Austrian / German version of EBCDIC" + :short-name "IBM273" + :code-space [0 255] + :mime-charset 'ibm273 + :map "IBM273") +(define-charset-alias 'cp273 'ibm273) + +(define-charset 'ibm274 + "Belgian version of EBCDIC" + :short-name "IBM274" + :code-space [0 255] + :mime-charset 'ibm274 + :map "IBM274") +(define-charset-alias 'ebcdic-be 'ibm274) +(define-charset-alias 'cp274 'ibm274) + +(define-charset 'ibm275 + "Brazilian version of EBCDIC" + :short-name "IBM275" + :code-space [0 255] + :mime-charset 'ibm275 + :map "IBM275") +(define-charset-alias 'ebcdic-br 'ibm275) +(define-charset-alias 'cp275 'ibm275) + +(define-charset 'ibm277 + "Danish / Norwegian version of EBCDIC" + :short-name "IBM277" + :code-space [0 255] + :mime-charset 'ibm277 + :map "IBM277") +(define-charset-alias 'ebcdic-cp-dk 'ibm277) +(define-charset-alias 'ebcdic-cp-no 'ibm277) +(define-charset-alias 'cp277 'ibm277) + +(define-charset 'ibm278 + "Finnish / Swedish version of EBCDIC" + :short-name "IBM278" + :code-space [0 255] + :mime-charset 'ibm278 + :map "IBM278") +(define-charset-alias 'ebcdic-cp-fi 'ibm278) +(define-charset-alias 'ebcdic-cp-se 'ibm278) +(define-charset-alias 'cp278 'ibm278) + +(define-charset 'ibm280 + "Italian version of EBCDIC" + :short-name "IBM280" + :code-space [0 255] + :mime-charset 'ibm270 + :map "IBM280") +(define-charset-alias 'ebcdic-cp-it 'ibm280) +(define-charset-alias 'cp280 'ibm280) + +(define-charset 'ibm281 + "Japanese-E version of EBCDIC" + :short-name "IBM281" + :code-space [0 255] + :mime-charset 'ibm281 + :map "IBM281") +(define-charset-alias 'ebcdic-jp-e 'ibm281) +(define-charset-alias 'cp281 'ibm281) + +(define-charset 'ibm284 + "Spanish version of EBCDIC" + :short-name "IBM284" + :code-space [0 255] + :mime-charset 'ibm284 + :map "IBM284") +(define-charset-alias 'ebcdic-cp-es 'ibm284) +(define-charset-alias 'cp284 'ibm284) + +(define-charset 'ibm285 + "UK english version of EBCDIC" + :short-name "IBM285" + :code-space [0 255] + :mime-charset 'ibm285 + :map "IBM285") +(define-charset-alias 'ebcdic-cp-gb 'ibm285) ;; how this differs from ebcdic-uk? +(define-charset-alias 'cp285 'ibm285) + +(define-charset 'ibm290 + "Japanese katakana version of EBCDIC" + :short-name "IBM290" + :code-space [0 255] + :mime-charset 'ibm290 + :map "IBM290") +(define-charset-alias 'ebcdic-jp-kana 'ibm290) +(define-charset-alias 'cp290 'ibm290) + +(define-charset 'ibm297 + "French version of EBCDIC" + :short-name "IBM297" + :code-space [0 255] + :mime-charset 'ibm297 + :map "IBM297") +(define-charset-alias 'ebcdic-cp-fr 'ibm297) +(define-charset-alias 'cp297 'ibm297) + (define-charset 'ibm1047 ;; Says groff: "IBM1047, `EBCDIC Latin 1/Open Systems' used by OS/390 Unix." diff --git a/lisp/language/english.el b/lisp/language/english.el index b7af84c8f75..d5254effa9d 100644 --- a/lisp/language/english.el +++ b/lisp/language/english.el @@ -70,6 +70,14 @@ Nothing special is needed to handle English.") (define-coding-system-alias 'ebcdic-int 'ibm038) (define-coding-system-alias 'cp038 'ibm038) +(define-coding-system 'ibm275 + "Brazilian version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm275) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-br 'ibm275) +(define-coding-system-alias 'cp275 'ibm275) + ;; Make "ASCII" an alias of "English" language environment. (set-language-info-alist "ASCII" (cdr (assoc "English" language-info-alist))) diff --git a/lisp/language/european.el b/lisp/language/european.el index 713a0fdb344..99f062215f6 100644 --- a/lisp/language/european.el +++ b/lisp/language/european.el @@ -324,6 +324,79 @@ Latin-9 is sometimes nicknamed `Latin-0'.")) :mime-charset 'windows-1257) (define-coding-system-alias 'cp1257 'windows-1257) +(define-coding-system 'ibm256 + "Netherlands version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm256) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-int1 'ibm256) +(define-coding-system-alias 'cp256 'ibm256) + +(define-coding-system 'ibm273 + "Austrian / German version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm273) + :mnemonic ?*) +(define-coding-system-alias 'cp273 'ibm273) + +(define-coding-system 'ibm274 + "Belgian version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm274) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-be 'ibm274) +(define-coding-system-alias 'cp274 'ibm274) + +(define-coding-system 'ibm277 + "Danish / Norwegian version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm277) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-dk 'ibm277) +(define-coding-system-alias 'ebcdic-cp-no 'ibm277) +(define-coding-system-alias 'cp277 'ibm277) + +(define-coding-system 'ibm278 + "Finnish / Swedish version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm278) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-fi 'ibm278) +(define-coding-system-alias 'ebcdic-cp-se 'ibm278) +(define-coding-system-alias 'cp278 'ibm278) + +(define-coding-system 'ibm280 + "Italian version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm280) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-it 'ibm280) +(define-coding-system-alias 'cp280 'ibm280) + +(define-coding-system 'ibm284 + "Spanish version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm284) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-es 'ibm284) +(define-coding-system-alias 'cp284 'ibm284) + +(define-coding-system 'ibm285 + "UK english version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm285) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-gb 'ibm285) +(define-coding-system-alias 'cp285 'ibm285) + +(define-coding-system 'ibm297 + "French version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm297) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-cp-fr 'ibm297) +(define-coding-system-alias 'cp297 'ibm297) + (define-coding-system 'cp775 "DOS codepage 775 (PC Baltic, MS-DOS Baltic Rim)" :coding-type 'charset diff --git a/lisp/language/japanese.el b/lisp/language/japanese.el index 9a99245dfde..a517b4ea8eb 100644 --- a/lisp/language/japanese.el +++ b/lisp/language/japanese.el @@ -188,6 +188,22 @@ eucJP-ms is defined in ." (define-coding-system-alias 'shift_jis-2004 'japanese-shift-jis-2004) +(define-coding-system 'ibm281 + "Japanese-E version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm281) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-jp-e 'ibm281) +(define-coding-system-alias 'cp281 'ibm281) + +(define-coding-system 'ibm290 + "Japanese katakana version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm290) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-jp-kana 'ibm290) +(define-coding-system-alias 'cp290 'ibm290) + (set-language-info-alist "Japanese" '((setup-function . setup-japanese-environment-internal) (exit-function . use-default-char-width-table) -- cgit v1.2.1 From a9413dd2d12b4ecf1c76c805a24f46e830e1da3d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 15:58:15 +0200 Subject: Fix last change * lisp/international/mule-conf.el (ebcdic-int1, cp256, cp273) (ebcdic-be, cp274, ebcdic-br, cp275, ebcdic-cp-dk, ebcdic-cp-no) (cp277, ebcdic-cp-fi, ebcdic-cp-se, cp278, ebcdic-cp-it, cp280) (ebcdic-jp-e, cp281, ebcdic-cp-es, cp284, ebcdic-cp-gb, cp285) (ebcdic-jp-kana, cp290, ebcdic-cp-fr, cp297): Remove charset aliases, they are not really needed. * lisp/language/english.el (ibm275): Move from here... * lisp/language/european.el (ibm275): ...to here. --- lisp/international/mule-conf.el | 25 ------------------------- lisp/language/english.el | 8 -------- lisp/language/european.el | 8 ++++++++ 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/lisp/international/mule-conf.el b/lisp/international/mule-conf.el index dd6d0326d73..3b436864f8d 100644 --- a/lisp/international/mule-conf.el +++ b/lisp/international/mule-conf.el @@ -1081,8 +1081,6 @@ :code-space [0 255] :mime-charset 'ibm256 :map "IBM256") -(define-charset-alias 'ebcdic-int1 'ibm256) -(define-charset-alias 'cp256 'ibm256) (define-charset 'ibm273 "Austrian / German version of EBCDIC" @@ -1090,7 +1088,6 @@ :code-space [0 255] :mime-charset 'ibm273 :map "IBM273") -(define-charset-alias 'cp273 'ibm273) (define-charset 'ibm274 "Belgian version of EBCDIC" @@ -1098,8 +1095,6 @@ :code-space [0 255] :mime-charset 'ibm274 :map "IBM274") -(define-charset-alias 'ebcdic-be 'ibm274) -(define-charset-alias 'cp274 'ibm274) (define-charset 'ibm275 "Brazilian version of EBCDIC" @@ -1107,8 +1102,6 @@ :code-space [0 255] :mime-charset 'ibm275 :map "IBM275") -(define-charset-alias 'ebcdic-br 'ibm275) -(define-charset-alias 'cp275 'ibm275) (define-charset 'ibm277 "Danish / Norwegian version of EBCDIC" @@ -1116,9 +1109,6 @@ :code-space [0 255] :mime-charset 'ibm277 :map "IBM277") -(define-charset-alias 'ebcdic-cp-dk 'ibm277) -(define-charset-alias 'ebcdic-cp-no 'ibm277) -(define-charset-alias 'cp277 'ibm277) (define-charset 'ibm278 "Finnish / Swedish version of EBCDIC" @@ -1126,9 +1116,6 @@ :code-space [0 255] :mime-charset 'ibm278 :map "IBM278") -(define-charset-alias 'ebcdic-cp-fi 'ibm278) -(define-charset-alias 'ebcdic-cp-se 'ibm278) -(define-charset-alias 'cp278 'ibm278) (define-charset 'ibm280 "Italian version of EBCDIC" @@ -1136,8 +1123,6 @@ :code-space [0 255] :mime-charset 'ibm270 :map "IBM280") -(define-charset-alias 'ebcdic-cp-it 'ibm280) -(define-charset-alias 'cp280 'ibm280) (define-charset 'ibm281 "Japanese-E version of EBCDIC" @@ -1145,8 +1130,6 @@ :code-space [0 255] :mime-charset 'ibm281 :map "IBM281") -(define-charset-alias 'ebcdic-jp-e 'ibm281) -(define-charset-alias 'cp281 'ibm281) (define-charset 'ibm284 "Spanish version of EBCDIC" @@ -1154,8 +1137,6 @@ :code-space [0 255] :mime-charset 'ibm284 :map "IBM284") -(define-charset-alias 'ebcdic-cp-es 'ibm284) -(define-charset-alias 'cp284 'ibm284) (define-charset 'ibm285 "UK english version of EBCDIC" @@ -1163,8 +1144,6 @@ :code-space [0 255] :mime-charset 'ibm285 :map "IBM285") -(define-charset-alias 'ebcdic-cp-gb 'ibm285) ;; how this differs from ebcdic-uk? -(define-charset-alias 'cp285 'ibm285) (define-charset 'ibm290 "Japanese katakana version of EBCDIC" @@ -1172,8 +1151,6 @@ :code-space [0 255] :mime-charset 'ibm290 :map "IBM290") -(define-charset-alias 'ebcdic-jp-kana 'ibm290) -(define-charset-alias 'cp290 'ibm290) (define-charset 'ibm297 "French version of EBCDIC" @@ -1181,8 +1158,6 @@ :code-space [0 255] :mime-charset 'ibm297 :map "IBM297") -(define-charset-alias 'ebcdic-cp-fr 'ibm297) -(define-charset-alias 'cp297 'ibm297) (define-charset 'ibm1047 ;; Says groff: diff --git a/lisp/language/english.el b/lisp/language/english.el index d5254effa9d..b7af84c8f75 100644 --- a/lisp/language/english.el +++ b/lisp/language/english.el @@ -70,14 +70,6 @@ Nothing special is needed to handle English.") (define-coding-system-alias 'ebcdic-int 'ibm038) (define-coding-system-alias 'cp038 'ibm038) -(define-coding-system 'ibm275 - "Brazilian version of EBCDIC" - :coding-type 'charset - :charset-list '(ibm275) - :mnemonic ?*) -(define-coding-system-alias 'ebcdic-br 'ibm275) -(define-coding-system-alias 'cp275 'ibm275) - ;; Make "ASCII" an alias of "English" language environment. (set-language-info-alist "ASCII" (cdr (assoc "English" language-info-alist))) diff --git a/lisp/language/european.el b/lisp/language/european.el index 99f062215f6..1f9a15333ba 100644 --- a/lisp/language/european.el +++ b/lisp/language/european.el @@ -347,6 +347,14 @@ Latin-9 is sometimes nicknamed `Latin-0'.")) (define-coding-system-alias 'ebcdic-be 'ibm274) (define-coding-system-alias 'cp274 'ibm274) +(define-coding-system 'ibm275 + "Brazilian version of EBCDIC" + :coding-type 'charset + :charset-list '(ibm275) + :mnemonic ?*) +(define-coding-system-alias 'ebcdic-br 'ibm275) +(define-coding-system-alias 'cp275 'ibm275) + (define-coding-system 'ibm277 "Danish / Norwegian version of EBCDIC" :coding-type 'charset -- cgit v1.2.1 From 3649160f618e7ec36dcca7be3212b3572c03de38 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 25 Dec 2020 16:11:49 +0200 Subject: ; * etc/NEWS: Announce the last change. --- etc/NEWS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index b65f184bc82..a320acb5faf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2235,6 +2235,15 @@ do not support the old calling conventions any longer. don't contain any NUL bytes. This avoids subtle bugs caused by silently using only the part of the filename until the first NUL byte. +** New coding-systems for EBCDIC variants. +New coding-systems 'ibm256', 'ibm273', 'ibm274', 'ibm277', 'ibm278', +'ibm280', 'ibm281', 'ibm284', 'ibm285', 'ibm290', 'ibm297'. These are +variants of the EBCDIC encoding tailored to some European and Japanese +locales. They are also available as aliases 'ebcdic-cp-*' (e.g., +'ebcdic-cp-fi' for the Finnish variant 'ibm278'), and 'cp2xx' (e.g., +'cp278' for 'ibm278'). There are also new charsets 'ibm2xx' to +support these coding-systems. + * Changes in Emacs 28.1 on Non-Free Operating Systems -- cgit v1.2.1 From e497a013f71ab89d2524631cd63a74b02c01b022 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 25 Dec 2020 17:05:36 +0100 Subject: Tag Tramp test :unstable * test/lisp/net/tramp-tests.el (tramp-test31-interrupt-process): Tag it :unstable on emba. --- test/lisp/net/tramp-tests.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 9dd98037a0e..fd0c4d6f4b3 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4663,7 +4663,8 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'." (ert-deftest tramp-test31-interrupt-process () "Check `interrupt-process'." - :tags '(:expensive-test) + :tags (if (getenv "EMACS_EMBA_CI") + '(:expensive-test :unstable) '(:expensive-test)) (skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-sh-p)) (skip-unless (not (tramp--test-crypt-p))) -- cgit v1.2.1 From 1ca6add75f81eac83dc7e11ec771c86f14be6a8e Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 25 Dec 2020 18:45:29 +0100 Subject: Tag another Tramp test :unstable on emba * test/lisp/net/tramp-tests.el (tramp-test31-interrupt-process) (tramp-test43-asynchronous-requests): Tag them :unstable on emba. --- test/lisp/net/tramp-tests.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index fd0c4d6f4b3..c8756627936 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -6255,7 +6255,8 @@ This is needed in timer functions as well as process filters and sentinels." "Check parallel asynchronous requests. Such requests could arrive from timers, process filters and process sentinels. They shall not disturb each other." - :tags '(:expensive-test) + :tags (if (getenv "EMACS_EMBA_CI") + '(:expensive-test :unstable) '(:expensive-test)) (skip-unless (tramp--test-enabled)) ;; Prior Emacs 27, `shell-file-name' was hard coded as "/bin/sh" for ;; remote processes in Emacs. That doesn't work for tramp-adb.el. -- cgit v1.2.1 From b242bbb073b501f7a4d4569c2d70cde522abbea3 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Fri, 25 Dec 2020 10:36:25 -0800 Subject: ; lisp/org/org.el: Fix Version header. This is flagged by the single org test that exists in Emacs. --- lisp/org/org.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/org/org.el b/lisp/org/org.el index 1f7e434cefd..06e516539ed 100644 --- a/lisp/org/org.el +++ b/lisp/org/org.el @@ -8,7 +8,7 @@ ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: https://orgmode.org -;; Version: 9.4.3 +;; Version: 9.4.4 ;; This file is part of GNU Emacs. ;; -- cgit v1.2.1 From 00b8fdf29b83092a830f85e73084382c3a166ed3 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 20:56:22 +0100 Subject: Fix gpg-agent killing in mml-sec-tests * test/lisp/gnus/mml-sec-tests.el (mml-sec-test--kill-gpg-agent): Identify the gpg-agent more successfully after the resource dir makeover. --- test/lisp/gnus/mml-sec-tests.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lisp/gnus/mml-sec-tests.el b/test/lisp/gnus/mml-sec-tests.el index a6002b4d51e..20d8e03c385 100644 --- a/test/lisp/gnus/mml-sec-tests.el +++ b/test/lisp/gnus/mml-sec-tests.el @@ -883,7 +883,8 @@ So the second decryption fails." (equal (cdr (assq 'comm atts)) "gpg-agent") (string-match (concat "homedir.*" - (regexp-quote (ert-resource-directory))) + (regexp-quote (directory-file-name + (ert-resource-directory)))) (cdr (assq 'args atts)))) (call-process "kill" nil nil nil (format "%d" pid)))))) -- cgit v1.2.1 From c9fb3474c9d596675d3ae53d7db59264424c7eb3 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 21:09:31 +0100 Subject: Skip some mml tests that rely on CMS if that's not installed --- test/lisp/gnus/mml-sec-tests.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/lisp/gnus/mml-sec-tests.el b/test/lisp/gnus/mml-sec-tests.el index 20d8e03c385..a144e2e4ffb 100644 --- a/test/lisp/gnus/mml-sec-tests.el +++ b/test/lisp/gnus/mml-sec-tests.el @@ -432,6 +432,7 @@ In both cases, the first key is customized for signing and encryption." (ert-deftest mml-secure-select-preferred-keys-4 () "Multiple keys can be recorded per recipient or signature." (skip-unless (test-conf)) + (skip-unless (ignore-errors (epg-find-configuration 'CMS))) (mml-secure-test-fixture (lambda () (let ((pcontext (epg-make-context 'OpenPGP)) @@ -590,6 +591,7 @@ In this test, the single matching key is chosen automatically." "Encrypt message; then decrypt and test for expected result. In this test, the encryption key needs to fixed among multiple ones." (skip-unless (test-conf)) + (skip-unless (ignore-errors (epg-find-configuration 'CMS))) ;; sub@example.org with multiple candidate keys, ;; fixture customizes preferred ones. (mml-secure-test-key-fixture @@ -603,6 +605,7 @@ In this test, the encryption key needs to fixed among multiple ones." "Encrypt message; then decrypt and test for expected result. In this test, encrypt-to-self variables are set to t." (skip-unless (test-conf)) + (skip-unless (ignore-errors (epg-find-configuration 'CMS))) ;; sub@example.org with multiple candidate keys, ;; fixture customizes preferred ones. (mml-secure-test-key-fixture @@ -745,6 +748,7 @@ Use sign-with-sender and encrypt-to-self." (ert-deftest mml-secure-sign-verify-1 () "Sign message with sender; then verify and test for expected result." (skip-unless (test-conf)) + (skip-unless (ignore-errors (epg-find-configuration 'CMS))) (mml-secure-test-key-fixture (lambda () (dolist (method (sign-standards) nil) -- cgit v1.2.1 From e1eabc8ee114a171107e892a3ad1437a9d18069e Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 21:19:37 +0100 Subject: Disable some semantic tests on systems without g++ * test/lisp/cedet/semantic-utest-ia.el: Disable g++ tests on systems without g++. --- test/lisp/cedet/semantic-utest-ia.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lisp/cedet/semantic-utest-ia.el b/test/lisp/cedet/semantic-utest-ia.el index c99ef97b509..ea1a7790985 100644 --- a/test/lisp/cedet/semantic-utest-ia.el +++ b/test/lisp/cedet/semantic-utest-ia.el @@ -86,6 +86,7 @@ (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-nsp.cpp () + (skip-unless (executable-find "g++")) (let ((tst (expand-file-name "testnsp.cpp" semantic-utest-test-directory))) (should (file-exists-p tst)) (should-not (semantic-ia-utest tst)))) @@ -96,6 +97,7 @@ (should-not (semantic-ia-utest tst)))) (ert-deftest semantic-utest-ia-namespace.cpp () + (skip-unless (executable-find "g++")) (let ((tst (expand-file-name "testnsp.cpp" semantic-utest-test-directory))) (should (file-exists-p tst)) (should-not (semantic-ia-utest tst)))) -- cgit v1.2.1 From 443a53874b8cca1b382509fde1f0f8f70f56e916 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 22:29:42 +0100 Subject: Refactor package--list-loaded-files for easier debuggability * lisp/emacs-lisp/package.el (package--files-load-history) (package--list-of-conflicts): Factor out from... (package--list-loaded-files): ... this function for easier debuggability. --- lisp/emacs-lisp/package.el | 53 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index fa93ffd0cc5..0170e61e126 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -825,40 +825,45 @@ correspond to previously loaded files (those returned by (declare-function find-library-name "find-func" (library)) +(defun package--files-load-history () + (delq nil + (mapcar (lambda (x) + (let ((f (car x))) + (and (stringp f) + (file-name-sans-extension f)))) + load-history))) + +(defun package--list-of-conflicts (dir history) + (delq + nil + (mapcar + (lambda (x) (let* ((file (file-relative-name x dir)) + ;; Previously loaded file, if any. + (previous + (ignore-errors + (file-name-sans-extension + (file-truename (find-library-name file))))) + (pos (when previous (member previous history)))) + ;; Return (RELATIVE-FILENAME . HISTORY-POSITION) + (when pos + (cons (file-name-sans-extension file) (length pos))))) + (directory-files-recursively dir "\\`[^\\.].*\\.el\\'")))) + (defun package--list-loaded-files (dir) "Recursively list all files in DIR which correspond to loaded features. Returns the `file-name-sans-extension' of each file, relative to DIR, sorted by most recently loaded last." - (let* ((history (delq nil - (mapcar (lambda (x) - (let ((f (car x))) - (and (stringp f) - (file-name-sans-extension f)))) - load-history))) + (let* ((history (package--files-load-history)) (dir (file-truename dir)) ;; List all files that have already been loaded. - (list-of-conflicts - (delq - nil - (mapcar - (lambda (x) (let* ((file (file-relative-name x dir)) - ;; Previously loaded file, if any. - (previous - (ignore-errors - (file-name-sans-extension - (file-truename (find-library-name file))))) - (pos (when previous (member previous history)))) - ;; Return (RELATIVE-FILENAME . HISTORY-POSITION) - (when pos - (cons (file-name-sans-extension file) (length pos))))) - (directory-files-recursively dir "\\`[^\\.].*\\.el\\'"))))) + (list-of-conflicts (package--list-of-conflicts dir history))) ;; Turn the list of (FILENAME . POS) back into a list of features. Files in ;; subdirectories are returned relative to DIR (so not actually features). (let ((default-directory (file-name-as-directory dir))) (mapcar (lambda (x) (file-truename (car x))) - (sort list-of-conflicts - ;; Sort the files by ascending HISTORY-POSITION. - (lambda (x y) (< (cdr x) (cdr y)))))))) + (sort list-of-conflicts + ;; Sort the files by ascending HISTORY-POSITION. + (lambda (x y) (< (cdr x) (cdr y)))))))) ;;;; `package-activate' ;; This function activates a newer version of a package if an older -- cgit v1.2.1 From d18b1c8c7583b981d4f3d687e49e82250d51634f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 25 Dec 2020 22:44:56 +0100 Subject: Fix package reloading problems on systems with symlinks * lisp/emacs-lisp/package.el (package--files-load-history): We're comparing the truenames, so ensure that we've using that everywhere. This fixes problems when there's symlinks in the paths. --- lisp/emacs-lisp/package.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 0170e61e126..bc450b09d01 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -830,7 +830,7 @@ correspond to previously loaded files (those returned by (mapcar (lambda (x) (let ((f (car x))) (and (stringp f) - (file-name-sans-extension f)))) + (file-name-sans-extension (file-truename f))))) load-history))) (defun package--list-of-conflicts (dir history) -- cgit v1.2.1 From 90e40099debaa876273ae560ed8e66985719dd0c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 26 Dec 2020 00:57:01 +0100 Subject: Fix infloop in memory-report * lisp/emacs-lisp/memory-report.el (memory-report--object-size-1): Fix infloop on circular lists. --- lisp/emacs-lisp/memory-report.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el index b532ddc56c5..332749987c4 100644 --- a/lisp/emacs-lisp/memory-report.el +++ b/lisp/emacs-lisp/memory-report.el @@ -204,7 +204,9 @@ by counted more than once." (cl-incf total (memory-report--object-size counted (car value)))) (if (cdr value) (if (consp (cdr value)) - (setq value (cdr value)) + (if (gethash (cdr value) counted) + (setq value nil) + (setq value (cdr value))) (cl-incf total (memory-report--object-size counted (cdr value))) (setq value nil)) (setq value nil))) -- cgit v1.2.1 From a63855cd21aefee993b622241993043a31894c0c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 26 Dec 2020 03:59:35 +0100 Subject: Kill the scdaemon after doing the mml-sec tests * test/lisp/gnus/mml-sec-tests.el (mml-sec-test--kill-gpg-agent): Kill the scdaemon, too (bug#43358). --- test/lisp/gnus/mml-sec-tests.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lisp/gnus/mml-sec-tests.el b/test/lisp/gnus/mml-sec-tests.el index a144e2e4ffb..e3a8c81cc65 100644 --- a/test/lisp/gnus/mml-sec-tests.el +++ b/test/lisp/gnus/mml-sec-tests.el @@ -884,7 +884,8 @@ So the second decryption fails." (dolist (pid (list-system-processes)) (let ((atts (process-attributes pid))) (when (and (equal (cdr (assq 'user atts)) (user-login-name)) - (equal (cdr (assq 'comm atts)) "gpg-agent") + (or (equal (cdr (assq 'comm atts)) "gpg-agent") + (equal (cdr (assq 'comm atts)) "scdaemon")) (string-match (concat "homedir.*" (regexp-quote (directory-file-name -- cgit v1.2.1 From 60bfa84e41449020d1122a1d18b7c11cb73211f3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Dec 2020 19:16:27 -0800 Subject: Fix issues with lib/malloc out-of-dir builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem reported by Mattias Engdegård in: https://lists.gnu.org/r/emacs-devel/2020-12/msg01626.html * configure.ac: If the scratch_buffer module is enabled, create lib/malloc and (if doing dependencies) lib/deps/malloc. * lib/Makefile.in (DEPFLAGS) [AUTO_DEPEND]: No longer any need to squash lib dependencies into a single directory. (clean): Also remove */*.o and $(DEPDIR)/*/*.d, to clean out malloc/*.o and deps/malloc/*.d. Just remove *.d files in dependencies so that rm does not complain about not being able to remove deps/malloc. (extraclean): Also remove malloc, if it is empty. --- configure.ac | 6 ++++++ lib/Makefile.in | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 888b4151487..bf768441fe3 100644 --- a/configure.ac +++ b/configure.ac @@ -5878,6 +5878,12 @@ if test $AUTO_DEPEND = yes; then AS_MKDIR_P([$dir/deps]) done fi +if $gl_gnulib_enabled_scratch_buffer; then + AS_MKDIR_P([lib/malloc]) + if test $AUTO_DEPEND = yes; then + AS_MKDIR_P([lib/deps/malloc]) + fi +fi AC_OUTPUT diff --git a/lib/Makefile.in b/lib/Makefile.in index a280b7a3311..e6b1ae6a9ab 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -67,7 +67,7 @@ endif DEPDIR = deps ifeq ($(AUTO_DEPEND),yes) - DEPFLAGS = -MMD -MF $(DEPDIR)/$(*F).d -MP + DEPFLAGS = -MMD -MF $(DEPDIR)/$*.d -MP -include $(ALLOBJS:%.o=$(DEPDIR)/%.d) else DEPFLAGS = @@ -118,7 +118,7 @@ TAGS: $(ETAGS) $(tagsfiles) .PHONY: $(ETAGS) tags clean: - rm -f ./*.[ao] ./*-t \#* $(DEPDIR)/* + rm -f ./*.[ao] ./*/*.o ./*-t \#* $(DEPDIR)/*.d $(DEPDIR)/*/*.d mostlyclean: clean rm -f $(filter-out %-t,$(MOSTLYCLEANFILES)) distclean bootstrap-clean: mostlyclean @@ -127,7 +127,7 @@ distclean bootstrap-clean: mostlyclean maintainer-clean: distclean rm -f TAGS gnulib.mk extraclean: distclean - -rmdir sys 2>/dev/null + -rmdir malloc sys 2>/dev/null .PHONY: mostlyclean clean distclean bootstrap-clean maintainer-clean -- cgit v1.2.1 From cf1d7034445e7896c34f88256e5d7f2674a4f7ee Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 26 Dec 2020 10:23:04 +0200 Subject: Fix messages with plural forms in todo-mode.el * lisp/calendar/todo-mode.el (todo-move-item, todo-item-undone) (todo-category-completions): Use 'ngettext' instead of hard-coding plural forms by hand. --- lisp/calendar/todo-mode.el | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 3975a9ba6a9..637df85f5dc 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -2745,9 +2745,10 @@ section in the category moved to." (setq ov (make-overlay (save-excursion (todo-item-start)) (save-excursion (todo-item-end)))) (overlay-put ov 'face 'todo-search)) - (let* ((pl (if (and marked (> (cdr marked) 1)) "s" "")) - (cat+file (todo-read-category (concat "Move item" pl - " to category: ") + (let* ((num (if (not marked) 1 (cdr marked))) + (cat+file (todo-read-category + (ngettext "Move item to category: " + "Move items to category: " num) nil file))) (while (and (equal (car cat+file) cat1) (equal (cdr cat+file) file1)) @@ -2974,7 +2975,7 @@ comments without asking." (interactive) (let* ((cat (todo-current-category)) (marked (assoc cat todo-categories-with-marks)) - (pl (if (and marked (> (cdr marked) 1)) "s" ""))) + (num (if (not marked) 1 (cdr marked)))) (when (or marked (todo-done-item-p)) (let ((buffer-read-only) (opoint (point)) @@ -2982,6 +2983,9 @@ comments without asking." (first 'first) (item-count 0) (diary-count 0) + (omit-prompt (ngettext "Omit comment from restored item? " + "Omit comments from restored items? " + num)) start end item ov npoint undone) (and marked (goto-char (point-min))) (catch 'done @@ -3013,10 +3017,7 @@ comments without asking." (if (eq first 'first) (setq first (if (eq todo-undo-item-omit-comment 'ask) - (when (todo-y-or-n-p - (concat "Omit comment" pl - " from restored item" - pl "? ")) + (when (todo-y-or-n-p omit-prompt) 'omit) (when todo-undo-item-omit-comment 'omit))) t) @@ -5782,11 +5783,13 @@ have been removed." (delete f todo-category-completions-files)) (push f deleted))) (when deleted - (let ((pl (> (length deleted) 1)) + (let ((ndeleted (length deleted)) (names (mapconcat (lambda (f) (concat "\"" f "\"")) deleted ", "))) - (message (concat "File" (if pl "s" "") " %s ha" (if pl "ve" "s") - " been deleted and removed from\n" - "the list of category completion files") + (message (concat + (ngettext "File %s has been deleted and removed from\n" + "Files %s have been deleted and removed from\n" + ndeleted) + "the list of category completion files") names)) (put 'todo-category-completions-files 'custom-type `(set ,@(todo--files-type-list))) -- cgit v1.2.1 From b3c9af9061e09efd94a1f5bd58aed69800da237d Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Thu, 17 Dec 2020 01:04:09 +0300 Subject: Improvements for `:base-uri' svg image property * src/image.c (svg_load): Use ENCODE_FILE for `:base-uri' * doc/lispref/display.texi (SVG Images): Add more documentation for `:base-uri' --- doc/lispref/display.texi | 8 +++++++- src/image.c | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 2b3119ea590..949fd8987c2 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5904,7 +5904,13 @@ string containing the image data as raw bytes. @var{image-type} should be a To @var{svg} add an embedded (raster) image placed at @var{relative-filename}. @var{relative-filename} is searched inside @code{file-name-directory} of the @code{:base-uri} svg image property. -This improves the performance of embedding large images. +@code{:base-uri} specifies a (possibly non-existing) file name of the +svg image to be created, thus all the embedded files are searched +relatively to the @code{:base-uri} filename's directory. If +@code{:base-uri} is ommited, then filename from where svg image is +loaded is used. Using @code{:base-uri} improves the performance of +embedding large images, comparing to @code{svg-embed}, because all the +work is done directly by librsvg. @lisp ;; Embeding /tmp/subdir/rms.jpg and /tmp/another/rms.jpg diff --git a/src/image.c b/src/image.c index 29cd189f177..e99ba09f515 100644 --- a/src/image.c +++ b/src/image.c @@ -9803,8 +9803,9 @@ svg_load (struct frame *f, struct image *img) } /* If the file was slurped into memory properly, parse it. */ if (!STRINGP (base_uri)) - base_uri = ENCODE_FILE (file); - success_p = svg_load_image (f, img, contents, size, SSDATA (base_uri)); + base_uri = file; + success_p = svg_load_image (f, img, contents, size, + SSDATA (ENCODE_FILE (base_uri))); xfree (contents); } /* Else it's not a file, it's a Lisp object. Load the image from a @@ -9822,7 +9823,8 @@ svg_load (struct frame *f, struct image *img) if (!STRINGP (base_uri)) base_uri = BVAR (current_buffer, filename); success_p = svg_load_image (f, img, SSDATA (data), SBYTES (data), - (NILP (base_uri) ? NULL : SSDATA (base_uri))); + (STRINGP (base_uri) ? + SSDATA (ENCODE_FILE (base_uri)) : NULL)); } return success_p; -- cgit v1.2.1 From f9264a3878ba6366aacdf80e3ebba3ba799415a6 Mon Sep 17 00:00:00 2001 From: emacs-f Date: Tue, 8 Dec 2020 18:22:30 -0500 Subject: Avoid missing email messages due to rmail-spam-filter * lisp/mail/rmail-spam-filter.el (rsf--rmail-last-seen-message): New function. (rmail-spam-filter, rmail-get-new-mail-filter-spam): Call 'rsf--rmail-last-seen-message' instead of 'rmail-first-unseen-message'. (Bug#45128) Copyright-paperwork-exempt: yes --- lisp/mail/rmail-spam-filter.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/mail/rmail-spam-filter.el b/lisp/mail/rmail-spam-filter.el index db518482591..4d8c9267f31 100644 --- a/lisp/mail/rmail-spam-filter.el +++ b/lisp/mail/rmail-spam-filter.el @@ -214,6 +214,16 @@ the cdr is set to t. Else, the car is set to nil." ;; rule means this cannot be spam. (setcar result nil))))) +;; Don't spuriously advance to the next unseen message while +;; prompting, because that causes it to then be missed while actually +;; reading mail afterwards! Call this instead of +;; rmail-first-unseen-message. +(defun rsf--rmail-last-seen-message () + (max 1 + ;; 'rmail-first-unseen-message' can return nil in a completely + ;; empty buffer. + (1- (or (rmail-first-unseen-message) 1)))) + (defun rmail-spam-filter (msg) "Return nil if message number MSG is spam based on `rsf-definitions-alist'. If spam, optionally output message to a file `rsf-file' and delete @@ -327,8 +337,7 @@ it from rmail file. Called for each new message retrieved by (if (and (car maybe-spam) (cdr maybe-spam)) ;; Temporarily set rmail-current-message in order to output ;; and delete the spam msg if needed: - (let ((rmail-current-message msg) ; FIXME does this do anything? - (action (cdr (assq 'action + (let ((action (cdr (assq 'action (nth num-element rsf-definitions-alist)))) (newfile (not (file-exists-p rsf-file)))) ;; Check action item in rsf-definitions-alist and do it. @@ -337,7 +346,7 @@ it from rmail file. Called for each new message retrieved by ;; Else the prompt to write a new file leaves the raw ;; mbox buffer visible. (and newfile - (rmail-show-message (rmail-first-unseen-message) t)) + (rmail-show-message (rsf--rmail-last-seen-message) t)) (rmail-output rsf-file) ;; Swap back, else rmail-get-new-mail-1 gets confused. (when newfile @@ -377,7 +386,7 @@ This is called at the end of `rmail-get-new-mail-1' if there is new mail." (sleep-for rsf-sleep-after-message)) (when (> nspam 0) ;; Otherwise sleep or expunge prompt leaves raw mbox buffer showing. - (rmail-show-message (or (rmail-first-unseen-message) 1) t) + (rmail-show-message (or (rsf--rmail-last-seen-message) 1) t) (unwind-protect (progn (if rsf-beep (ding t)) -- cgit v1.2.1 From fd658b810056d41fad9edeba8bdba0594fc87867 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sat, 26 Dec 2020 12:39:10 +0100 Subject: Rename Tramp method "media" to "mtp" (Bug#45402) * doc/misc/tramp.texi (Quick Start Guide, GVFS-based methods): Rename "media" to "mtp". (Bug#45402) * etc/NEWS: Rename Tramp method "media" to "mtp". Fix typos. * lisp/net/tramp-gvfs.el (tramp-gvfs-methods, tramp-media-methods) (tramp-gvfs-activation-uri) (tramp-gvfs-handler-volumeadded-volumeremoved) (tramp-get-media-devices, top): Rename "media" to "mtp". (Bug#45402) --- doc/misc/tramp.texi | 18 +++++++++--------- etc/NEWS | 16 ++++++++-------- lisp/net/tramp-gvfs.el | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index dd350f10c0b..2133dfec35a 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -558,8 +558,8 @@ of the local file name is the share exported by the remote host, @cindex method @option{davs} @cindex @option{dav} method @cindex @option{davs} method -@cindex method @option{media} -@cindex @option{media} method +@cindex method @option{mtp} +@cindex @option{mtp} method On systems, which have installed @acronym{GVFS, the GNOME Virtual File System}, its offered methods could be used by @value{tramp}. Examples @@ -567,7 +567,7 @@ are @file{@trampfn{sftp,user@@host,/path/to/file}}, @file{@trampfn{afp,user@@host,/path/to/file}} (accessing Apple's AFP file system), @file{@trampfn{dav,user@@host,/path/to/file}}, @file{@trampfn{davs,user@@host,/path/to/file}} (for WebDAV shares) and -@file{@trampfn{media,device,/path/to/file}} (for media devices). +@file{@trampfn{mtp,device,/path/to/file}} (for media devices). @anchor{Quick Start Guide: GNOME Online Accounts based methods} @@ -1246,13 +1246,13 @@ Since Google Drive uses cryptic blob file names internally, could produce unexpected behavior in case two files in the same directory have the same @code{display-name}, such a situation must be avoided. -@item @option{media} -@cindex method @option{media} -@cindex @option{media} method +@item @option{mtp} +@cindex method @option{mtp} +@cindex @option{mtp} method @cindex media Media devices, like cell phones, tablets, cameras, can be accessed via -the @option{media} method. Just the device name is needed in order to +the @option{mtp} method. Just the device name is needed in order to specify the host in the file name. However, the device must already be connected via USB, before accessing it. Possible device names are visible via host name completion, @ref{File name completion}. @@ -1263,7 +1263,7 @@ different parts of their file system. @value{tramp} does not require a host name as part of the remote file name when a single media device is connected. @value{tramp} instead -uses @file{@trampfn{media,,}} as the default name. +uses @file{@trampfn{mtp,,}} as the default name. @item @option{nextcloud} @cindex method @option{nextcloud} @@ -1289,7 +1289,7 @@ that for security reasons refuse @command{ssh} connections. @defopt tramp-gvfs-methods This user option is a list of external methods for @acronym{GVFS}@. By default, this list includes @option{afp}, @option{dav}, -@option{davs}, @option{gdrive}, @option{media}, @option{nextcloud} and +@option{davs}, @option{gdrive}, @option{mtp}, @option{nextcloud} and @option{sftp}. Other methods to include are @option{ftp}, @option{http}, @option{https} and @option{smb}. These methods are not intended to be used directly as @acronym{GVFS}-based method. Instead, diff --git a/etc/NEWS b/etc/NEWS index a320acb5faf..d24d8b1f0a2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -384,7 +384,7 @@ If your mouse or trackpad supports it, you can now scroll tabs when the mouse pointer is in the tab line by scrolling left or right. --- -*** New tab-line faces and options +*** New tab-line faces and options. The face 'tab-line-tab-special' is used for tabs whose buffers are special, i.e. not file-backed. The face 'tab-line-tab-inactive-alternate' is used to display inactive tabs @@ -890,7 +890,7 @@ preferred over the eudcb-mab.el backend. ** Tramp +++ -*** New connection method "media", which allows accessing media devices +*** New connection method "mtp", which allows accessing media devices like cell phones, tablets or cameras. +++ @@ -1465,7 +1465,7 @@ that makes it a valid button. --- *** New user option 'authinfo-hide-elements'. -This can be set to nil to inhibit hiding passwords in .authinfo files. +This can be set to nil to inhibit hiding passwords in ".authinfo" files. +++ *** A number of new string manipulation functions have been added. @@ -2009,7 +2009,7 @@ used in. +++ ** 'truncate-string-ellipsis' now uses '…' by default. Modes that use 'truncate-string-to-width' with non-nil, non-string -argument 'ellipsis', will now indicate truncation using '…' when +argument ELLIPSIS, will now indicate truncation using '…' when the selected frame can display it, and using "..." otherwise. +++ @@ -2046,7 +2046,7 @@ of its file argument. +++ ** New utility function 'directory-empty-p'. -This predicate tests whether a given filename is an accessible +This predicate tests whether a given file name is an accessible directory and whether it contains no other directories or files. +++ @@ -2221,7 +2221,7 @@ Until it is solved you could ignore such errors by performing +++ ** Buffers can now be created with certain hooks disabled. The functions 'get-buffer-create' and 'generate-new-buffer' accept a -new optional argument 'inhibit-buffer-hooks'. If non-nil, the new +new optional argument INHIBIT-BUFFER-HOOKS. If non-nil, the new buffer does not run the hooks 'kill-buffer-hook', 'kill-buffer-query-functions', and 'buffer-list-update-hook'. This avoids slowing down internal or temporary buffers that are never @@ -2231,9 +2231,9 @@ presented to users or passed on to other applications. ** 'start-process-shell-command' and 'start-file-process-shell-command' do not support the old calling conventions any longer. -** Functions operating on local filenames now check that the filenames +** Functions operating on local file names now check that the file names don't contain any NUL bytes. This avoids subtle bugs caused by -silently using only the part of the filename until the first NUL byte. +silently using only the part of the file name until the first NUL byte. ** New coding-systems for EBCDIC variants. New coding-systems 'ibm256', 'ibm273', 'ibm274', 'ibm277', 'ibm278', diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 1722c53be05..fa1a90bc844 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -49,12 +49,12 @@ ;; The user option `tramp-gvfs-methods' contains the list of supported ;; connection methods. Per default, these are "afp", "dav", "davs", -;; "gdrive", "media", "nextcloud" and "sftp". +;; "gdrive", "mtp", "nextcloud" and "sftp". ;; "gdrive" and "nextcloud" connection methods require a respective ;; account in GNOME Online Accounts, with enabled "Files" service. -;; The "media" connection method is responsible for media devices, +;; The "mtp" connection method is responsible for media devices, ;; like cell phones, tablets, cameras etc. The device must already be ;; connected via USB, before accessing it. @@ -131,7 +131,7 @@ ;;;###tramp-autoload (defcustom tramp-gvfs-methods - '("afp" "dav" "davs" "gdrive" "media" "nextcloud" "sftp") + '("afp" "dav" "davs" "gdrive" "mtp" "nextcloud" "sftp") "List of methods for remote files, accessed with GVFS." :group 'tramp :version "28.1" @@ -142,7 +142,7 @@ (const "gdrive") (const "http") (const "https") - (const "media") + (const "mtp") (const "nextcloud") (const "sftp") (const "smb")))) @@ -159,7 +159,7 @@ ;;;###tramp-autoload (defvar tramp-media-methods '("afc" "gphoto2" "mtp") - "List of GVFS methods which are covered by the \"media\" method. + "List of GVFS methods which are covered by the \"mtp\" method. They are checked during start up via `tramp-gvfs-interface-remotevolumemonitor'.") @@ -1639,7 +1639,7 @@ ID-FORMAT valid values are `string' and `integer'." (if (tramp-tramp-file-p filename) (with-parsed-tramp-file-name filename nil ;; Ensure that media devices are cached. - (when (string-equal method "media") + (when (string-equal method "mtp") (tramp-get-media-device v)) (with-tramp-connection-property v "activation-uri" (setq localname "/") @@ -1649,7 +1649,7 @@ ID-FORMAT valid values are `string' and `integer'." (setq method "davs" localname (concat (tramp-gvfs-get-remote-prefix v) localname))) - (when (string-equal "media" method) + (when (string-equal "mtp" method) (when-let ((media (tramp-get-connection-property v "media-device" nil))) (setq method (tramp-media-device-method media) @@ -2058,7 +2058,7 @@ and \"org.gtk.Private.RemoteVolumeMonitor.VolumeRemoved\" signals." (uri (url-generic-parse-url (nth 5 volume))) (method (url-type uri)) (vec (make-tramp-file-name - :method "media" + :method "mtp" ;; A host name cannot contain spaces. :host (tramp-compat-string-replace " " "_" (nth 1 volume)))) (media (make-tramp-media-device @@ -2363,7 +2363,7 @@ VEC is used only for traces." tramp-gvfs-interface-remotevolumemonitor "List"))) (let* ((uri (url-generic-parse-url (nth 5 volume))) (vec (make-tramp-file-name - :method "media" + :method "mtp" ;; A host name cannot contain spaces. :host (tramp-compat-string-replace " " "_" (nth 1 volume)))) (media (make-tramp-media-device @@ -2376,12 +2376,12 @@ VEC is used only for traces." (tramp-set-connection-property vec "media-device" media) (tramp-set-connection-property media "vector" vec)))) - ;; Adapt default host name, supporting /media:: when possible. + ;; Adapt default host name, supporting /mtp:: when possible. (setq tramp-default-host-alist (append - `(("media" nil ,(if (= (length devices) 1) (car devices) ""))) + `(("mtp" nil ,(if (= (length devices) 1) (car devices) ""))) (delete - (assoc "media" tramp-default-host-alist) + (assoc "mtp" tramp-default-host-alist) tramp-default-host-alist))))) (defun tramp-parse-media-names (service) @@ -2498,7 +2498,7 @@ This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi." ;; Add completion functions for media devices. (tramp-get-media-devices nil) (tramp-set-completion-function - "media" + "mtp" (mapcar (lambda (method) `(tramp-parse-media-names ,(format "_%s._tcp" method))) tramp-media-methods)))) -- cgit v1.2.1 From 25fb44fad15743cd7725aa73681c2652d5a23b09 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 26 Dec 2020 15:01:52 +0200 Subject: Fix test/src/process-tests on MS-Windows * src/process.c (network_lookup_address_info_1) [WINDOWSNT]: Initialize winsock. --- src/process.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/process.c b/src/process.c index 98b575fc864..28ab15c9038 100644 --- a/src/process.c +++ b/src/process.c @@ -4512,6 +4512,12 @@ network_lookup_address_info_1 (Lisp_Object host, const char *service, if (STRING_MULTIBYTE (host) && SBYTES (host) != SCHARS (host)) error ("Non-ASCII hostname %s detected, please use puny-encode-domain", SSDATA (host)); + +#ifdef WINDOWSNT + /* Ensure socket support is loaded if available. */ + init_winsock (TRUE); +#endif + ret = getaddrinfo (SSDATA (host), service, hints, res); if (ret) { -- cgit v1.2.1 From 4b2ca6bfc079c66cfcf39f2f36dc139012787535 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 26 Dec 2020 12:21:17 -0500 Subject: * lisp/forms.el (forms--run-functions): New function (forms--intuit-from-file, forms-save-buffer): Use it. (forms-mode): Use it to fix regression. Remove always-true test. Fix incorrect uses of `fboundp`. (forms--iif-hook): Use `add-hook`. (forms--iif-post-command-hook): Use `remove-hook` and fix typo. (forms--debug): Use `mapconcat`. --- lisp/forms.el | 63 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/lisp/forms.el b/lisp/forms.el index 8974f99ef57..b8638bc6e20 100644 --- a/lisp/forms.el +++ b/lisp/forms.el @@ -436,6 +436,14 @@ Also, initial position is at last record." (defvar read-file-filter) ; bound in forms--intuit-from-file +;; The code used to use `run-hooks' but in a way that's actually +;; incompatible with hooks (and with lexical scoping), so this function +;; approximates the actual behavior that `run-hooks' provided. +(defun forms--run-functions (functions) + (if (functionp functions) + (funcall functions) + (mapc #'funcall functions))) + ;;;###autoload (defun forms-mode (&optional primary) ;; FIXME: use define-derived-mode @@ -547,8 +555,6 @@ Commands: Equivalent keys in read-only mode: "`forms-multi-line' is equal to `forms-field-sep'"))) (error (concat "Forms control file error: " "`forms-multi-line' must be nil or a one-character string")))) - (or (fboundp 'set-text-properties) - (setq forms-use-text-properties nil)) ;; Validate and process forms-format-list. ;;(message "forms: pre-processing format list...") @@ -568,12 +574,12 @@ Commands: Equivalent keys in read-only mode: ;; Check if record filters are defined. (if (and forms-new-record-filter - (not (fboundp forms-new-record-filter))) + (not (functionp forms-new-record-filter))) (error (concat "Forms control file error: " "`forms-new-record-filter' is not a function"))) (if (and forms-modified-record-filter - (not (fboundp forms-modified-record-filter))) + (not (functionp forms-modified-record-filter))) (error (concat "Forms control file error: " "`forms-modified-record-filter' is not a function"))) @@ -647,7 +653,7 @@ Commands: Equivalent keys in read-only mode: (with-current-buffer forms--file-buffer (let ((inhibit-read-only t) (file-modified (buffer-modified-p))) - (mapc #'funcall read-file-filter) + (forms--run-functions read-file-filter) (if (not file-modified) (set-buffer-modified-p nil))) (if write-file-filter (add-hook 'write-file-functions write-file-filter nil t))) @@ -875,8 +881,7 @@ Commands: Equivalent keys in read-only mode: (list 'face forms--rw-face 'front-sticky '(face)))) ;; Enable `post-command-hook' to restore the properties. - (setq post-command-hook - (append (list 'forms--iif-post-command-hook) post-command-hook))) + (add-hook 'post-command-hook #'forms--iif-post-command-hook)) ;; No action needed. Clear marker. (setq forms--iif-start nil))) @@ -885,8 +890,7 @@ Commands: Equivalent keys in read-only mode: "`post-command-hook' function for read-only segments." ;; Disable `post-command-hook'. - (setq post-command-hook - (delq 'forms--iif-hook-post-command-hook post-command-hook)) + (remove-hook 'post-command-hook #'forms--iif-post-command-hook) ;; Restore properties. (if forms--iif-start @@ -916,7 +920,7 @@ Commands: Equivalent keys in read-only mode: (if forms-use-text-properties `(lambda (arg) (let ((inhibit-read-only t)) - ,@(apply 'append + ,@(apply #'append (mapcar #'forms--make-format-elt-using-text-properties forms-format-list)) ;; Prevent insertion before the first text. @@ -929,7 +933,7 @@ Commands: Equivalent keys in read-only mode: '(rear-nonsticky nil))) (setq forms--iif-start nil)) `(lambda (arg) - ,@(apply 'append + ,@(apply #'append (mapcar #'forms--make-format-elt forms-format-list))))) ;; We have tallied the number of markers and dynamic texts, @@ -1100,7 +1104,7 @@ Commands: Equivalent keys in read-only mode: `(lambda nil (let (here) (goto-char (point-min)) - ,@(apply 'append + ,@(apply #'append (mapcar #'forms--make-parser-elt (append forms-format-list (list nil))))))))) @@ -1219,7 +1223,7 @@ Commands: Equivalent keys in read-only mode: (setq the-record (with-current-buffer forms--file-buffer (let ((inhibit-read-only t)) - (run-hooks 'read-file-filter)) + (forms--run-functions read-file-filter)) (goto-char (point-min)) (forms--get-record))) @@ -1427,7 +1431,7 @@ Commands: Equivalent keys in read-only mode: ;; ;; We have our own revert function - use it. (make-local-variable 'revert-buffer-function) - (setq revert-buffer-function 'forms--revert-buffer) + (setq revert-buffer-function #'forms--revert-buffer) t) @@ -1900,7 +1904,7 @@ after writing out the data." ;; Write file hooks are run via write-file-functions. ;; (if write-file-filter ;; (save-excursion - ;; (run-hooks 'write-file-filter))) + ;; (forms--run-functions write-file-filter))) ;; If they have a write-file-filter, force the buffer to be ;; saved even if it doesn't seem to be changed. First, they @@ -1912,7 +1916,7 @@ after writing out the data." (save-buffer args) (if read-file-filter (save-excursion - (run-hooks 'read-file-filter))) + (forms--run-functions read-file-filter))) (set-buffer-modified-p nil))) ;; Make sure we end up with the same record number as we started. ;; Since read-file-filter may perform arbitrary transformations on @@ -2037,20 +2041,19 @@ Usage: (setq forms-number-of-fields (defun forms--debug (&rest args) "Internal debugging routine." (if forms--debug - (let ((ret nil)) - (while args - (let ((el (car-safe args))) - (setq args (cdr-safe args)) - (if (stringp el) - (setq ret (concat ret el)) - (setq ret (concat ret (prin1-to-string el) " = ")) - (if (boundp el) - (let ((vel (eval el))) - (setq ret (concat ret (prin1-to-string vel) "\n"))) - (setq ret (concat ret "" "\n"))) - (if (fboundp el) - (setq ret (concat ret (prin1-to-string (symbol-function el)) - "\n")))))) + (let ((ret + (mapconcat + (lambda (el) + (if (stringp el) el + (concat (prin1-to-string el) " = " + (if (boundp el) + (prin1-to-string (eval el)) + "") + "\n" + (if (fboundp el) + (concat (prin1-to-string (symbol-function el)) + "\n"))))) + args ""))) (with-current-buffer (get-buffer-create "*forms-mode debug*") (if (zerop (buffer-size)) (emacs-lisp-mode)) -- cgit v1.2.1 From 714ca849ba658405ddde698cdc5836c4c9b289ca Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 26 Dec 2020 23:13:29 +0100 Subject: Improve the edebug-form-data doc string * lisp/emacs-lisp/edebug.el (edebug-form-data): Doc string clarification (bug#42776). --- lisp/emacs-lisp/edebug.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index f242e922bde..8e5ece3605d 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -592,7 +592,7 @@ already is one.)" "A list of entries associating symbols with buffer regions. Each entry is an `edebug--form-data' struct with fields: SYMBOL, BEGIN-MARKER, and END-MARKER. The markers -are at the beginning and end of an entry level form and SYMBOL is +are at the beginning and end of an instrumented form and SYMBOL is a symbol that holds all edebug related information for the form on its property list. -- cgit v1.2.1 From 0f790464d547dd57a857d88dab309b286067ac45 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 27 Dec 2020 09:00:23 +0100 Subject: Add new predicates for sequence lengths * doc/lispref/sequences.texi (Sequence Functions): Document them. * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns): Mark them as side-effect-free. * lisp/emacs-lisp/shortdoc.el (list): Mention them. * src/fns.c (Flength): Mention them in the doc string. (length_internal): New function. (Flength_less, Flength_greater, Flength_equal): New defuns. (syms_of_fns): Sym them. --- doc/lispref/sequences.texi | 15 +++++++++ etc/NEWS | 6 ++++ lisp/emacs-lisp/byte-opt.el | 4 ++- lisp/emacs-lisp/shortdoc.el | 6 ++++ src/fns.c | 76 ++++++++++++++++++++++++++++++++++++++++++++- test/src/fns-tests.el | 30 ++++++++++++++++++ 6 files changed, 135 insertions(+), 2 deletions(-) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 952834bd4e3..57b49847e7f 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -116,6 +116,21 @@ If you need to compute the width of a string on display, you should use since @code{length} only counts the number of characters, but does not account for the display width of each character. +@defun length< sequence length +Return non-@code{nil} if @var{sequence} is shorter than @var{length}. +This may be more efficient than computing the length of @var{sequence} +if @var{sequence} is a long list. +@end defun + +@defun length> sequence length +Return non-@code{nil} if @var{sequence} is longer than @var{length}. +@end defun + +@defun length= sequence length +Return non-@code{nil} if the length of @var{sequence} is equal to +@var{length}. +@end defun + @defun elt sequence index @anchor{Definition of elt} @cindex elements of sequences diff --git a/etc/NEWS b/etc/NEWS index d24d8b1f0a2..9ae8cc91d63 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1460,6 +1460,12 @@ that makes it a valid button. ** Miscellaneous ++++ +*** New predicate functions 'length<', 'length>' and 'length='. +Using these functions may be more efficient than using 'length' (if +the length of a (long) list is being computed just to compare this +length to a number). + --- *** 'remove-hook' is now an interactive command. diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 469bbe6c7c0..0eee6e9d015 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -1169,7 +1169,9 @@ hash-table-count int-to-string intern-soft isnan keymap-parent - lax-plist-get ldexp length line-beginning-position line-end-position + lax-plist-get ldexp + length length< length> length= + line-beginning-position line-end-position local-variable-if-set-p local-variable-p locale-info log log10 logand logb logcount logior lognot logxor lsh make-byte-code make-list make-string make-symbol marker-buffer max diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 9d183e0d4e9..c6259f89711 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -618,6 +618,12 @@ There can be any number of :example/:result elements." "Data About Lists" (length :eval (length '(a b c))) + (length< + :eval (lenth< '(a b c) 1)) + (length> + :eval (lenth> '(a b c) 1)) + (length= + :eval (lenth> '(a b c) 3)) (safe-length :eval (safe-length '(a b c)))) diff --git a/src/fns.c b/src/fns.c index 646c3ed0834..0fded92aeb2 100644 --- a/src/fns.c +++ b/src/fns.c @@ -105,9 +105,14 @@ list_length (Lisp_Object list) DEFUN ("length", Flength, Slength, 1, 1, 0, doc: /* Return the length of vector, list or string SEQUENCE. A byte-code function object is also allowed. + If the string contains multibyte characters, this is not necessarily the number of bytes in the string; it is the number of characters. -To get the number of bytes, use `string-bytes'. */) +To get the number of bytes, use `string-bytes'. + +If the length of a list is being computed to compare to a (small) +number, the `string<', `string>' and `string=' functions may be more +efficient. */) (Lisp_Object sequence) { EMACS_INT val; @@ -145,6 +150,72 @@ least the number of distinct elements. */) return make_fixnum (len); } +static inline +EMACS_INT length_internal (Lisp_Object sequence, int len) +{ + /* If LENGTH is short (arbitrarily chosen cut-off point), use a + fast loop that doesn't care about whether SEQUENCE is + circular or not. */ + if (len < 0xffff) + while (CONSP (sequence)) + { + if (--len == 0) + return -1; + sequence = XCDR (sequence); + } + /* Signal an error on circular lists. */ + else + FOR_EACH_TAIL (sequence) + if (--len == 0) + return -1; + return len; +} + +DEFUN ("length<", Flength_less, Slength_less, 2, 2, 0, + doc: /* Return non-nil if SEQUENCE is shorter than LENGTH. +See `length' for allowed values of SEQUENCE and how elements are +counted. */) + (Lisp_Object sequence, Lisp_Object length) +{ + CHECK_FIXNUM (length); + EMACS_INT len = XFIXNUM (length); + + if (CONSP (sequence)) + return length_internal (sequence, len) == -1? Qnil: Qt; + else + return XFIXNUM (Flength (sequence)) < len? Qt: Qnil; +} + +DEFUN ("length>", Flength_greater, Slength_greater, 2, 2, 0, + doc: /* Return non-nil if SEQUENCE is longer than LENGTH. +See `length' for allowed values of SEQUENCE and how elements are +counted. */) + (Lisp_Object sequence, Lisp_Object length) +{ + CHECK_FIXNUM (length); + EMACS_INT len = XFIXNUM (length); + + if (CONSP (sequence)) + return length_internal (sequence, len + 1) == -1? Qt: Qnil; + else + return XFIXNUM (Flength (sequence)) > len? Qt: Qnil; +} + +DEFUN ("length=", Flength_equal, Slength_equal, 2, 2, 0, + doc: /* Return non-nil if SEQUENCE is equal to LENGTH. +See `length' for allowed values of SEQUENCE and how elements are +counted. */) + (Lisp_Object sequence, Lisp_Object length) +{ + CHECK_FIXNUM (length); + EMACS_INT len = XFIXNUM (length); + + if (CONSP (sequence)) + return length_internal (sequence, len + 1) == 1? Qt: Qnil; + else + return XFIXNUM (Flength (sequence)) == len? Qt: Qnil; +} + DEFUN ("proper-list-p", Fproper_list_p, Sproper_list_p, 1, 1, 0, doc: /* Return OBJECT's length if it is a proper list, nil otherwise. A proper list is neither circular nor dotted (i.e., its last cdr is nil). */ @@ -5721,6 +5792,9 @@ this variable. */); defsubr (&Srandom); defsubr (&Slength); defsubr (&Ssafe_length); + defsubr (&Slength_less); + defsubr (&Slength_greater); + defsubr (&Slength_equal); defsubr (&Sproper_list_p); defsubr (&Sstring_bytes); defsubr (&Sstring_distance); diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index eaa569e0d95..3486c745bf3 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -999,3 +999,33 @@ (object-intervals (current-buffer))) '((0 1 (foo 1)) (1 2 (zot 3 foo 1)) (2 4 (zot 3 bar 2)) (4 5 (bar 2)) (5 6 nil))))) + +(ert-deftest length-equals-tests () + (should-not (length< (list 1 2 3) 2)) + (should-not (length< (list 1 2 3) 3)) + (should (length< (list 1 2 3) 4)) + + (should-not (length< "abc" 2)) + (should-not (length< "abc" 3)) + (should (length< "abc" 4)) + + (should (length> (list 1 2 3) 2)) + (should-not (length> (list 1 2 3) 3)) + (should-not (length> (list 1 2 3) 4)) + + (should (length> "abc" 2)) + (should-not (length> "abc" 3)) + (should-not (length> "abc" 4)) + + (should-not (length= (list 1 2 3) 2)) + (should (length= (list 1 2 3) 3)) + (should-not (length= (list 1 2 3) 4)) + + (should-not (length= "abc" 2)) + (should (length= "abc" 3)) + (should-not (length= "abc" 4)) + + (should-error + (let ((list (list 1))) + (setcdr list list) + (length< list #x1fffe)))) -- cgit v1.2.1 From 80420faf4921ffe5e9d4c4f9595941acf3156e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Sun, 27 Dec 2020 09:04:56 +0100 Subject: Improve "find definition" in *Help* buffers * lisp/emacs-lisp/find-func.el (find-function-search-for-symbol): If our regexp algorithm could not find a location for the symbol definition, resort to find-function--search-by-expanding-macros. * test/lisp/emacs-lisp/find-func-tests.el: Add a automatic test for a function and variable generated by a macro. * etc/NEWS: Advertise the improved functionality (bug#45443). --- etc/NEWS | 6 +++ lisp/emacs-lisp/find-func.el | 65 ++++++++++++++++++++++++++++++++- test/lisp/emacs-lisp/find-func-tests.el | 10 +++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 9ae8cc91d63..4f072df31c5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -114,6 +114,12 @@ choosing a group, or clicking a button in the "*Help*" buffers when looking at the doc string of a function that belongs to one of these groups. +--- +** Improved "find definition" feature of *Help* buffers. +Now clicking on the link to find the definition of functions generated +by 'cl-defstruct', or variables generated by 'define-derived-mode', +for example, will go to the exact place where they are defined. + ** New variable 'redisplay-skip-initial-frame' to enable batch redisplay tests. Setting it to nil forces the redisplay to do its job even in the initial frame used in batch mode. diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 074e7db295b..7796a72ecfd 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -389,7 +389,70 @@ The search is done in the source for library LIBRARY." (progn (beginning-of-line) (cons (current-buffer) (point))) - (cons (current-buffer) nil))))))))) + ;; If the regexp search didn't find the location of + ;; the symbol (for example, because it is generated by + ;; a macro), try a slightly more expensive search that + ;; expands macros until it finds the symbol. + (cons (current-buffer) + (find-function--search-by-expanding-macros + (current-buffer) symbol type)))))))))) + +(defun find-function--try-macroexpand (form) + "Try to macroexpand FORM in full or partially. +This is a best-effort operation in which if macroexpansion fails, +this function returns FORM as is." + (ignore-errors + (or + (macroexpand-all form) + (macroexpand-1 form) + form))) + +(defun find-function--any-subform-p (form pred) + "Walk FORM and apply PRED to its subexpressions. +Return t if any PRED returns t." + (cond + ((not (consp form)) nil) + ((funcall pred form) t) + (t + (cl-destructuring-bind (left-child . right-child) form + (or + (find-function--any-subform-p left-child pred) + (find-function--any-subform-p right-child pred)))))) + +(defun find-function--search-by-expanding-macros (buf symbol type) + "Expand macros in BUF to search for the definition of SYMBOL of TYPE." + (catch 'found + (with-current-buffer buf + (save-excursion + (goto-char (point-min)) + (condition-case nil + (while t + (let ((form (read (current-buffer))) + (expected-symbol-p + (lambda (form) + (cond + ((null type) + ;; Check if a given form is a `defalias' to + ;; SYM, the function name we are searching + ;; for. All functions in Emacs Lisp + ;; ultimately expand to a `defalias' form + ;; after several steps of macroexpansion. + (and (eq (car-safe form) 'defalias) + (equal (car-safe (cdr form)) + `(quote ,symbol)))) + ((eq type 'defvar) + ;; Variables generated by macros ultimately + ;; expand to `defvar'. + (and (eq (car-safe form) 'defvar) + (eq (car-safe (cdr form)) symbol))) + (t nil))))) + (when (find-function--any-subform-p + (find-function--try-macroexpand form) + expected-symbol-p) + ;; We want to return the location at the beginning + ;; of the macro, so move back one sexp. + (throw 'found (progn (backward-sexp) (point)))))) + (end-of-file nil)))))) (defun find-function-library (function &optional lisp-only verbose) "Return the pair (ORIG-FUNCTION . LIBRARY) for FUNCTION. diff --git a/test/lisp/emacs-lisp/find-func-tests.el b/test/lisp/emacs-lisp/find-func-tests.el index d77eb6757ff..03df4bb9ff4 100644 --- a/test/lisp/emacs-lisp/find-func-tests.el +++ b/test/lisp/emacs-lisp/find-func-tests.el @@ -43,5 +43,15 @@ (concat data-directory (kbd "n x / TAB RET")) (read-library-name))))) +;; Avoid a byte-compilation warning that may confuse people reading +;; the result of the following test. +(declare-function compilation--message->loc nil "compile") + +(ert-deftest find-func-tests--locate-macro-generated-symbols () ;bug#45443 + (should (cdr (find-function-search-for-symbol + #'compilation--message->loc nil "compile"))) + (should (cdr (find-function-search-for-symbol + 'c-mode-hook 'defvar "cc-mode")))) + (provide 'find-func-tests) ;;; find-func-tests.el ends here -- cgit v1.2.1 From eb98afaf354288c583ceb2fbdd647841d5c76b2d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 27 Dec 2020 09:22:02 +0100 Subject: Fix up length_internal with degenerate length inputs * src/fns.c (length_internal): Protect against edge conditions. --- src/fns.c | 7 +++++-- test/src/fns-tests.el | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/fns.c b/src/fns.c index 0fded92aeb2..6aad119d1f9 100644 --- a/src/fns.c +++ b/src/fns.c @@ -159,14 +159,14 @@ EMACS_INT length_internal (Lisp_Object sequence, int len) if (len < 0xffff) while (CONSP (sequence)) { - if (--len == 0) + if (--len <= 0) return -1; sequence = XCDR (sequence); } /* Signal an error on circular lists. */ else FOR_EACH_TAIL (sequence) - if (--len == 0) + if (--len <= 0) return -1; return len; } @@ -210,6 +210,9 @@ counted. */) CHECK_FIXNUM (length); EMACS_INT len = XFIXNUM (length); + if (len < 0) + return Qnil; + if (CONSP (sequence)) return length_internal (sequence, len + 1) == 1? Qt: Qnil; else diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 3486c745bf3..e66dad44a1a 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -1025,6 +1025,17 @@ (should (length= "abc" 3)) (should-not (length= "abc" 4)) + (should-not (length< (list 1 2 3) -1)) + (should-not (length< (list 1 2 3) 0)) + (should-not (length< (list 1 2 3) -10)) + + (should (length> (list 1 2 3) -1)) + (should (length> (list 1 2 3) 0)) + + (should-not (length= (list 1 2 3) -1)) + (should-not (length= (list 1 2 3) 0)) + (should-not (length= (list 1 2 3) 1)) + (should-error (let ((list (list 1))) (setcdr list list) -- cgit v1.2.1 From 8bc727d0b4e46554ee4e92c1d1db7d3b3e672068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= Date: Sun, 27 Dec 2020 11:43:19 +0100 Subject: ; Fix the recent `length' doc string addition --- src/fns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fns.c b/src/fns.c index 6aad119d1f9..217e3b62cca 100644 --- a/src/fns.c +++ b/src/fns.c @@ -111,7 +111,7 @@ the number of bytes in the string; it is the number of characters. To get the number of bytes, use `string-bytes'. If the length of a list is being computed to compare to a (small) -number, the `string<', `string>' and `string=' functions may be more +number, the `length<', `length>' and `length=' functions may be more efficient. */) (Lisp_Object sequence) { -- cgit v1.2.1 From df882c9701755e2ae063f05d3381de14ae09951e Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sun, 27 Dec 2020 13:14:30 +0000 Subject: ; Fix recent shortdoc.el and fns.c additions * lisp/emacs-lisp/shortdoc.el (list): Fix typos. * src/fns.c (Flength_equal): Fix docstring. --- lisp/emacs-lisp/shortdoc.el | 6 +++--- src/fns.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index c6259f89711..7fb1a88b861 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -619,11 +619,11 @@ There can be any number of :example/:result elements." (length :eval (length '(a b c))) (length< - :eval (lenth< '(a b c) 1)) + :eval (length< '(a b c) 1)) (length> - :eval (lenth> '(a b c) 1)) + :eval (length> '(a b c) 1)) (length= - :eval (lenth> '(a b c) 3)) + :eval (length> '(a b c) 3)) (safe-length :eval (safe-length '(a b c)))) diff --git a/src/fns.c b/src/fns.c index 217e3b62cca..2de1d26dd31 100644 --- a/src/fns.c +++ b/src/fns.c @@ -202,7 +202,7 @@ counted. */) } DEFUN ("length=", Flength_equal, Slength_equal, 2, 2, 0, - doc: /* Return non-nil if SEQUENCE is equal to LENGTH. + doc: /* Return non-nil if SEQUENCE has length equal to LENGTH. See `length' for allowed values of SEQUENCE and how elements are counted. */) (Lisp_Object sequence, Lisp_Object length) -- cgit v1.2.1