refuse -o - for an executable or an object

Only the text outputs knew `-' as stdout; compiling handed it to cc as
a file name, and left a binary called `-' behind.
This commit is contained in:
2026-10-15 14:49:46 +03:00
parent 6e150aaaf1
commit 62b1ead3eb
2 changed files with 22 additions and 8 deletions

View File

@@ -59,8 +59,8 @@
(value #f)
(single-char #\m))
(output ,(fmt #f "Write output to file. Default file name is a.out." nl
(pad padding) "If -C or -m options are provided, defaults to stdout;" nl
(pad padding) "`-' is stdout too")
(pad padding) "With -C, -m or --public-interface, defaults to stdout," nl
(pad padding) "which `-' names too")
(required #f)
(value #t)
(single-char #\o))
@@ -145,6 +145,12 @@
(define (stdout-output? output)
(or (eq? output 'default) (equal? output "-")))
;;; Whether ARGS ask for text, which `-o -' can send to stdout. An
;;; executable or an object goes to cc's -o, where `-' is a file name
(define (text-output? args)
(any (lambda (option) (get-arg args option #f))
'(emit-c macro-expand public-interface)))
(define (write-to-file-or-stdout output what)
(if (stdout-output? output)
(what)
@@ -254,6 +260,8 @@ status, which is ours to pass on."
(when help
(print-help)
(return #f))
(when (and (equal? output "-") (not (text-output? args)))
(error "-o - is stdout, which takes only -C, -m or --public-interface"))
;; Read time comes before everything, so the features have to be
;; in place before the first form is read
(current-features