bug#78882: stty.c compilation error

Bruno Haible via GNU coreutils Bug Reports <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Organization GNU
Message-ID <64848289.rAQPL4r5uZ@nimes>
Hi,

The coreutils CI fails today on OpenBSD and Solaris. (The previous build,
a week ago, succeeded.)

Compilation error on OpenBSD:

cc  -I. -I.. -I./lib  -Ilib -I../lib -Isrc -I../src -I/usr/local/include -Wall  -Wno-format-extra-args -Wno-implicit-const-int-float-conversion -Wno-tautological-constant-out-of-range-compare -g -O2 -MT src/stty.o -MD -MP -MF $depbase.Tpo -c -o src/stty.o ../src/stty.c &&\
mv -f $depbase.Tpo $depbase.Po
In file included from ../src/stty.c:2177:
src/speedlist.h:156:4: error: unterminated conditional directive
#  ifdef B4000000n      case 4000000: return B4000000;n#  endif
   ^
src/speedlist.h:155:4: error: unterminated conditional directive
#  ifdef B3500000n      case 3500000: return B3500000;n#  endif
   ^
...

Compilation error on Solaris 11.4:

gcc -m64  -I. -I.. -I./lib  -Ilib -I../lib -Isrc -I../src  -Wall -D_REENTRANT  -g -O2 -MT src/stty.o -MD -MP -MF $depbase.Tpo -c -o src/stty.o ../src/stty.c &&\
mv -f $depbase.Tpo $depbase.Po
In file included from ../src/stty.c:2177:
src/speedlist.h: In function ‘baud_to_value’:
src/speedlist.h:60:19: warning: extra tokens at end of #ifdef directive
   60 | #  ifdef B0n      case B0: return 0;n#  endif
      |                   ^~~~
src/speedlist.h:156: error: unterminated #ifdef
  156 | #  ifdef B4000000n      case 4000000: return B4000000;n#  endif
src/speedlist.h:155: error: unterminated #ifdef
...


It looks like the 'speedgen' script, added in commit
357fda90d15fd3f7dba61e1ab322b183a48d0081, produces this invalid C code.

With GNU sed:

$ echo 100 | sed -e 's/^.*$/#  ifdef B&\n      case B&: return &;\n#  endif/'
#  ifdef B100
      case B100: return 100;
#  endif

With OpenBSD sed and Solaris sed:

$ echo 100 | sed -e 's/^.*$/#  ifdef B&\n      case B&: return &;\n#  endif/'
#  ifdef B100n      case B100: return 100;n#  endif

The attached patch fixes it.
0001-build-Fix-compilation-error-on-OpenBSD-and-Solaris.patch (text/x-patch, 1.1 KB)
From 4be6c54b010b05b143ffcfd2368b634f20be4dad Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Mon, 23 Jun 2025 22:59:47 +0200
Subject: [PATCH] build: Fix compilation error on OpenBSD and Solaris

* src/speedgen: Use 'printf', not 'sed', to emit code with newlines.
---
 src/speedgen | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/speedgen b/src/speedgen
index f1647d9f0..d14ed3f6b 100755
--- a/src/speedgen
+++ b/src/speedgen
@@ -49,8 +49,9 @@ baud_to_value (speed_t speed)
     {
 EOF
 
-sed -e 's/^.*$/#  ifdef B&\n      case B&: return &;\n#  endif/' \
-    < "$tmp" >> "$out"
+while read n; do
+  printf '#  ifdef B%s\n      case B%s: return %s;\n#  endif\n' "$n" "$n" "$n"
+done < "$tmp" >> "$out"
 
 cat >> "$out" <<'EOF'
       default: return -1;
@@ -72,8 +73,9 @@ value_to_baud (unsigned long int value)
     {
 EOF
 
-sed -e 's/^.*$/#  ifdef B&\n      case &: return B&;\n#  endif/' \
-    < "$tmp" >> "$out"
+while read n; do
+  printf '#  ifdef B%s\n      case %s: return B%s;\n#  endif\n' "$n" "$n" "$n"
+done < "$tmp" >> "$out"
 
 cat >> "$out" <<'EOF'
       default: return (speed_t) -1;
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.