From eea3ca3fd11daa5f2058a88d522e1aec922fd5be Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 27 Jul 2022 16:56:54 +0200 Subject: [PATCH] Sfio: fix non-multibyte build (re: 7c4418cc) The Sfio code uses its own _has_multibyte macro and that was not being disabled by AST_NOMULTIBYTE, so some of its multibyte code was still getting compiled in. This is easily fixed in sfhdr.h. But that exposed another issue: the Sfio stdio wrappers didn't know about the _has_multibyte macro. So this adds the necessary directives to keep their multibyte functions from compiling. --- src/lib/libast/sfio/sfhdr.h | 4 +++- src/lib/libast/stdio/fgetwc.c | 8 ++++++++ src/lib/libast/stdio/fgetws.c | 8 ++++++++ src/lib/libast/stdio/fputwc.c | 8 ++++++++ src/lib/libast/stdio/fputws.c | 8 ++++++++ src/lib/libast/stdio/fwide.c | 8 ++++++++ src/lib/libast/stdio/fwprintf.c | 10 +++++++++- src/lib/libast/stdio/fwscanf.c | 8 ++++++++ src/lib/libast/stdio/getwc.c | 10 +++++++++- src/lib/libast/stdio/getwchar.c | 10 +++++++++- src/lib/libast/stdio/putwc.c | 10 +++++++++- src/lib/libast/stdio/putwchar.c | 10 +++++++++- src/lib/libast/stdio/swprintf.c | 10 +++++++++- src/lib/libast/stdio/swscanf.c | 10 +++++++++- src/lib/libast/stdio/ungetwc.c | 8 ++++++++ src/lib/libast/stdio/vfwprintf.c | 8 ++++++++ src/lib/libast/stdio/vfwscanf.c | 8 ++++++++ src/lib/libast/stdio/vswprintf.c | 8 ++++++++ src/lib/libast/stdio/vswscanf.c | 8 ++++++++ src/lib/libast/stdio/vwprintf.c | 10 +++++++++- src/lib/libast/stdio/vwscanf.c | 10 +++++++++- src/lib/libast/stdio/wprintf.c | 10 +++++++++- src/lib/libast/stdio/wscanf.c | 10 +++++++++- 23 files changed, 190 insertions(+), 12 deletions(-) diff --git a/src/lib/libast/sfio/sfhdr.h b/src/lib/libast/sfio/sfhdr.h index c868b091e..aa313d56c 100644 --- a/src/lib/libast/sfio/sfhdr.h +++ b/src/lib/libast/sfio/sfhdr.h @@ -180,7 +180,9 @@ #include /* deal with multi-byte character and string conversions */ -#if _PACKAGE_ast +#if AST_NOMULTIBYTE +#undef _has_multibyte +#elif _PACKAGE_ast #include diff --git a/src/lib/libast/stdio/fgetwc.c b/src/lib/libast/stdio/fgetwc.c index 9efd49979..9d7cefb22 100644 --- a/src/lib/libast/stdio/fgetwc.c +++ b/src/lib/libast/stdio/fgetwc.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fgetwc) + +#else + wint_t fgetwc(Sfio_t* f) { @@ -31,3 +37,5 @@ fgetwc(Sfio_t* f) FWIDE(f, WEOF); return (sfread(f, &c, sizeof(c)) == sizeof(c)) ? c : WEOF; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fgetws.c b/src/lib/libast/stdio/fgetws.c index 16f4eb481..f437de1a5 100644 --- a/src/lib/libast/stdio/fgetws.c +++ b/src/lib/libast/stdio/fgetws.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fgetws) + +#else + wchar_t* fgetws(wchar_t* s, int n, Sfio_t* f) { @@ -48,3 +54,5 @@ getws(wchar_t* s) *p = 0; return s; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fputwc.c b/src/lib/libast/stdio/fputwc.c index 084374ec3..6a1165b5f 100644 --- a/src/lib/libast/stdio/fputwc.c +++ b/src/lib/libast/stdio/fputwc.c @@ -23,9 +23,17 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fputwc) + +#else + wint_t fputwc(wchar_t c, Sfio_t* f) { FWIDE(f, WEOF); return (sfwrite(f, &c, sizeof(c)) == sizeof(c)) ? c : WEOF; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fputws.c b/src/lib/libast/stdio/fputws.c index 9ac00b3ad..e2d35a8c6 100644 --- a/src/lib/libast/stdio/fputws.c +++ b/src/lib/libast/stdio/fputws.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fputws) + +#else + int fputws(const wchar_t* s, Sfio_t* f) { @@ -32,3 +38,5 @@ fputws(const wchar_t* s, Sfio_t* f) n = wcslen(s) * sizeof(wchar_t); return (sfwrite(f, s, n) == n) ? 0 : -1; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fwide.c b/src/lib/libast/stdio/fwide.c index 02d272809..90962d7cf 100644 --- a/src/lib/libast/stdio/fwide.c +++ b/src/lib/libast/stdio/fwide.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fwide) + +#else + int fwide(Sfio_t* f, int mode) { @@ -47,3 +53,5 @@ fwide(Sfio_t* f, int mode) } return 0; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fwprintf.c b/src/lib/libast/stdio/fwprintf.c index 631ac5fc3..abd3d3f42 100644 --- a/src/lib/libast/stdio/fwprintf.c +++ b/src/lib/libast/stdio/fwprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fwprintf) + +#else + int fwprintf(Sfio_t* f, const wchar_t* fmt, ...) { @@ -34,3 +40,5 @@ fwprintf(Sfio_t* f, const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/fwscanf.c b/src/lib/libast/stdio/fwscanf.c index 195b3e3df..43648acdb 100644 --- a/src/lib/libast/stdio/fwscanf.c +++ b/src/lib/libast/stdio/fwscanf.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(fwscanf) + +#else + int fwscanf(Sfio_t* f, const wchar_t* fmt, ...) { @@ -35,3 +41,5 @@ fwscanf(Sfio_t* f, const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/getwc.c b/src/lib/libast/stdio/getwc.c index 3e16b8af4..a9075e08b 100644 --- a/src/lib/libast/stdio/getwc.c +++ b/src/lib/libast/stdio/getwc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -24,8 +24,16 @@ #include "stdhdr.h" #include "ast_wchar.h" +#if !_has_multibyte + +NoN(getwc) + +#else + wint_t getwc(Sfio_t* f) { return fgetwc(f); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/getwchar.c b/src/lib/libast/stdio/getwchar.c index bba96f8e1..8d3b9c7eb 100644 --- a/src/lib/libast/stdio/getwchar.c +++ b/src/lib/libast/stdio/getwchar.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -24,8 +24,16 @@ #include "stdhdr.h" #include "ast_wchar.h" +#if !_has_multibyte + +NoN(getwchar) + +#else + wint_t getwchar(void) { return fgetwc(sfstdin); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/putwc.c b/src/lib/libast/stdio/putwc.c index 5bb8359ce..c2a3d115f 100644 --- a/src/lib/libast/stdio/putwc.c +++ b/src/lib/libast/stdio/putwc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -24,8 +24,16 @@ #include "stdhdr.h" #include "ast_wchar.h" +#if !_has_multibyte + +NoN(putwc) + +#else + wint_t putwc(wchar_t c, Sfio_t* f) { return fputwc(c, f); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/putwchar.c b/src/lib/libast/stdio/putwchar.c index e07457a22..2fffd8b36 100644 --- a/src/lib/libast/stdio/putwchar.c +++ b/src/lib/libast/stdio/putwchar.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -24,8 +24,16 @@ #include "stdhdr.h" #include "ast_wchar.h" +#if !_has_multibyte + +NoN(putwchar) + +#else + wint_t putwchar(wchar_t c) { return fputwc(c, sfstdout); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/swprintf.c b/src/lib/libast/stdio/swprintf.c index f9fe1e0ac..dc0559e1c 100644 --- a/src/lib/libast/stdio/swprintf.c +++ b/src/lib/libast/stdio/swprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(swprintf) + +#else + int swprintf(wchar_t* s, size_t size, const wchar_t* fmt, ...) { @@ -34,3 +40,5 @@ swprintf(wchar_t* s, size_t size, const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/swscanf.c b/src/lib/libast/stdio/swscanf.c index 78906b208..3529a81bd 100644 --- a/src/lib/libast/stdio/swscanf.c +++ b/src/lib/libast/stdio/swscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(swscanf) + +#else + int swscanf(const wchar_t* s, const wchar_t* fmt, ...) { @@ -34,3 +40,5 @@ swscanf(const wchar_t* s, const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/ungetwc.c b/src/lib/libast/stdio/ungetwc.c index 1cb945df0..bb3f308bd 100644 --- a/src/lib/libast/stdio/ungetwc.c +++ b/src/lib/libast/stdio/ungetwc.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(ungetwc) + +#else + wint_t ungetwc(wint_t c, Sfio_t* f) { @@ -35,3 +41,5 @@ ungetwc(wint_t c, Sfio_t* f) return WEOF; return c; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vfwprintf.c b/src/lib/libast/stdio/vfwprintf.c index c2da158c8..332b6f917 100644 --- a/src/lib/libast/stdio/vfwprintf.c +++ b/src/lib/libast/stdio/vfwprintf.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vfwprintf) + +#else + int vfwprintf(Sfio_t* f, const wchar_t* fmt, va_list args) { @@ -64,3 +70,5 @@ vfwprintf(Sfio_t* f, const wchar_t* fmt, va_list args) v = -1; return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vfwscanf.c b/src/lib/libast/stdio/vfwscanf.c index cfb0f39cd..c08352576 100644 --- a/src/lib/libast/stdio/vfwscanf.c +++ b/src/lib/libast/stdio/vfwscanf.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vfwscanf) + +#else + typedef struct { Sfdisc_t sfdisc; /* sfio discipline */ @@ -117,3 +123,5 @@ vfwscanf(Sfio_t* f, const wchar_t* fmt, va_list args) v = -1; return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vswprintf.c b/src/lib/libast/stdio/vswprintf.c index fdfbb111c..3350a371a 100644 --- a/src/lib/libast/stdio/vswprintf.c +++ b/src/lib/libast/stdio/vswprintf.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vswprintf) + +#else + int vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) { @@ -53,3 +59,5 @@ vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) _Sfi = f.next - f.data; return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vswscanf.c b/src/lib/libast/stdio/vswscanf.c index ea0fff70e..636ec5e66 100644 --- a/src/lib/libast/stdio/vswscanf.c +++ b/src/lib/libast/stdio/vswscanf.c @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vswscanf) + +#else + int vswscanf(const wchar_t* s, const wchar_t* fmt, va_list args) { @@ -49,3 +55,5 @@ vswscanf(const wchar_t* s, const wchar_t* fmt, va_list args) return vfwscanf(&f, fmt, args); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vwprintf.c b/src/lib/libast/stdio/vwprintf.c index af2676ae7..98065d7ba 100644 --- a/src/lib/libast/stdio/vwprintf.c +++ b/src/lib/libast/stdio/vwprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,8 +23,16 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vwprintf) + +#else + int vwprintf(const wchar_t* fmt, va_list args) { return vfwprintf(sfstdout, fmt, args); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/vwscanf.c b/src/lib/libast/stdio/vwscanf.c index d95426f72..454083c9f 100644 --- a/src/lib/libast/stdio/vwscanf.c +++ b/src/lib/libast/stdio/vwscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,8 +23,16 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(vwscanf) + +#else + int vwscanf(const wchar_t* fmt, va_list args) { return vfwscanf(sfstdin, fmt, args); } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/wprintf.c b/src/lib/libast/stdio/wprintf.c index e748a55a2..6e4b89b8e 100644 --- a/src/lib/libast/stdio/wprintf.c +++ b/src/lib/libast/stdio/wprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(wprintf) + +#else + int wprintf(const wchar_t* fmt, ...) { @@ -34,3 +40,5 @@ wprintf(const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */ diff --git a/src/lib/libast/stdio/wscanf.c b/src/lib/libast/stdio/wscanf.c index 5f856f9e1..04295bf32 100644 --- a/src/lib/libast/stdio/wscanf.c +++ b/src/lib/libast/stdio/wscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,6 +23,12 @@ #include "stdhdr.h" +#if !_has_multibyte + +NoN(wscanf) + +#else + int wscanf(const wchar_t* fmt, ...) { @@ -34,3 +40,5 @@ wscanf(const wchar_t* fmt, ...) va_end(args); return v; } + +#endif /* !_has_multibyte */