diff --git a/NEWS b/NEWS index 76a2966a48ec..d23c79a5fcb9 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library. - Fixed an issue, introduced on 2022-06-13, causing a subshell to fork unnecessarily if an EXIT pseudosignal trap is set within it. +- The ksh93 codebase now requires a C99 compiler to build. + 2026-03-16: - Fixed a bug in the join(1) built-in command (bound to /opt/ast/bin) that diff --git a/src/cmd/INIT/README-mamake.md b/src/cmd/INIT/README-mamake.md index 61256b672d1a..693173138837 100644 --- a/src/cmd/INIT/README-mamake.md +++ b/src/cmd/INIT/README-mamake.md @@ -4,7 +4,7 @@ MAM (Make Abstract Machine) is a simple rule-based make language that is implemented in just ten four-letter commands and four attributes, yet allows unlimited flexibility as it can execute arbitrary shell code. The program implementing MAM, `mamake`, -is a portable C90 program written in a single file, `mamake.c`. +is a portable C99 program written in a single file, `mamake.c`. This allows ksh 93u+m, or other programs using this build system, to be built using only a standard C compiler and utilities installation diff --git a/src/cmd/INIT/iffe.sh b/src/cmd/INIT/iffe.sh index 4e0e5a5aae69..beb210355d98 100644 --- a/src/cmd/INIT/iffe.sh +++ b/src/cmd/INIT/iffe.sh @@ -82,10 +82,10 @@ is_hdr() # [ - ] [ file.c ] hdr esac is hdr $1 case $1 in - sys/types.h | limits.h | stdio.h | unistd.h) - # These are often tested for repeatedly, especially sys/types.h. - # But POSIX has specified these since issue 1 (1988). It's 2023. - # Skip the compile to save time, but act like a positive test. + sys/types.h | limits.h | stddef.h | stdio.h | stdlib.h | unistd.h) + # These are often tested for repeatedly, but POSIX has specified + # these since issue 1 (1988). It's 2026. Skip the compile to save time, + # but act like a positive test. : 2>$tmp.e ;; *) compile $cc -c $_is_hdr_file <&$nullin >&$nullout 2>$tmp.e @@ -689,7 +689,7 @@ case $( (getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null ) in } [+?\abegin\a\b{\b ... \b}end\b delimit multiline code blocks that override or augment the default code provided by \biffe\b. User supplied code - blocks should be compatible with the C89/C90 C language + blocks should be compatible with the C99 C language standard for maximal portability. Test code may call the function \bNOTE("...")\b to emit short text in \b--verbose\b output; only one \bNOTE()\b should be called per test for readability. In addition to @@ -1162,7 +1162,6 @@ can= cansep= cctest= file= -hdrtest= ifelse=NONE ifstack= ini= @@ -2263,51 +2262,6 @@ int x; cc="$cc $mac" - # check for global default headers (some cc -E insist on compiling) - - case $hdrtest in - '') hdrtest=1 - allinc= - for x in types - do case $config in - 0) c=_sys_${x} - ;; - 1) case $shell in - ksh) typeset -u u=$x ;; - *) u=$(echo $x | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ) ;; - esac - c=HAVE_SYS_${u}_H - ;; - esac - x=sys/$x.h - echo "${allinc}#include <$x>" > $tmp.c - if is_hdr $x - then gothdr="$gothdr + $x" - case $explicit in - 0) can="$can$cansep#define $c 1 /* #include <$x> ok */" - nan="$nan$cansep$c=1" - cansep=$nl - ;; - esac - eval $c=1 - allinc="${allinc}#include <$x>$nl" - else gothdr="$gothdr - $x" - case $explicit$all$config$undef in - 0?1?|0??1) - can="$can$cansep#undef $c /* #include <$x> not ok */" - nan="$nan$cansep$c=" - cansep=$nl - ;; - 01??) can="$can$cansep#define $c 0 /* #include <$x> not ok */" - nan="$nan$cansep$c=0" - cansep=$nl - ;; - esac - fi - done - ;; - esac - # add implicit headers/libraries before the checks case $op in diff --git a/src/cmd/INIT/iffe.tst b/src/cmd/INIT/iffe.tst index d8ae7228caaf..4a2413bce31b 100644 --- a/src/cmd/INIT/iffe.tst +++ b/src/cmd/INIT/iffe.tst @@ -6,11 +6,9 @@ TEST 01 'command line basics' OUTPUT - $'/* : : generated by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes' + ERROR - $'iffe: test: is stdio.h a header ... yes' EXEC -r -v -s posix - hdr stdio @@ -18,12 +16,10 @@ iffe: test: is stdio.h a header ... yes' OUTPUT - $'/* : : generated by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #define _hdr_limits 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is limits.h a header ... yes' EXEC -r -v -s posix - hdr stdio,limits @@ -32,11 +28,9 @@ iffe: test: is limits.h a header ... yes' OUTPUT - $'/* : : generated by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is no_foo_bar.h a header ... no iffe: test: is no_bar_foo.h a header ... no iffe: test: is no_foo_bar a library function ... no @@ -55,11 +49,9 @@ TEST 02 'file input basics' OUTPUT - $'/* : : generated from t1.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes' + ERROR - $'iffe: test: is stdio.h a header ... yes' EXEC -r -v -s posix - t1.iffe @@ -68,12 +60,10 @@ iffe: test: is stdio.h a header ... yes' OUTPUT - $'/* : : generated from t2.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #define _hdr_limits 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is limits.h a header ... yes' EXEC -r -v -s posix - t2.iffe @@ -83,11 +73,9 @@ iffe: test: is limits.h a header ... yes' OUTPUT - $'/* : : generated from t3.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is no_foo_bar.h a header ... no iffe: test: is no_bar_foo.h a header ... no iffe: test: is no_foo_bar a library function ... no @@ -126,14 +114,12 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _ifelse_H #define _ifelse_H 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #define _lib_open 1 /* open() in default lib(s) */ HIT 1 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is open a library function ... yes' EXEC -r -v -s posix - t.iffe @@ -161,13 +147,11 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _ifelse_H #define _ifelse_H 1 -#define _sys_types 1 /* #include ok */ #define _hdr_limits 1 /* #include ok */ HIT 4 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is _XXX_stdio.h a header ... no + ERROR - $'iffe: test: is _XXX_stdio.h a header ... no iffe: test: is limits.h a header ... yes' EXEC -r -v -s posix - t.iffe @@ -195,12 +179,10 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _ifelse_H #define _ifelse_H 1 -#define _sys_types 1 /* #include ok */ HIT 5 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is _XXX_stdio.h a header ... no + ERROR - $'iffe: test: is _XXX_stdio.h a header ... no iffe: test: is _XXX_limits.h a header ... no' EXEC -r -v -s posix - t.iffe @@ -228,14 +210,12 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _ifelse_H #define _ifelse_H 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ #define _lib_close 1 /* close() in default lib(s) */ HIT 2 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is _XXX_open a library function ... no iffe: test: is close a library function ... yes' @@ -264,13 +244,11 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _ifelse_H #define _ifelse_H 1 -#define _sys_types 1 /* #include ok */ #define _hdr_stdio 1 /* #include ok */ HIT 3 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is _XXX_open a library function ... no iffe: test: is _XXX_close a library function ... no' @@ -450,8 +428,7 @@ endif' OK #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes' + ERROR - $'iffe: test: is stdio.h a header ... yes' EXEC -r -v -s posix - t.iffe @@ -463,11 +440,9 @@ HAVE_STDIO = hdr stdio' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define HAVE_STDIO 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes' + ERROR - $'iffe: test: is stdio.h a header ... yes' EXEC -r -v -s posix - t.iffe @@ -480,7 +455,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define HIT 1 #endif' @@ -527,15 +501,13 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define HAVE_STDIO 1 /* #include ok */ #define HIT 1 #define TOO ALSO #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is ( HAVE_STDIO ) true ... yes' EXEC -r -v -s posix - t.iffe @@ -550,14 +522,12 @@ exp ALSO HAVE_STDIO' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define HAVE_STDIO 1 /* #include ok */ #define HIT 1 #define ALSO 1 /* HAVE_STDIO is true */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is HAVE_STDIO true ... yes' EXEC -r -v -s posix - t.iffe @@ -572,14 +542,12 @@ ALSO = ( HAVE_STDIO )' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define HAVE_STDIO 1 /* #include ok */ #define HIT 1 #define ALSO 1 /* ( HAVE_STDIO ) is true */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is ( HAVE_STDIO ) true ... yes' EXEC -r -v -s posix - t.iffe @@ -599,11 +567,9 @@ tst seq - -DA=1 - -DB=1 note{ long int type }end compile{ OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #define _seq 1 /* long int type */ #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... yes' + ERROR - 'iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -630,8 +596,7 @@ tst seq - -DA=1 - -DB=1 note{ long int type }end compile{ #endif t n = 0; }end' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -662,10 +627,8 @@ tst seq - -DA=1 - -DB=1 note{ long int type }end compile{ OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... no' EXEC -r -v -s posix - t.iffe @@ -699,13 +662,11 @@ endif' OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ /* long int type */ #define seq 1 #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... yes' + ERROR - 'iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -738,8 +699,7 @@ if tst - -DA=1 - -DB=1 note{ long int type }end compile{ #define seq 1 } endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -776,10 +736,8 @@ endif' OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... no' EXEC -r -v -s posix - t.iffe @@ -816,13 +774,11 @@ endif' OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ /* long int type */ #define seq 1 #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... yes' + ERROR - 'iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -839,8 +795,7 @@ if tst - -DN=1 - -DN=2 - -DN=3 note{ long int type }end compile{ #define seq 1 } endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... yes' EXEC -r -v -s posix - t.iffe @@ -858,8 +813,7 @@ if tst - -DN=1 - -DN=2 - -DN=3 note{ long int type }end compile{ #define seq 1 } endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... iffe: test: long int type ... yes' @@ -881,10 +835,8 @@ endif' OUTPUT - '/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _macro_H #define _macro_H 1 -#define _sys_types 1 /* #include ok */ #endif' - ERROR - 'iffe: test: is sys/types.h a header ... yes -iffe: test: long int type ... + ERROR - 'iffe: test: long int type ... iffe: test: long int type ... iffe: test: long int type ... no' @@ -903,7 +855,6 @@ tst output{ } }end' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ -#define _sys_types 1 /* #include ok */ HIT' EXEC -r -s posix - t.iffe @@ -931,8 +882,7 @@ tst - output{ return 1; } }end' - OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ -#define _sys_types 1 /* #include ok */' + OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */' EXEC -r -s posix - t.iffe @@ -947,7 +897,6 @@ tst - nooutput{ } }end' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ -#define _sys_types 1 /* #include ok */ HIT' EXEC -r -s posix - t.iffe @@ -959,7 +908,6 @@ TEST 07 'diagnostics' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #endif' ERROR - $'iffe: t.iffe:1: tst: unknown feature test' EXIT 1 @@ -970,8 +918,7 @@ TEST 07 'diagnostics' INPUT t.iffe $'if (1)' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS -#define _REGRESS 1 -#define _sys_types 1 /* #include ok */' +#define _REGRESS 1' ERROR - $'iffe: t.iffe:1: missing endif' EXIT 1 @@ -981,8 +928,7 @@ TEST 07 'diagnostics' INPUT t.iffe $'if' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS -#define _REGRESS 1 -#define _sys_types 1 /* #include ok */' +#define _REGRESS 1' ERROR - $'iffe: t.iffe:1: missing endif' EXEC -r -s posix - t.iffe @@ -1113,7 +1059,6 @@ exp _tst_hit !_tst_hit&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_false is true */ /* !_tst_false */ @@ -1140,7 +1085,6 @@ exp _tst_hit !_tst_hit&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_hit&_tst_true is true */ TWO 0 1 @@ -1165,7 +1109,6 @@ exp _tst_hit !_tst_hit&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_hit&_tst_true is true */ /* !_tst_hit&_tst_true */ @@ -1192,7 +1135,6 @@ exp _tst_hit !_tst_hit&_tst_false { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #endif' @@ -1215,7 +1157,6 @@ exp _tst_hit !_tst_hit&&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_false is true */ /* !_tst_false */ @@ -1242,7 +1183,6 @@ exp _tst_hit !_tst_hit&&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_hit&&_tst_true is true */ TWO 0 1 @@ -1267,7 +1207,6 @@ exp _tst_hit !_tst_hit&&_tst_true { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #define _tst_hit 1 /* !_tst_hit&&_tst_true is true */ /* !_tst_hit&&_tst_true */ @@ -1294,7 +1233,6 @@ exp _tst_hit !_tst_hit&&_tst_false { OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #endif' @@ -1318,7 +1256,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ ONE @@ -1344,7 +1281,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ TWO #endif' @@ -1369,7 +1305,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ THREE @@ -1390,7 +1325,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ #endif' @@ -1412,7 +1346,6 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _tst_true 1 /* ( 1 ) is true */ OK @@ -1454,13 +1387,11 @@ _zzz = ( 1 ) OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _str "string" #define _hdr
#define _zzz 1 /* ( 1 ) is true */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is ( 0 ) true ... no + ERROR - $'iffe: test: is ( 0 ) true ... no iffe: test: is ( 1 ) true ... yes iffe: test: is ( _str ) true ... yes iffe: test: is ( ! _str ) true ... no @@ -1514,11 +1445,9 @@ TEST 12 'non-opaque mem' OUTPUT - $'/* : : generated by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_t 1 /* #include ok */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is t.h a header ... yes + ERROR - $'iffe: test: is t.h a header ... yes iffe: test: is OPAQUE a type or typedef ... no iffe: test: is struct OPAQUE a non-opaque struct ... no' @@ -1528,12 +1457,10 @@ typedef struct nonopaque NONOPAQUE;' OUTPUT - $'/* : : generated by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _hdr_t 1 /* #include ok */ #define _mem_NONOPAQUE 1 /* NONOPAQUE is a non-opaque struct */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is t.h a header ... yes + ERROR - $'iffe: test: is t.h a header ... yes iffe: test: is NONOPAQUE a type or typedef ... yes iffe: test: is NONOPAQUE a non-opaque struct ... yes' @@ -1549,7 +1476,6 @@ key chr = char = int' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _key_int 1 /* int is a reserved keyword */ #define _key_const 1 /* const is a reserved keyword */ #define bar /* default for reserved keyword bar */ @@ -1557,8 +1483,7 @@ key chr = char = int' #define _key_char 1 /* char is a reserved keyword */ #define chr char /* alternate for reserved keyword chr */ #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is int a reserved keyword ... yes + ERROR - $'iffe: test: is int a reserved keyword ... yes iffe: test: is const a reserved keyword ... yes iffe: test: is foo a reserved keyword ... no iffe: test: is bar a reserved keyword ... no @@ -1573,7 +1498,6 @@ iffe: test: is char a reserved keyword ... yes' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _key_int 1 /* int is a reserved keyword */ #define _key_const 1 /* const is a reserved keyword */ #undef _key_foo /* foo is not a reserved keyword */ @@ -1591,7 +1515,6 @@ iffe: test: is char a reserved keyword ... yes' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define _key_int 1 /* int is a reserved keyword */ #define _key_const 1 /* const is a reserved keyword */ #define _key_foo 0 /* foo is not a reserved keyword */ @@ -1609,7 +1532,6 @@ iffe: test: is char a reserved keyword ... yes' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define HAVE_SYS_TYPES_H 1 /* #include ok */ #define HAVE_INT_RESERVED 1 /* int is a reserved keyword */ #define HAVE_CONST_RESERVED 1 /* const is a reserved keyword */ #undef HAVE_FOO_RESERVED /* foo is not a reserved keyword */ @@ -1639,12 +1561,10 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define some 1 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is ( bar_foo ) true ... no + ERROR - $'iffe: test: is ( bar_foo ) true ... no iffe: test: is ( _foo_bar ) true ... yes' EXEC -r -v - t.iffe @@ -1659,12 +1579,10 @@ endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define all 1 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is ( bar_foo ) true ... yes' + ERROR - $'iffe: test: is ( bar_foo ) true ... yes' EXEC -r -v - t.iffe INPUT t.iffe $'inc t_lib.h . ? @@ -1675,24 +1593,20 @@ elif ( _foo_bar ) { #define ok 1 } endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: t.iffe:1: warning: ?: operands ignored + ERROR - $'iffe: t.iffe:1: warning: ?: operands ignored iffe: test: is ( bar_foo ) true ... yes' EXEC -r -v - t.iffe INPUT t.iffe $'inc foo_lib.h' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS -#define _REGRESS 1 -#define _sys_types 1 /* #include ok */' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: t.iffe:1: foo_lib.h: file not found' +#define _REGRESS 1' + ERROR - $'iffe: t.iffe:1: foo_lib.h: file not found' EXIT 1 EXEC -r -v - t.iffe INPUT t.iffe $'inc' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: t.iffe:1: path expected' + ERROR - $'iffe: t.iffe:1: path expected' TEST 15 'KnR compatibility' @@ -1716,14 +1630,12 @@ cat{ OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define some 1 #endif' OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #define all 1 #define some 1 @@ -1734,8 +1646,7 @@ cat{ #define d 4 #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is ( 1 ) true ... yes + ERROR - $'iffe: test: is ( 1 ) true ... yes iffe: test: is ( 2 ) true ... yes iffe: test: cat{ ... }end ... yes' @@ -1757,15 +1668,13 @@ extern Tab_lE struct barfoo* [10]' /* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #include #define FoobaR(a,b) ((a)+(b)) #define FoomaC -1 extern struct barfoo* BarfoO(int); extern struct barfoo* Tab_lE[10]; #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes + ERROR - $'iffe: test: is stdio.h a header ... yes iffe: test: is EOF a macro ... yes iffe: test: is FoobaR a macro ... no iffe: test: is FoomaC a macro ... no @@ -1780,11 +1689,9 @@ TEST 17 'features/* => FEATURE/*' OUTPUT FEATURE/stdio $'/* : : generated from features/stdio by iffe version 1995-03-19 : : */ #ifndef _REGRESS #define _REGRESS 1 -#define _sys_types 1 /* #include ok */ #include #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes -iffe: test: is stdio.h a header ... yes' + ERROR - $'iffe: test: is stdio.h a header ... yes' TEST 18 'api + ver' EXEC -r -v - t.iffe @@ -1804,7 +1711,6 @@ api bar 20050505 joe_d OUTPUT - $'/* : : generated from t.iffe by iffe version 1995-03-19 : : */ #ifndef _api_H #define _api_H 1 -#define _sys_types 1 /* #include ok */ #define FOO_VERSION 20100606 #define BAR_VERSION 19840919 @@ -1878,4 +1784,3 @@ api bar 20050505 joe_d #define _API_bar_MAP "curly_20020202 joe_b_20040404 joe_d_20050505 larry_19991231 moe_19991231 shemp_20030303 shemp_19991231" #endif' - ERROR - $'iffe: test: is sys/types.h a header ... yes' diff --git a/src/cmd/INIT/make.probe b/src/cmd/INIT/make.probe index 535b661a18db..727a77b24bb5 100644 --- a/src/cmd/INIT/make.probe +++ b/src/cmd/INIT/make.probe @@ -43,6 +43,7 @@ probe_shared_name="-Wl,-soname= -h" probe_shared_registry='"-update_registry $probe_shared_registry_file"' probe_shared_registry_file='registry.ld' probe_shared_registry_path="\$(LIBDIR)/$probe_shared_registry_file" +probe_stdc="-std=gnu23 -std=c23 -std=gnu11 -std=c11 -std=gnu99 -std=c99" probe_strict="'-ansi -pedantic' '-ansi -strict' -strict -ansi" probe_stripflags="'-f -s' -f -s" probe_unresolved="'-expect_unresolved \"*\"'" @@ -1476,6 +1477,22 @@ then e=`wc -c < e` ;; esac + # use the newest C standard available + eval set x $probe_stdc + while : + do shift + case $# in + 0) break ;; + esac + rm -f warn.$obj + $cc $1 -c warn.$src 2>e && test -f warn.$obj || continue + n=`wc -c < e` + if test $n -ge $e + then stdc=$1 + break + fi + done + eval set x $probe_strict while : do shift @@ -2006,6 +2023,7 @@ CC_SIZE=$size CC_STATIC=$static CC_STDINCLUDE=$stdinclude CC_STDLIB=$stdlib +CC_STDC=$stdc CC_STRICT=$strict CC_STRIP=$strip CC_STRIP_FLAGS=$stripflags @@ -2114,6 +2132,7 @@ echo CC.SIZE = $CC_SIZE echo CC.STATIC = $CC_STATIC echo CC.STDINCLUDE = $CC_STDINCLUDE echo CC.STDLIB = $CC_STDLIB +echo CC.STDC = $CC_STDC echo CC.STRICT = $CC_STRICT echo CC.STRIP = $CC_STRIP echo CC.STRIP.FLAGS = $CC_STRIP_FLAGS diff --git a/src/cmd/INIT/mamake.c b/src/cmd/INIT/mamake.c index 59629bf7ac6d..f011995fcc32 100644 --- a/src/cmd/INIT/mamake.c +++ b/src/cmd/INIT/mamake.c @@ -200,11 +200,7 @@ typedef struct Dict_item_s /* dictionary item */ struct Dict_item_s *left; /* left child */ struct Dict_item_s *right; /* right child */ void *value; /* user defined value */ -#if __STDC_VERSION__ >= 199901L char name[]; /* 0 terminated name */ -#else - char name[1];/* 0 terminated name */ -#endif } Dict_item_t; typedef struct Dict_s /* dictionary handle */ @@ -247,11 +243,7 @@ typedef struct View_s /* viewpath level */ { struct View_s *next; /* next level in viewpath */ size_t node; /* viewpath node path length */ -#if __STDC_VERSION__ >= 199901L char dir[]; /* viewpath level dir prefix */ -#else - char dir[1]; /* viewpath level dir prefix */ -#endif } View_t; typedef struct Makestate_s /* make() shareable state */ @@ -400,11 +392,7 @@ static void report(int level, char *text, char *item, Rule_t *r) fprintf(stderr, "%s: ", item); fprintf(stderr, "%s", text); if (r && r->time && state.debug <= -2) -#if __STDC_VERSION__ >= 199901L fprintf(stderr, " %llu", (unsigned long long)r->time); -#else - fprintf(stderr, " %lu", (unsigned long)r->time); -#endif fprintf(stderr, "\n"); if (level > 2) exit_wait(level - 2); diff --git a/src/cmd/builtin/Mamfile b/src/cmd/builtin/Mamfile index b1293274f98c..79db8ec2034a 100644 --- a/src/cmd/builtin/Mamfile +++ b/src/cmd/builtin/Mamfile @@ -7,7 +7,7 @@ setv MAMAKE_STRICT 5 setv INSTALLROOT ../../.. setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} setv CCFLAGS setv CCLDFLAGS %{-strip-symbols?1?%{mam_cc_LD_STRIP}??} setv IFFEFLAGS diff --git a/src/cmd/builtin/pty.c b/src/cmd/builtin/pty.c index a417b49f2aa5..20e196418743 100644 --- a/src/cmd/builtin/pty.c +++ b/src/cmd/builtin/pty.c @@ -135,7 +135,7 @@ static noreturn void outofmemory(size_t size) { static char sname[MAXNAME]; char *last; - strncpy(sname,name,sizeof(sname)); + strlcpy(sname,name,sizeof(sname)); last = strrchr(sname,'/'); last[1] = 't'; return sname; diff --git a/src/cmd/ksh93/Mamfile b/src/cmd/ksh93/Mamfile index 68e9176ce7e1..f5c749bfdd3b 100644 --- a/src/cmd/ksh93/Mamfile +++ b/src/cmd/ksh93/Mamfile @@ -6,7 +6,7 @@ note * setv MAMAKE_STRICT 5 setv INSTALLROOT ../../.. setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} -D_BLD_ksh %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} -D_BLD_ksh %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} setv CCFLAGS setv CCLDFLAGS %{-strip-symbols?1?%{mam_cc_LD_STRIP}??} setv IFFEFLAGS @@ -352,6 +352,7 @@ make install virtual prev include/shlex.h prev include/fcin.h prev include/builtins.h + prev %{INCLUDE_AST}/tv.h prev %{INCLUDE_AST}/tmx.h prev %{INCLUDE_AST}/error.h prev include/defs.h @@ -700,6 +701,7 @@ make install virtual prev include/variables.h prev %{INCLUDE_AST}/ast_random.h prev %{INCLUDE_AST}/regex.h + prev %{INCLUDE_AST}/tv.h prev %{INCLUDE_AST}/tmx.h prev include/defs.h prev shopt.h @@ -847,6 +849,7 @@ make install virtual prev %{INCLUDE_AST}/error.h prev %{INCLUDE_AST}/sig.h prev %{INCLUDE_AST}/ast.h + prev %{INCLUDE_AST}/tv.h prev shopt.h done @@ -878,6 +881,7 @@ make install virtual prev include/variables.h prev include/fcin.h prev include/defs.h + prev %{INCLUDE_AST}/tv.h prev shopt.h done diff --git a/src/cmd/ksh93/bltins/alarm.c b/src/cmd/ksh93/bltins/alarm.c index 399b3c24dfe3..02b895cd4218 100644 --- a/src/cmd/ksh93/bltins/alarm.c +++ b/src/cmd/ksh93/bltins/alarm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -27,6 +27,7 @@ #include "defs.h" #include #include +#include #include "builtins.h" #include "fcin.h" #include "shlex.h" @@ -96,9 +97,9 @@ static void *time_delete(struct tevent *item, void *list) static Time_t getnow(void) { - struct timeval tmp; - timeofday(&tmp); - return tmp.tv_sec + 1.e-6 * tmp.tv_usec; + Tv_t tmp; + tvgettime(&tmp); + return tmp.tv_sec + 1.e-9 * tmp.tv_nsec; } static void print_alarms(void *list) diff --git a/src/cmd/ksh93/bltins/getopts.c b/src/cmd/ksh93/bltins/getopts.c index 2c356dda7bdf..9163ea63a995 100644 --- a/src/cmd/ksh93/bltins/getopts.c +++ b/src/cmd/ksh93/bltins/getopts.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -62,12 +62,12 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context) int jmpval; volatile int extended, r= -1; struct checkpt buff, *pp; - Optdisc_t disc; + Optdisc_t disc = { + .version = OPT_VERSION, + .infof = infof + }; NOT_USED(context); - memset(&disc, 0, sizeof(disc)); - disc.version = OPT_VERSION; - disc.infof = infof; value[1] = 0; key[1] = 0; while((flag = optget(argv,sh_optgetopts))) switch(flag) diff --git a/src/cmd/ksh93/bltins/print.c b/src/cmd/ksh93/bltins/print.c index 6cbcc3c07ef7..20648364a631 100644 --- a/src/cmd/ksh93/bltins/print.c +++ b/src/cmd/ksh93/bltins/print.c @@ -101,9 +101,7 @@ static int exitval; int B_echo(int argc, char *argv[],Shbltin_t *context) { static char bsd_univ; - struct print prdata; - prdata.options = sh_optecho+5; - prdata.raw = prdata.echon = 0; + struct print prdata = { .options = sh_optecho+5 }; NOT_USED(argc); NOT_USED(context); /* This mess is because /bin/echo on BSD is different */ @@ -141,11 +139,9 @@ static int exitval; int b_printf(int argc, char *argv[],Shbltin_t *context) { - struct print prdata; + struct print prdata = { .options = sh_optprintf }; NOT_USED(argc); NOT_USED(context); - memset(&prdata,0,sizeof(prdata)); - prdata.options = sh_optprintf; return b_print(-1,argv,(Shbltin_t*)&prdata); } @@ -176,11 +172,11 @@ int b_print(int argc, char *argv[], Shbltin_t *context) #endif /* !SHOPT_SCRIPTONLY */ int nflag=0, rflag=0, vflag=0; Namval_t *vname=0; - Optdisc_t disc; + Optdisc_t disc = { + .version = OPT_VERSION, + .infof = infof + }; exitval = 0; - memset(&disc, 0, sizeof(disc)); - disc.version = OPT_VERSION; - disc.infof = infof; if(argc>0) { options = sh_optprint; @@ -371,12 +367,14 @@ int b_print(int argc, char *argv[], Shbltin_t *context) { /* printf style print */ Sfio_t *pool; - struct printf pdata; - memset(&pdata, 0, sizeof(pdata)); - pdata.hdr.version = SFIO_VERSION; - pdata.hdr.extf = extend; - pdata.hdr.reloadf = reload; - pdata.nextarg = argv; + struct printf pdata = { + .hdr = { + .version = SFIO_VERSION, + .extf = extend, + .reloadf = reload + }, + .nextarg = argv + }; sh_offstate(SH_STOPOK); pool=sfpool(sfstderr,NULL,SFIO_WRITE); do @@ -445,9 +443,7 @@ static int echolist(Sfio_t *outfile, int raw, char *argv[]) { char *cp; ptrdiff_t n; - struct printf pdata; - pdata.cescape = 0; - pdata.err = 0; + struct printf pdata = {0}; while(!pdata.cescape && (cp= *argv++)) { if(!raw && (n=fmtvecho(cp,&pdata))>=0) diff --git a/src/cmd/ksh93/bltins/test.c b/src/cmd/ksh93/bltins/test.c index eae6d6659aa6..0f65f93f8f38 100644 --- a/src/cmd/ksh93/bltins/test.c +++ b/src/cmd/ksh93/bltins/test.c @@ -113,13 +113,14 @@ static int test_strmatch(const char *str, const char *pat) int b_test(int argc, char *argv[],Shbltin_t *context) { - struct test tdata; char *cp = argv[0]; int not; + struct test tdata = { + .av = argv, + .ap = 1 + }; NOT_USED(context); - tdata.av = argv; - tdata.ap = 1; if(c_eq(cp,'[')) { cp = argv[--argc]; diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 3e5d3c07e0c7..21ecf6fbe587 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -94,11 +94,9 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context) { int flag; char *command = argv[0]; - struct tdata tdata; + struct tdata tdata = { .aflag = '-' }; NOT_USED(argc); NOT_USED(context); - memset(&tdata,0,sizeof(tdata)); - tdata.aflag = '-'; while((flag = optget(argv,*command=='e'?sh_optexport:sh_optreadonly))) switch(flag) { case 'p': @@ -139,10 +137,9 @@ int b_alias(int argc,char *argv[],Shbltin_t *context) unsigned flag = NV_NOARRAY|NV_NOSCOPE|NV_ASSIGN; Dt_t *troot; int rflag=0, xflag=0, n; - struct tdata tdata; + struct tdata tdata = {0}; NOT_USED(argc); NOT_USED(context); - memset(&tdata,0,sizeof(tdata)); troot = sh.alias_tree; if(*argv[0]=='h') flag |= NV_TAGGED; @@ -151,7 +148,6 @@ int b_alias(int argc,char *argv[],Shbltin_t *context) opt_info.offset = 0; opt_info.index = 1; *opt_info.option = 0; - tdata.argnum = 0; tdata.aflag = *argv[1]; while((n = optget(argv, *argv[0]=='h' ? sh_opthash : sh_optalias))) switch(n) { @@ -222,13 +218,12 @@ int b_alias(int argc,char *argv[],Shbltin_t *context) int b_typeset(int argc,char *argv[],Shbltin_t *context) { int n, flag = NV_VARNAME|NV_ASSIGN; - struct tdata tdata; + struct tdata tdata = {0}; const char *optstring = sh_opttypeset; Namdecl_t *ntp = (Namdecl_t*)context->ptr; Dt_t *troot; int isfloat=0, isadjust=0, shortint=0, sflag=0; - memset(&tdata,0,sizeof(tdata)); troot = sh.var_tree; if(ntp) /* type declaration command added using 'typeset -T' or 'enum' */ { @@ -1131,7 +1126,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) int n, r=0, flag=0; Namval_t *np; long dlete=0; - struct tdata tdata; + struct tdata tdata={0}; Shbltin_f addr; Stk_t *stkp; char *errmsg; @@ -1140,7 +1135,6 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) #endif NOT_USED(argc); NOT_USED(context); - memset(&tdata,0,sizeof(tdata)); stkp = sh.stk; if(!sh.pathlist) path_absolute(argv[0],NULL,0); @@ -1287,10 +1281,8 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) int b_set(int argc,char *argv[],Shbltin_t *context) { - struct tdata tdata; + struct tdata tdata={0}; NOT_USED(context); - memset(&tdata,0,sizeof(tdata)); - tdata.prefix=0; if(argv[1]) { if(sh_argopts(argc,argv) < 0) diff --git a/src/cmd/ksh93/bltins/ulimit.c b/src/cmd/ksh93/bltins/ulimit.c index 930b32a686a4..f25f12913291 100644 --- a/src/cmd/ksh93/bltins/ulimit.c +++ b/src/cmd/ksh93/bltins/ulimit.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -79,11 +79,11 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) int label, unit, nosupport, ret=0; rlim_t i=0; char tmp[41]; - Optdisc_t disc; + Optdisc_t disc = { + .version = OPT_VERSION, + .infof = infof + }; NOT_USED(context); - memset(&disc, 0, sizeof(disc)); - disc.version = OPT_VERSION; - disc.infof = infof; opt_info.disc = &disc; while((n = optget(argv,sh_optulimit))) switch(n) { diff --git a/src/cmd/ksh93/data/limits.c b/src/cmd/ksh93/data/limits.c index 6478d697bf13..6c8435bb07b1 100644 --- a/src/cmd/ksh93/data/limits.c +++ b/src/cmd/ksh93/data/limits.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * diff --git a/src/cmd/ksh93/data/math.tab b/src/cmd/ksh93/data/math.tab index 7a2427967b61..c6076dda532b 100644 --- a/src/cmd/ksh93/data/math.tab +++ b/src/cmd/ksh93/data/math.tab @@ -2,7 +2,7 @@ # # # This software is part of the ast package # # Copyright (c) 1982-2013 AT&T Intellectual Property # -# Copyright (c) 2020-2025 Contributors to ksh 93u+m # +# Copyright (c) 2020-2026 Contributors to ksh 93u+m # # and is licensed under the # # Eclipse Public License, Version 2.0 # # # @@ -13,6 +13,7 @@ # David Korn # # Martijn Dekker # # hyenias <58673227+hyenias@users.noreply.github.com> # +# Johnothan King # # # ######################################################################## diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index 431de29845d4..6b22a46b5896 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -79,14 +79,12 @@ static int charcmp(int a, int b, int nocase) { if(nocase) { -#if _lib_towlower if(mbwide()) { a = (int)towlower((wint_t)a); b = (int)towlower((wint_t)b); } else -#endif { a = tolower(a); b = tolower(b); @@ -649,8 +647,8 @@ int ed_fulledit(Edit_t *ep) sh_onstate(SH_HISTORY); hist_flush(sh.hist_ptr); } - cp = strcopy((char*)ep->e_inbuf,e_runvi); - cp = strcopy(cp, fmtint(ep->e_hline,1)); + cp = stpcpy((char*)ep->e_inbuf,e_runvi); + cp = stpcpy(cp, fmtint(ep->e_hline,1)); #if SHOPT_VSH ep->e_eol = ((unsigned char*)cp - (unsigned char*)ep->e_inbuf)-(sh_isoption(SH_VI)!=0); #else diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index 40250573460c..fb2fe90407b1 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -1209,12 +1209,7 @@ int ed_external(const genchar *src, char *dest) int c; char buffer[MAXLINE*sizeof(genchar)] = ""; c = ed_external(src,buffer); - -#if _lib_wcscpy - wcscpy((wchar_t *)dest,(const wchar_t *)buffer); -#else - strcopy(dest,buffer); -#endif + wcscpy((wchar_t*)dest,(const wchar_t*)buffer); return c; } while((wc = *src++) && dp0) { - strncopy(inbuff,cp,bufsize); - inbuff[bufsize-1]='\0'; + strlcpy(inbuff,cp,bufsize); insize = strlen(inbuff); } else diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index 3c72f18593e8..4b55f5437fdc 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -79,7 +79,7 @@ One line screen editor for any program static int print(int); static int _isword(int); # define isword(c) _isword(out[c]) -# define digit(c) ((c&~STRIP)==0 && isdigit(c)) +# define digit(c) iswdigit((wint_t)(c)) #else # define gencpy(a,b) strcopy((char*)(a),(char*)(b)) @@ -1588,7 +1588,7 @@ static int print(int c) static int _isword(int c) { - return (c&~STRIP) || isalnum(c) || c=='_'; + return iswalnum((wint_t)c) || c=='_'; } #endif /* SHOPT_MULTIBYTE */ diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index dad780995b46..e8fb6272bf44 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -56,11 +56,8 @@ # define gencpy(a,b) ed_gencpy(a,b) # define genncpy(a,b,n) ed_genncpy(a,b,n) # define genlen(str) ed_genlen(str) -# define digit(c) ((c&~STRIP)==0 && isdigit(c)) +# define digit(c) iswdigit((wint_t)(c)) # define is_print(c) ((c&~STRIP) || isprint(c)) -# if !_lib_iswprint && !defined(iswprint) -# define iswprint(c) ((c&~0177) || isprint(c)) -# endif static int _isalph(int); static int _isblank(int); # undef isblank @@ -2584,11 +2581,7 @@ static int textmod(Vi_t *vp,int c, int mode) #if SHOPT_MULTIBYTE static int _isalph(int v) { -#if _lib_iswalnum return iswalnum(v) || v=='_'; -#else - return (v&~STRIP) || isalnum(v) || v=='_'; -#endif } diff --git a/src/cmd/ksh93/features/locale b/src/cmd/ksh93/features/locale index 631b087a7d19..c9bdc7c8fc26 100644 --- a/src/cmd/ksh93/features/locale +++ b/src/cmd/ksh93/features/locale @@ -1,5 +1,5 @@ -hdr locale,wchar,wctype -lib locale,localeconv,wctype,iswctype,iswblank +lib iswblank +hdr wchar,wctype tst note{ do wctrans/towctrans work }end output{ /* diff --git a/src/cmd/ksh93/features/time b/src/cmd/ksh93/features/time index 73576ea2ebf3..047cee4cb84c 100644 --- a/src/cmd/ksh93/features/time +++ b/src/cmd/ksh93/features/time @@ -1,38 +1,10 @@ hdr utime,sys/resource -lib getrusage,gettimeofday,setitimer -mem timeval.tv_usec sys/time.h -tst lib_2_timeofday note{ 2 arg gettimeofday() }end link{ - #include - #include - int main(void) - { - struct timeval tv; - struct timezone tz; - return gettimeofday(&tv, &tz); - } -}end -tst lib_1_timeofday note{ 1 arg gettimeofday() }end link{ - #include - #include - int main(void) - { - struct timeval tv; - return gettimeofday(&tv); - } -}end +lib getrusage,setitimer cat{ #undef _def_time #include #include #define _def_time 1 - #undef timeofday - #if _lib_2_timeofday - #define timeofday(p) gettimeofday(p,NULL) - #else - #if _lib_1_timeofday - #define timeofday(p) gettimeofday(p) - #endif - #endif /* BSD timeradd and timersub macros */ #if !defined(timeradd) #define timeradd(tvp, uvp, vvp) \ diff --git a/src/cmd/ksh93/include/lexstates.h b/src/cmd/ksh93/include/lexstates.h index 33eadbb55378..d3573e5d92da 100644 --- a/src/cmd/ksh93/include/lexstates.h +++ b/src/cmd/ksh93/include/lexstates.h @@ -84,18 +84,9 @@ # if _hdr_wctype # include # undef isalpha -# define isalpha(x) iswalpha(x) -# if defined(iswblank) || _lib_iswblank -# undef isblank -# define isblank(x) iswblank(x) -# else -# if _lib_wctype && _lib_iswctype -# define _lib_iswblank -1 -# undef isblank -# define isblank(x) local_iswblank(x) - extern int local_iswblank(wchar_t); -# endif -# endif +# define isalpha(x) iswalpha((wint_t)(x)) +# undef isblank +# define isblank(x) iswblank((wint_t)(x)) # endif #endif #ifndef isblank diff --git a/src/cmd/ksh93/include/path.h b/src/cmd/ksh93/include/path.h index 8c4882a75393..f7650d35832a 100644 --- a/src/cmd/ksh93/include/path.h +++ b/src/cmd/ksh93/include/path.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -85,7 +85,7 @@ extern char *path_pwd(void); extern Pathcomp_t *path_nextcomp(Pathcomp_t*,const char*,Pathcomp_t*); extern int path_search(const char*,Pathcomp_t**,int); extern char *path_relative(const char*); -extern int path_complete(const char*, const char*,struct argnod**); +extern int path_complete(const char *restrict, const char *restrict,struct argnod**); #if SHOPT_BRACEPAT extern int path_generate(struct argnod*,struct argnod**, int); #endif /* SHOPT_BRACEPAT */ diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index 017a4df87d7d..510f54b0d6b6 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -126,11 +126,11 @@ int sh_argopts(int argc,char *argv[]) Namval_t *np = NULL; const char *cp; int verbose, f; - Optdisc_t disc; + Optdisc_t disc = { + .version = OPT_VERSION, + .infof = infof + }; newflags=sh.options; - memset(&disc, 0, sizeof(disc)); - disc.version = OPT_VERSION; - disc.infof = infof; opt_info.disc = &disc; if(argc>0) diff --git a/src/cmd/ksh93/sh/defs.c b/src/cmd/ksh93/sh/defs.c index a1fe33f179f0..038eee1d76c9 100644 --- a/src/cmd/ksh93/sh/defs.c +++ b/src/cmd/ksh93/sh/defs.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,11 +26,21 @@ #include "jobs.h" #include "shlex.h" -Shell_t sh = {0}; +Shell_t sh = { + .cpipe[0] = -1, + .coutpipe = -1, +#if _lib_openat + .pwdfd = -1, +#endif + .radixpoint = '.', /* pre-locale init */ + .stk = stkstd +}; Dtdisc_t _Nvdisc = { - offsetof(Namval_t,nvname), -1 , 0, 0, 0, nv_compare + .key = offsetof(Namval_t,nvname), + .size = -1, + .comparf = nv_compare }; struct jobs job = {0}; diff --git a/src/cmd/ksh93/sh/expand.c b/src/cmd/ksh93/sh/expand.c index 1a909528c25a..462fb2df2ea6 100644 --- a/src/cmd/ksh93/sh/expand.c +++ b/src/cmd/ksh93/sh/expand.c @@ -64,12 +64,11 @@ static char *nextdir(glob_t *gp, char *dir) int path_expand(const char *pattern, struct argnod **arghead, int musttrim) { - glob_t gdata; + glob_t gdata = {0}; struct argnod *ap; glob_t *gp= &gdata; int flags,extra=0; sh_stats(STAT_GLOBS); - memset(gp,0,sizeof(gdata)); flags = GLOB_GROUP|GLOB_AUGMENTED|GLOB_NOCHECK|GLOB_NOSORT|GLOB_STACK|GLOB_LIST|GLOB_DISC; if(sh_isoption(SH_MARKDIRS)) flags |= GLOB_MARK; @@ -167,7 +166,7 @@ static int scantree(Dt_t *tree, const char *pattern, struct argnod **arghead) * Generate the list of files found by adding a suffix to end of name * The number of matches is returned */ -int path_complete(const char *name,const char *suffix, struct argnod **arghead) +int path_complete(const char *restrict name, const char *restrict suffix, struct argnod **arghead) { sufstr = suffix; suflen = strlen(suffix); @@ -291,11 +290,11 @@ int path_generate(struct argnod *todo, struct argnod **arghead, int musttrim) { if(*endc=='%') { - Sffmt_t fmt; - memset(&fmt, 0, sizeof(fmt)); - fmt.version = SFIO_VERSION; - fmt.form = endc; - fmt.extf = checkfmt; + Sffmt_t fmt = { + .version = SFIO_VERSION, + .form = endc, + .extf = checkfmt + }; sfprintf(sfstdout, "%!", &fmt); if(!(fmt.flags&(SFFMT_LLONG|SFFMT_LDOUBLE))) switch (fmt.fmt) diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 0ed96276d22b..8f5f4ba44c78 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -32,6 +32,7 @@ #include "defs.h" #include #include +#include #include #include #include @@ -96,7 +97,6 @@ static wctrans_t wctrans(const char *name) #define towctrans sh_towctrans static int towctrans(int c, wctrans_t t) { -#if _lib_towupper && _lib_towlower if(mbwide()) { if(t==1 && iswupper((wint_t)c)) @@ -105,7 +105,6 @@ static int towctrans(int c, wctrans_t t) c = (int)towupper((wint_t)c); } else -#endif if(t==1 && isupper(c)) c = tolower(c); else if(t==2 && islower(c)) @@ -470,7 +469,6 @@ static void put_lang(Namval_t *np,const char *val,int flags,Namfun_t *fp) } } nv_putv(np, val, flags, fp); -#if _lib_localeconv if(type==LC_ALL || type==LC_NUMERIC || type==LC_LANG) { struct lconv *lp = localeconv(); @@ -478,7 +476,6 @@ static void put_lang(Namval_t *np,const char *val,int flags,Namfun_t *fp) /* Multibyte radix points are not (yet?) supported */ sh.radixpoint = strlen(cp)==1 ? *cp : '.'; } -#endif } /* Trap for IFS assignment and invalidates state table */ @@ -553,14 +550,13 @@ static char* get_ifs(Namval_t *np, Namfun_t *fp) /* * these functions are used to get and set the SECONDS variable */ -#define dtime(tp) ((double)((tp)->tv_sec)+1e-6*((double)((tp)->tv_usec))) -#define tms timeval +#define dtime(tp) ((double)((tp)->tv_sec)+1e-9*((double)((tp)->tv_nsec))) static void put_seconds(Namval_t *np,const char *val,int flags,Namfun_t *fp) { double d; double *dp = np->nvalue; - struct tms tp; + Tv_t tp; if(!val) { nv_putv(np, val, flags, fp); @@ -577,19 +573,19 @@ static void put_seconds(Namval_t *np,const char *val,int flags,Namfun_t *fp) } nv_putv(np, val, flags, fp); d = *dp; - timeofday(&tp); + tvgettime(&tp); *dp = dtime(&tp)-d; } static char* get_seconds(Namval_t *np, Namfun_t *fp) { size_t places = nv_size(np); - struct tms tp; + Tv_t tp; double d; double *dp = np->nvalue; double offset = dp ? *dp : 0; NOT_USED(fp); - timeofday(&tp); + tvgettime(&tp); d = dtime(&tp)- offset; sfprintf(sh.strbuf,"%.*f",places,d); return sfstruse(sh.strbuf); @@ -597,11 +593,11 @@ static char* get_seconds(Namval_t *np, Namfun_t *fp) static Sfdouble_t nget_seconds(Namval_t *np, Namfun_t *fp) { - struct tms tp; + Tv_t tp; double *dp = np->nvalue; double offset = dp ? *dp : 0; NOT_USED(fp); - timeofday(&tp); + tvgettime(&tp); return dtime(&tp) - offset; } @@ -1240,13 +1236,10 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sh.mac_context = sh_macopen(); sh.arg_context = sh_argopen(); sh.lex_context = sh_lexopen(0,1); - sh.radixpoint = '.'; /* pre-locale init */ sh.strbuf = sfstropen(); - stkoverflow(sh.stk = stkstd, nomemory); + stkoverflow(sh.stk, nomemory); sfsetbuf(sh.strbuf,NULL,64); error_info.catalog = e_dict; - sh.cpipe[0] = -1; - sh.coutpipe = -1; sh_ioinit(); /* initialize signal handling */ sh_siginit(); @@ -1402,13 +1395,12 @@ static void freeup_tree(Dt_t *tree) */ void sh_reinit(void) { - Shopt_t opt; + Shopt_t opt = {0}; Namval_t *np,*npnext; Dt_t *dp; sh_onstate(SH_INIT); sh_offstate(SH_FORKED); /* Reset shell options; inherit some */ - memset(&opt,0,sizeof(opt)); if(sh_isoption(SH_POSIX)) on_option(&opt,SH_POSIX); #if SHOPT_ESH diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index f300366613dd..32e5ac2dc519 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -128,7 +128,7 @@ struct addrinfo }; static int -getaddrinfo(const char* node, const char* service, const struct addrinfo* hint, struct addrinfo **addr) +getaddrinfo(const char *restrict node, const char *restrict service, const struct addrinfo *restrict hint, struct addrinfo **restrict addr) { unsigned long ip_addr = 0; unsigned short ip_port = 0; @@ -216,17 +216,14 @@ static int onintr(struct addrinfo*); static int inetopen(const char* path, int flags) { - char* s; - char* t; + char *s, *t, *tofree; int fd; int oerrno; - struct addrinfo hint; + struct addrinfo hint = { .ai_family = PF_UNSPEC }; struct addrinfo* addr; struct addrinfo* p; int server = !!(flags&O_SERVICE); - memset(&hint, 0, sizeof(hint)); - hint.ai_family = PF_UNSPEC; switch (path[0]) { #ifdef IPPROTO_SCTP @@ -265,17 +262,19 @@ inetopen(const char* path, int flags) } if(flags==O_NONBLOCK) return 1; - s = sh_strdup(path); + tofree = s = sh_strdup(path); if (t = strchr(s, '/')) { *t++ = 0; if (streq(s, "local")) - s = sh_strdup("localhost"); + s = "localhost"; + else + t = strchr(path,'/')+1; /* POSIX requires getaddrinfo()'s arguments not overlap */ fd = getaddrinfo(s, t, &hint, &addr); } else fd = -1; - free(s); + free(tofree); if (fd) { if (fd != EAI_SYSTEM) @@ -1033,13 +1032,15 @@ static Sfoff_t file_offset(int fn, char *fname) Sfio_t *sp = sh.sftable[fn]; char *cp; Sfoff_t off; - struct Eof endf; Namval_t *mp = nv_open("EOF",sh.var_tree,0); Namval_t *pp = nv_open("CUR",sh.var_tree,0); - memset(&endf,0,sizeof(struct Eof)); - endf.fd = fn; - endf.hdr.disc = &EOF_disc; - endf.hdr.nofree = 1; + struct Eof endf = { + .fd = fn, + .hdr = { + .disc = &EOF_disc, + .nofree = 1 + } + }; if(mp) nv_stack(mp, &endf.hdr); if(pp) @@ -1398,11 +1399,7 @@ int sh_redirect(struct ionod *iop, int flag) UNREACHABLE(); } if(perm>0) -#if _lib_fchmod fchmod(fd,perm); -#else - chmod(tname,perm); -#endif } } traceit: diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 1160c57f3bf2..af1ef8989efd 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -41,24 +41,6 @@ #define SYNBAD 3 /* exit value for syntax errors */ #define STACK_ARRAY 3 /* size of depth match stack growth */ -#if _lib_iswblank < 0 /* set in lexstates.h to enable this code */ - -int -local_iswblank(wchar_t wc) -{ - static int initialized; - static wctype_t wt; - - if (!initialized) - { - initialized = 1; - wt = wctype("blank"); - } - return iswctype(wc, wt); -} - -#endif - #define pushlevel(lp,c,s) ((lp->lexd.level>=lex_max?stack_grow():1) &&\ ((lex_match[lp->lexd.level++]=lp->lexd.lastc),\ lp->lexd.lastc=(((s)<nodes,0); nq->nvname = cp; nv_onattr(nq,NV_MINIMAL); - cp = strcopy(cp,NV_DATA); + cp = stpcpy(cp,NV_DATA); *cp++ = 0; for(name=0, offset=0, k=i=1; i < numnodes; i++) { diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index bec870a402f2..fa6e20c1ca4d 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -298,7 +298,12 @@ static char *dotpaths_lib(Pathcomp_t *pp, char *path) *last = 0; else path = (char*)e_dot; - r = stat(path,&statb); +#if _lib_openat + if(path==e_dot && sh.pwdfd>-1) + r = fstat(sh.pwdfd,&statb); + else +#endif + r = stat(path,&statb); if(last) *last = '/'; if(r>=0) @@ -1396,7 +1401,7 @@ static noreturn void exscript(char *path,char *argv[]) before = times(&buffer); sabuf.ac_uid = sh.userid; sabuf.ac_gid = sh.groupid; - strncpy(sabuf.ac_comm, (char*)path_basename(cmdname), + strlcpy(sabuf.ac_comm, (char*)path_basename(cmdname), sizeof(sabuf.ac_comm)); shaccton = 1; } diff --git a/src/cmd/ksh93/sh/pmain.c b/src/cmd/ksh93/sh/pmain.c index 17b1fd91e234..12f887b13f45 100644 --- a/src/cmd/ksh93/sh/pmain.c +++ b/src/cmd/ksh93/sh/pmain.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,10 +32,10 @@ int main(int argc, char *argv[]) { #if _lib_memcntl /* advise larger stack size */ - struct memcntl_mha mha; - mha.mha_cmd = MHA_MAPSIZE_STACK; - mha.mha_flags = 0; - mha.mha_pagesize = 64 * 1024; + struct memcntl_mha mha = { + .mha_cmd = MHA_MAPSIZE_STACK, + .mha_pagesize = 64 * 1024 + }; (void)memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mha, 0, 0); #endif sh_main(argc, argv, NULL); diff --git a/src/cmd/ksh93/sh/shcomp.c b/src/cmd/ksh93/sh/shcomp.c index 6016d46d400c..013a9f9721dd 100644 --- a/src/cmd/ksh93/sh/shcomp.c +++ b/src/cmd/ksh93/sh/shcomp.c @@ -134,13 +134,15 @@ int main(int argc, char *argv[]) if(cp= *argv) { struct stat statb; + int fd; if(!(out = sfopen(NULL,cp,"w"))) { errormsg(SH_DICT,ERROR_system(1),"%s: cannot create",cp); UNREACHABLE(); } - if(fstat(sffileno(out),&statb) >=0) - chmod(cp,(statb.st_mode&~S_IFMT)|S_IXUSR|S_IXGRP|S_IXOTH); + fd = sffileno(out); + if(fstat(fd,&statb)>=0) + fchmod(fd,(statb.st_mode&~S_IFMT)|S_IXUSR|S_IXGRP|S_IXOTH); } else out = sfstdout; diff --git a/src/cmd/ksh93/sh/streval.c b/src/cmd/ksh93/sh/streval.c index 1e77d44f850f..88577a751d48 100644 --- a/src/cmd/ksh93/sh/streval.c +++ b/src/cmd/ksh93/sh/streval.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -146,15 +146,11 @@ Sfdouble_t arith_exec(Arith_t *ep) char *lastval=0; int lastsub=0; Math_f fun; - struct lval node; - node.emode = ep->emode; - node.expr = ep->expr; - node.elen = ep->elen; - node.value = 0; - node.nosub = 0; - node.sub = 0; - node.enum_p = 0; - node.isenum = 0; + struct lval node = { + .emode = ep->emode, + .expr = ep->expr, + .elen = ep->elen + }; if(sh.arithrecursion++ >= MAXLEVEL) { arith_error(e_recursive,ep->expr,ep->emode); @@ -884,15 +880,15 @@ static int expr(struct vars *vp,int precedence) Arith_t *arith_compile(const char *string,char **last,Sfdouble_t(*fun)(const char**,struct lval*,int,Sfdouble_t),int emode) { - struct vars cur; Arith_t *ep; int offset; - memset(&cur,0,sizeof(cur)); - cur.expr = cur.nextchr = string; - cur.convert = fun; - cur.emode = emode; - cur.errmsg.value = 0; - cur.errmsg.emode = emode; + struct vars cur = { + .expr = string, + .nextchr = string, + .convert = fun, + .emode = emode, + .errmsg = { .emode = emode } + }; stkseek(sh.stk,sizeof(Arith_t)); if(!expr(&cur,0) && cur.errmsg.value) { diff --git a/src/cmd/ksh93/sh/string.c b/src/cmd/ksh93/sh/string.c index fa6028779343..c713682d56fd 100644 --- a/src/cmd/ksh93/sh/string.c +++ b/src/cmd/ksh93/sh/string.c @@ -32,10 +32,6 @@ # include #endif -#if !_lib_iswprint && !defined(iswprint) -# define iswprint(c) (((c)&~0377) || isprint(c)) -#endif - /* * Table lookup routine * is searched for string and corresponding value is returned @@ -488,7 +484,7 @@ char *sh_fmtqf(const char *string, int single, int fold) #if SHOPT_MULTIBYTE if (c >= 0x200) continue; - if (c == '\'' || !iswprint(c)) + if (c == '\'' || !iswprint((wint_t)c)) #else if (c == '\'' || !isprint(c)) #endif /* SHOPT_MULTIBYTE */ @@ -553,7 +549,7 @@ char *sh_fmtqf(const char *string, int single, int fold) break; default: #if SHOPT_MULTIBYTE - if(!iswprint(c)) + if(!iswprint((wint_t)c)) #else if(!isprint(c)) #endif diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index dff9ee374711..a34f22f7f1dc 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -523,7 +523,12 @@ void sh_clear_subshell_pwdfd(void) */ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) { - struct subshell sub_data; + struct subshell sub_data = { + .options = sh.options, + .subshare = sh.subshare, + .comsub = sh.comsub, + .pwdfd = -1 /* pwdfd should not be initialized to stdin */ + }; struct subshell *sp = &sub_data; int n, jmpval, fatalerror = 0, saveerrno = 0; unsigned int savecurenv = sh.curenv; @@ -536,11 +541,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) struct sh_scoped savst; struct dolnod *argsav=0; int argcnt; - memset((char*)sp, 0, sizeof(*sp)); - sp->options = sh.options; - sp->subshare = sh.subshare; - sp->comsub = sh.comsub; - sp->pwdfd = -1; /* pwdfd should not be initialized to stdin */ sfsync(sh.outpool); sh_sigcheck(); sh.savesig = -1; diff --git a/src/cmd/ksh93/sh/timers.c b/src/cmd/ksh93/sh/timers.c index 26e96d8549ad..49e15a7ed7c8 100644 --- a/src/cmd/ksh93/sh/timers.c +++ b/src/cmd/ksh93/sh/timers.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -20,6 +20,7 @@ #include #include #include +#include #include "fault.h" #include "defs.h" #include "FEATURE/time" @@ -44,9 +45,9 @@ static char time_state; static Sfdouble_t getnow(void) { Sfdouble_t now; - struct timeval tp; - timeofday(&tp); - now = tp.tv_sec + 1.e-6*tp.tv_usec; + Tv_t tp; + tvgettime(&tp); + now = tp.tv_sec + 1.e-6*(tp.tv_nsec/1000); return now+.001; } diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index cae9e4d5251e..f7d51f690213 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -35,6 +35,7 @@ #include "jobs.h" #include "test.h" #include "builtins.h" +#include #include "FEATURE/time" #include "FEATURE/externs" #include "FEATURE/locale" @@ -2229,7 +2230,7 @@ int sh_exec(const Shnode_t *t, int flags) case TTIME: { const char *format = e_timeformat; - struct timeval ta, tb; + Tv_t tva, tvb; struct timeval before_usr, before_sys, after_usr, after_sys, tm[3]; if(type!=TTIME) { @@ -2241,7 +2242,7 @@ int sh_exec(const Shnode_t *t, int flags) { int timer_on = sh_isstate(SH_TIMING); /* must be run after forking a subshell */ - timeofday(&tb); + tvgettime(&tvb); get_cpu_times(&before_usr, &before_sys); sh_onstate(SH_TIMING); sh_exec(t->par.partre,sh_isstate(SH_ERREXIT)|(flags & ARG_OPTIMIZE)); @@ -2254,7 +2255,9 @@ int sh_exec(const Shnode_t *t, int flags) before_sys.tv_sec = before_sys.tv_usec = 0; } get_cpu_times(&after_usr, &after_sys); - timeofday(&ta); + tvgettime(&tva); + struct timeval ta = { .tv_sec = tva.tv_sec, .tv_usec = (suseconds_t)(tva.tv_nsec / 1000) }; + struct timeval tb = { .tv_sec = tvb.tv_sec, .tv_usec = (suseconds_t)(tvb.tv_nsec / 1000) }; timersub(&ta, &tb, &tm[TM_REAL_IDX]); /* calculate elapsed real-time */ timersub(&after_usr, &before_usr, &tm[TM_USR_IDX]); timersub(&after_sys, &before_sys, &tm[TM_SYS_IDX]); @@ -2424,7 +2427,9 @@ int sh_exec(const Shnode_t *t, int flags) struct Ufunction *rp = np->nvalue; static Dtdisc_t _Rpdisc = { - offsetof(struct Ufunction,fname), -1, sizeof(struct Ufunction) + .key = offsetof(struct Ufunction,fname), + .size = -1, + .link = sizeof(struct Ufunction) }; struct functnod *fp; struct comnod *ac = t->funct.functargs; diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 130494463b05..8b8b3587b8e1 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -8,7 +8,7 @@ setv INSTALLROOT ../../.. setv PACKAGEROOT ../../../../.. setv INCLUDE_AST %{INSTALLROOT}/include/ast setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} -D_BLD_ast %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} -D_BLD_ast %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} setv CCFLAGS setv CCLDFLAGS %{-strip-symbols?1?%{mam_cc_LD_STRIP}??} setv IFFEFLAGS @@ -953,6 +953,14 @@ make install virtual exec - compile %{<} done + make stpcpy.o + make string/stpcpy.c + prev ast_map.h + prev include/ast.h + done + exec - compile %{<} + done + make strlook.o make string/strlook.c prev include/ast.h @@ -2582,14 +2590,6 @@ make install virtual exec - compile %{<} -Idisc -Iport -Isfio done - make wc.o - make comp/wc.c - prev std/wchar.h - prev include/ast.h - done - exec - compile %{<} - done - make utf32toutf8.o make string/utf32toutf8.c prev include/ast.h @@ -2658,15 +2658,6 @@ make install virtual exec - compile %{<} done - make strptime.o - make comp/strptime.c - prev ast_map.h - prev tmx.h - prev include/ast.h - done - exec - compile %{<} - done - make tempnam.o make comp/tempnam.c prev std/stdio.h @@ -2676,26 +2667,6 @@ make install virtual exec - compile %{<} done - make wordexp.o - make comp/wordexp.c - prev include/stk.h - make comp/wordexp.h - prev ast_common.h - done - prev include/ast.h - done - exec - compile %{<} - done - - make mktime.o - make comp/mktime.c - prev ast_map.h - prev include/tm.h - prev include/ast.h - done - exec - compile %{<} - done - make regalloc.o make regex/regalloc.c make regex/reglib.h @@ -3699,7 +3670,7 @@ make install virtual done done note * ...comp(atibility) - loop HDR ftw re_comp wordexp fnmatch + loop HDR ftw re_comp fnmatch make %{INCLUDE_AST}/%{HDR}.h prev comp/%{HDR}.h exec - cp -f %{<} %{@} diff --git a/src/lib/libast/cdt/dtopen.c b/src/lib/libast/cdt/dtopen.c index a6d4c79b8653..62c6c9a5e670 100644 --- a/src/lib/libast/cdt/dtopen.c +++ b/src/lib/libast/cdt/dtopen.c @@ -35,7 +35,7 @@ static int _dttype2005(Dt_t* dt, int type) Dt_t* _dtopen(Dtdisc_t* disc, Dtmethod_t* meth, unsigned long version) { Dtdata_t *data; - Dt_t *dt, pdt; + Dt_t *dt; int ev; unsigned int type; @@ -45,10 +45,10 @@ Dt_t* _dtopen(Dtdisc_t* disc, Dtmethod_t* meth, unsigned long version) dt = NULL; data = NULL; type = meth->type; - - memset(&pdt, 0, sizeof(Dt_t)); - pdt.searchf = meth->searchf; - pdt.meth = meth; + Dt_t pdt = { + .searchf = meth->searchf, + .meth = meth + }; dtdisc(&pdt,disc,0); /* note that this sets pdt.memoryf */ if(disc->eventf) diff --git a/src/lib/libast/comp/assert.c b/src/lib/libast/comp/assert.c index d5e924998ab7..c70b7069a8ac 100644 --- a/src/lib/libast/comp/assert.c +++ b/src/lib/libast/comp/assert.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This file is part of the ksh 93u+m package * -* Copyright (c) 2024 Contributors to ksh 93u+m * +* Copyright (c) 2024-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -10,19 +10,15 @@ * (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * * * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ #include -void noreturn _ast_assertfail(const char *a, const char *fun, const char *file, int line) +noreturn void _ast_assertfail(const char *restrict a, const char *restrict fun, const char *restrict file, int line) { -#if _has___func__ || _has___FUNCTION__ sfprintf(sfstderr,"\n*** assertion %s failed in %s(), %s:%d\n", a, fun, file, line); -#else - NOT_USED(fun); - sfprintf(sfstderr,"\n*** assertion %s failed in %s:%d\n", a, file, line); -#endif sfsync(NULL); abort(); } diff --git a/src/lib/libast/comp/iconv.c b/src/lib/libast/comp/iconv.c index c68eef8eb4ec..3a1f3238482c 100644 --- a/src/lib/libast/comp/iconv.c +++ b/src/lib/libast/comp/iconv.c @@ -847,7 +847,7 @@ error(DEBUG_TRACE, "AHA#%d _ast_iconv_open f=%s:%s:%d t=%s:%s:%d\n", __LINE__, f if (!(cc = newof(0, Conv_t, 1, strlen(to) + strlen(fr) + 2))) return (iconv_t)(-1); cc->to.name = (char*)(cc + 1); - cc->from.name = strcopy(cc->to.name, to) + 1; + cc->from.name = stpcpy(cc->to.name, to) + 1; strcpy(cc->from.name, fr); cc->cvt = (iconv_t)(-1); diff --git a/src/lib/libast/comp/localeconv.c b/src/lib/libast/comp/localeconv.c index bdeac46563cd..940baf87d5af 100644 --- a/src/lib/libast/comp/localeconv.c +++ b/src/lib/libast/comp/localeconv.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -25,49 +26,48 @@ #undef localeconv -static struct lconv debug_lconv, default_lconv; +static struct lconv debug_lconv = { + .decimal_point = ",", + .thousands_sep = ".", + .grouping = "", + .int_curr_symbol = "", + .currency_symbol = "", + .mon_decimal_point = "", + .mon_thousands_sep = "", + .mon_grouping = "", + .positive_sign = "", + .negative_sign = "", + .int_frac_digits = CHAR_MAX, + .frac_digits = CHAR_MAX, + .p_cs_precedes = CHAR_MAX, + .p_sep_by_space = CHAR_MAX, + .n_cs_precedes = CHAR_MAX, + .n_sep_by_space = CHAR_MAX, + .p_sign_posn = CHAR_MAX, + .n_sign_posn = CHAR_MAX +}; -/* - * POSIX does not specify the order in which struct lconv members are declared, - * so they must be initialized by name. But C89 does not support initializing - * struct members by name, so we have to do it using an initializer function. - */ -static void init_lconv_structs(void) -{ - debug_lconv.decimal_point = ","; - default_lconv.decimal_point = debug_lconv.thousands_sep = "."; - default_lconv.thousands_sep = - debug_lconv.grouping = default_lconv.grouping = - debug_lconv.int_curr_symbol = default_lconv.int_curr_symbol = - debug_lconv.currency_symbol = default_lconv.currency_symbol = - debug_lconv.mon_decimal_point = default_lconv.mon_decimal_point = - debug_lconv.mon_thousands_sep = default_lconv.mon_thousands_sep = - debug_lconv.mon_grouping = default_lconv.mon_grouping = - debug_lconv.positive_sign = default_lconv.positive_sign = - debug_lconv.negative_sign = default_lconv.negative_sign = - ""; - debug_lconv.int_frac_digits = default_lconv.int_frac_digits = - debug_lconv.frac_digits = default_lconv.frac_digits = - debug_lconv.p_cs_precedes = default_lconv.p_cs_precedes = - debug_lconv.p_sep_by_space = default_lconv.p_sep_by_space = - debug_lconv.n_cs_precedes = default_lconv.n_cs_precedes = - debug_lconv.n_sep_by_space = default_lconv.n_sep_by_space = - debug_lconv.p_sign_posn = default_lconv.p_sign_posn = - debug_lconv.n_sign_posn = default_lconv.n_sign_posn = - CHAR_MAX; -} - -#if !_lib_localeconv - -struct lconv* -localeconv(void) -{ - if(!default_lconv.decimal_point) - init_lconv_structs(); - return &default_lconv; -} +static struct lconv default_lconv = { + .decimal_point = ".", + .thousands_sep = ".", + .grouping = "", + .int_curr_symbol = "", + .currency_symbol = "", + .mon_decimal_point = "", + .mon_thousands_sep = "", + .mon_grouping = "", + .positive_sign = "", + .negative_sign = "", + .int_frac_digits = CHAR_MAX, + .frac_digits = CHAR_MAX, + .p_cs_precedes = CHAR_MAX, + .p_sep_by_space = CHAR_MAX, + .n_cs_precedes = CHAR_MAX, + .n_sep_by_space = CHAR_MAX, + .p_sign_posn = CHAR_MAX, + .n_sign_posn = CHAR_MAX +}; -#endif /* * localeconv() intercept @@ -76,8 +76,6 @@ localeconv(void) struct lconv* _ast_localeconv(void) { - if(!default_lconv.decimal_point) - init_lconv_structs(); if ((locales[AST_LC_MONETARY]->flags | locales[AST_LC_NUMERIC]->flags) & LC_debug) return &debug_lconv; if ((locales[AST_LC_NUMERIC]->flags & (LC_default|LC_local)) == LC_local) diff --git a/src/lib/libast/comp/mktime.c b/src/lib/libast/comp/mktime.c deleted file mode 100644 index 19a6a7f98c63..000000000000 --- a/src/lib/libast/comp/mktime.c +++ /dev/null @@ -1,69 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * mktime implementation - */ - -#define mktime ______mktime - -#include -#include - -#undef mktime - -#undef _def_map_ast -#include - -#undef _lib_mktime /* we can pass X/Open */ - -#if _lib_mktime - -NoN(mktime) - -#else - -extern time_t -mktime(struct tm* ts) -{ - time_t t; - Tm_t tm; - - tm.tm_sec = ts->tm_sec; - tm.tm_min = ts->tm_min; - tm.tm_hour = ts->tm_hour; - tm.tm_mday = ts->tm_mday; - tm.tm_mon = ts->tm_mon; - tm.tm_year = ts->tm_year; - tm.tm_wday = ts->tm_wday; - tm.tm_yday = ts->tm_yday; - tm.tm_isdst = ts->tm_isdst; - t = tmtime(&tm, TM_LOCALZONE); - ts->tm_sec = tm.tm_sec; - ts->tm_min = tm.tm_min; - ts->tm_hour = tm.tm_hour; - ts->tm_mday = tm.tm_mday; - ts->tm_mon = tm.tm_mon; - ts->tm_year = tm.tm_year; - ts->tm_wday = tm.tm_wday; - ts->tm_yday = tm.tm_yday; - ts->tm_isdst = tm.tm_isdst; - return t; -} - -#endif diff --git a/src/lib/libast/comp/omitted.c b/src/lib/libast/comp/omitted.c index 15ac109abe47..d58b20d3691b 100644 --- a/src/lib/libast/comp/omitted.c +++ b/src/lib/libast/comp/omitted.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1995-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -1072,16 +1072,6 @@ utime(const char* path, const struct utimbuf* ut) * own BSD-like macros */ -#if !_lib_bzero && !defined(bzero) - -void -bzero(void* b, size_t n) -{ - memset(b, 0, n); -} - -#endif - #if !_lib_getpagesize || defined(getpagesize) #ifndef OMITTED diff --git a/src/lib/libast/comp/open.c b/src/lib/libast/comp/open.c index 10c6e3e69fbc..b478e6bc54b9 100644 --- a/src/lib/libast/comp/open.c +++ b/src/lib/libast/comp/open.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -76,11 +77,7 @@ _ast_open(const char* path, int op, ...) close(fd); return -1; } -#if _lib_fchmod if (mode && fchmod(fd, mode)) -#else - if (mode && chmod(path, mode)) -#endif errno = save_errno; } if ((op & O_ACCMODE) == O_RDWR) diff --git a/src/lib/libast/comp/setlocale.c b/src/lib/libast/comp/setlocale.c index c7f3033f0cea..68de7bdcb360 100644 --- a/src/lib/libast/comp/setlocale.c +++ b/src/lib/libast/comp/setlocale.c @@ -36,21 +36,12 @@ #include #include -#if ( _lib_wcwidth || _lib_wctomb ) && _hdr_wctype +#if _hdr_wctype #include #endif -#if _lib_wcwidth #undef wcwidth -#else -#define wcwidth 0 -#endif - -#if _lib_wctomb #undef wctomb -#else -#define wctomb 0 -#endif #ifdef mblen #undef mblen @@ -84,14 +75,14 @@ header(void) * LC_COLLATE and LC_CTYPE native support */ -#if !_lib_mbtowc || MB_LEN_MAX <= 1 +#if MB_LEN_MAX <= 1 #define mblen 0 #define mbtowc 0 #endif #if _macos_strxfrm_bug static size_t -_ast_strxfrm_workaround(char *s1, const char *s2, size_t n) +_ast_strxfrm_workaround(char *restrict s1, const char *restrict s2, size_t n) { size_t r; int save = errno; @@ -190,7 +181,7 @@ static unsigned char debug_order[] = }; static int -debug_mbtowc(wchar_t* p, const char* s, size_t n) +debug_mbtowc(wchar_t *restrict p, const char *restrict s, size_t n) { const char* q; const char* r; @@ -462,14 +453,14 @@ set_collate(Lc_category_t* cp) * workaround the interesting SJIS that translates unshifted 7 bit ASCII! */ -#if _hdr_wchar && _typ_mbstate_t && _lib_mbrtowc && !AST_NOMULTIBYTE +#if _hdr_wchar && !AST_NOMULTIBYTE #define sjis_workaround 1 static mbstate_t sjis_state_zero; static mbstate_t sjis_state; static int -sjis_mbtowc(wchar_t* p, const char* s, size_t n) +sjis_mbtowc(wchar_t *restrict p, const char *restrict s, size_t n) { if (n && p && s && (*s == '\\' || *s == '~') && !memcmp(&sjis_state, &sjis_state_zero, sizeof(mbstate_t))) { @@ -523,7 +514,7 @@ static const unsigned char utf8tab[256] = }; static int -utf8_mbtowc(wchar_t* wp, const char* str, size_t n) +utf8_mbtowc(wchar_t *restrict wp, const char *restrict str, size_t n) { unsigned char* sp = (unsigned char*)str; size_t m; @@ -2142,7 +2133,7 @@ utf8_alpha(wchar_t c) #endif /* !AST_NOMULTIBYTE */ -#if !_hdr_wchar || !_lib_wctype || !_lib_iswctype +#if !_hdr_wchar #undef iswalpha #define iswalpha default_iswalpha static int @@ -2358,28 +2349,6 @@ setopt(void* a, const void* p, int n, const char* v) return 0; } -#if !_lib_setlocale - -#define setlocale(c,l) default_setlocale(c,l) - -static char* -default_setlocale(int category, const char* locale) -{ - Lc_t* lc; - - if (locale) - { - if (!(lc = lcmake(locale)) || !(lc->flags & LC_default)) - return NULL; - locales[0]->flags &= ~lc->flags; - locales[1]->flags &= ~lc->flags; - return lc->name; - } - return (locales[1]->flags & (1<name : locales[0]->name; -} - -#endif - /* * set a single AST_LC_* locale category * the caller must validate category diff --git a/src/lib/libast/comp/spawnveg.c b/src/lib/libast/comp/spawnveg.c index 9848661c448b..da1e4a873b3f 100644 --- a/src/lib/libast/comp/spawnveg.c +++ b/src/lib/libast/comp/spawnveg.c @@ -150,19 +150,19 @@ spawnveg_fast(const char* path, char* const argv[], char* const envv[], pid_t pg { pid_t pid; char stack[STACK_SIZE]; - struct cargs args; #if defined(__MACHINE_STACK_GROWS_UP) || defined(__hppa__) || defined(__metag__) void *stack_top = stack; #else void *stack_top = stack+STACK_SIZE; #endif + struct cargs args = { + .path = path, + .argv = (char**)argv, + .envv = (char**)(envv ? envv : environ), + .pgid = pgid, + .tcfd = tcfd + }; - args.path = path; - args.argv = (char**)argv; - args.envv = (char**)(envv ? envv : environ); - args.err = 0; - args.pgid = pgid; - args.tcfd = tcfd; sigcritical(SIG_REG_EXEC|SIG_REG_PROC|(tcfd>=0?SIG_REG_TERM:0)); pid = clone(exec_process, stack_top, CLONE_VM|CLONE_VFORK|SIGCHLD, &args); if (pid == -1) diff --git a/src/lib/libast/comp/strftime.c b/src/lib/libast/comp/strftime.c index 6fba37b7f4de..ae5f7572ac29 100644 --- a/src/lib/libast/comp/strftime.c +++ b/src/lib/libast/comp/strftime.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -30,22 +31,12 @@ #undef _def_map_ast #include -#undef _lib_strftime /* we can pass X/Open */ - -#if _lib_strftime - -NoN(strftime) - -#else - extern size_t -strftime(char* buf, size_t len, const char* format, const struct tm* tm) +strftime(char *restrict buf, size_t len, const char *restrict format, const struct tm* tm) { char* s; time_t t; - Tm_t tl; - - memset(&tl, 0, sizeof(tl)); + Tm_t tl = {0}; /* * nl_langinfo() may call strftime() with bogus tm except for @@ -92,5 +83,3 @@ strftime(char* buf, size_t len, const char* format, const struct tm* tm) return 0; return s - buf; } - -#endif diff --git a/src/lib/libast/comp/strptime.c b/src/lib/libast/comp/strptime.c deleted file mode 100644 index dfcdfa32dc55..000000000000 --- a/src/lib/libast/comp/strptime.c +++ /dev/null @@ -1,75 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* K. Eugene Carlson * -* * -***********************************************************************/ -/* - * strptime implementation - */ - -#define strptime ______strptime - -#include -#include - -#undef strptime - -#undef _def_map_ast -#include - -#if _lib_strptime - -NoN(strptime) - -#else - -extern char* -strptime(const char* s, const char* format, struct tm* ts) -{ - char* e; - char* f; - time_t t; - Tm_t tm; - - memset(&tm, 0, sizeof(tm)); - tm.tm_sec = ts->tm_sec; - tm.tm_min = ts->tm_min; - tm.tm_hour = ts->tm_hour; - tm.tm_mday = ts->tm_mday; - tm.tm_mon = ts->tm_mon; - tm.tm_year = ts->tm_year; - tm.tm_wday = ts->tm_wday; - tm.tm_yday = ts->tm_yday; - tm.tm_isdst = ts->tm_isdst; - t = tmtime(&tm, TM_LOCALZONE); - t = tmscan(s, &e, format, &f, &t, 0); - if (e == (char*)s || *f) - return NULL; - tmxtm(&tm, tmxsns(t,0), NULL, 0); - ts->tm_sec = tm.tm_sec; - ts->tm_min = tm.tm_min; - ts->tm_hour = tm.tm_hour; - ts->tm_mday = tm.tm_mday; - ts->tm_mon = tm.tm_mon; - ts->tm_year = tm.tm_year; - ts->tm_wday = tm.tm_wday; - ts->tm_yday = tm.tm_yday; - ts->tm_isdst = tm.tm_isdst; - return e; -} - -#endif diff --git a/src/lib/libast/comp/strtoll.c b/src/lib/libast/comp/strtoll.c index 9606e3c01be4..c6f6150da33d 100644 --- a/src/lib/libast/comp/strtoll.c +++ b/src/lib/libast/comp/strtoll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,8 +32,8 @@ #include #define S2I_function strtoll -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long /* on macOS arm64, long == long long, causing a false-positive "incompatible library declaration" warning on clang */ #if _ast_intmax_long && __clang__ diff --git a/src/lib/libast/comp/strtoull.c b/src/lib/libast/comp/strtoull.c index 60a6af623c6e..f566f80a979d 100644 --- a/src/lib/libast/comp/strtoull.c +++ b/src/lib/libast/comp/strtoull.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,8 +32,8 @@ #include #define S2I_function strtoull -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long #define S2I_unsigned 1 /* on macOS arm64, long == long long, causing a false-positive "incompatible library declaration" warning on clang */ diff --git a/src/lib/libast/comp/wc.c b/src/lib/libast/comp/wc.c deleted file mode 100644 index ab9c37f79403..000000000000 --- a/src/lib/libast/comp/wc.c +++ /dev/null @@ -1,135 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ - -/* - * NOTE: mbs* and wcs* are provided to avoid link errors only - */ - -#include -#include - -#define STUB 1 - -#if !_lib_mbtowc -#undef STUB -size_t -mbtowc(wchar_t* t, const char* s, size_t n) -{ - if (t && n > 0) - *t = *s; - return 1; -} -#endif - -#if !_lib_mbrtowc -#undef STUB -size_t -mbrtowc(wchar_t* t, const char* s, size_t n, mbstate_t* q) -{ -#if _lib_mbtowc -#undef STUB - memset(q, 0, sizeof(*q)); - return mbtowc(t, s, n); -#else - *q = 0; - if (t && n > 0) - *t = *s; - return 1; -#endif -} -#endif - -#if !_lib_mbstowcs -#undef STUB -size_t -mbstowcs(wchar_t* t, const char* s, size_t n) -{ - wchar_t* p = t; - wchar_t* e = t + n; - unsigned char* u = (unsigned char*)s; - - if (t) - while (p < e && (*p++ = *u++)); - else - while (p++, *u++); - return p - t; -} -#endif - -#if !_lib_wctomb -#undef STUB -int -wctomb(char* s, wchar_t c) -{ - if (s) - *s = c; - return 1; -} -#endif - -#if !_lib_wcrtomb -#undef STUB -size_t -wcrtomb(char* s, wchar_t c, mbstate_t* q) -{ -#if _lib_wctomb -#undef STUB - memset(q, 0, sizeof(*q)); - return wctomb(s, c); -#else - if (s) - *s = c; - *q = 0; - return 1; -#endif -} -#endif - -#if !_lib_wcslen -#undef STUB -size_t -wcslen(const wchar_t* s) -{ - const wchar_t* p = s; - - while (*p) - p++; - return p - s; -} -#endif - -#if !_lib_wcstombs -#undef STUB -size_t -wcstombs(char* t, const wchar_t* s, size_t n) -{ - char* p = t; - char* e = t + n; - - if (t) - while (p < e && (*p++ = *s++)); - else - while (p++, *s++); - return p - t; -} -#endif - -#if STUB -NoN(wc) -#endif diff --git a/src/lib/libast/comp/wordexp.c b/src/lib/libast/comp/wordexp.c deleted file mode 100644 index 8142caff8688..000000000000 --- a/src/lib/libast/comp/wordexp.c +++ /dev/null @@ -1,214 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* Johnothan King * -* * -***********************************************************************/ -/* - * POSIX 1003.2 wordexp implementation - */ - -#include -#include -#include - -struct list -{ - struct list *next; -}; - -/* - * eliminates shell quoting as inserted with sh_fmtq - * result replaces - * length of resulting string is returned. - */ -static int sh_unquote(char* string) -{ - char *sp=string, *dp; - int c; - while((c= *sp) && c!='\'') - sp++; - if(c==0) - return sp-string; - if((dp=sp) > string && sp[-1]=='$') - { - int n=stresc(sp+1); - /* copy all but trailing ' */ - while(--n>0) - *dp++ = *++sp; - } - else - { - while((c= *++sp) && c!='\'') - *dp++ = c; - } - *dp=0; - return dp-string; -} - -int wordexp(const char *string, wordexp_t *wdarg, int flags) -{ - Sfio_t *iop; - char *cp=(char*)string; - int c,quoted=0,literal=0,ac=0; - int offset; - char *savebase,**av; - if(offset=stktell(stkstd)) - savebase = stkfreeze(stkstd,0); - if(flags&WRDE_REUSE) - wordfree(wdarg); - else if(!(flags&WRDE_APPEND)) - { - wdarg->we_wordv = 0; - wdarg->we_wordc = 0; - } - if(flags&WRDE_UNDEF) - sfwrite(stkstd,"set -u\n",7); - if(!(flags&WRDE_SHOWERR)) - sfwrite(stkstd,"exec 2> /dev/null\n",18); - sfwrite(stkstd,"print -f \"%q\\n\" ",16); - if(*cp=='#') - sfputc(stkstd,'\\'); - while(c = *cp++) - { - if(c=='\'' && !quoted) - literal = !literal; - else if(!literal) - { - if(c=='\\' && (!quoted || strchr("\\\"`\n$",c))) - { - sfputc(stkstd,'\\'); - if(c= *cp) - cp++; - else - c = '\\'; - } - else if(c=='"') - quoted = !quoted; - else if(c=='`' || (c=='$' && *cp=='(')) - { - if(flags&WRDE_NOCMD) - { - c=WRDE_CMDSUB; - goto err; - } - /* only the shell can parse the rest */ - sfputr(stkstd,cp-1,-1); - break; - } - else if(!quoted && strchr("|&\n;<>"+ac,c)) - { - c=WRDE_BADCHAR; - goto err; - } - else if(c=='(') /* allow | and & inside pattern */ - ac=2; - } - sfputc(stkstd,c); - } - sfputc(stkstd,0); - if(!(iop = sfpopen(NULL,stkptr(stkstd,0),"r"))) - { - c = WRDE_NOSHELL; - goto err; - } - stkseek(stkstd,0); - ac = 0; - while((c=sfgetc(iop)) != EOF) - { - if(c=='\'') - quoted = ! quoted; - else if(!quoted && (c==' ' || c=='\n')) - { - ac++; - c = 0; - } - sfputc(stkstd,c); - } - if(c=sfclose(iop)) - { - if(c==3 || !(flags&WRDE_UNDEF)) - c=WRDE_SYNTAX; - else - c=WRDE_BADVAL; - goto err; - } - c = ac+2; - if(flags&WRDE_DOOFFS) - c += wdarg->we_offs; - if(flags&WRDE_APPEND) - av = (char**)realloc(&wdarg->we_wordv[-1], (wdarg->we_wordc+c)*sizeof(char*)); - else if(av = (char**)malloc(c*sizeof(char*))) - { - if(flags&WRDE_DOOFFS) - memset(av,0,(wdarg->we_offs+1)*sizeof(char*)); - else - av[0] = 0; - } - if(!av) - return WRDE_NOSPACE; - c = stktell(stkstd); - if(!(cp = (char*)malloc(sizeof(char*)+c))) - { - c=WRDE_NOSPACE; - goto err; - } - ((struct list*)cp)->next = (struct list*)(*av); - *av++ = (char*)cp; - cp += sizeof(char*); - wdarg->we_wordv = av; - if(flags&WRDE_APPEND) - av += wdarg->we_wordc; - wdarg->we_wordc += ac; - if(flags&WRDE_DOOFFS) - av += wdarg->we_offs; - memcpy(cp,stkptr(stkstd,offset),c); - while(ac-- > 0) - { - *av++ = cp; - sh_unquote(cp); - while(c= *cp++); - } - *av = 0; - c=0; -err: - if(offset) - stkset(stkstd,savebase,offset); - else - stkseek(stkstd,0); - return c; -} - -/* - * free fields in - */ -int wordfree(wordexp_t *wdarg) -{ - struct list *arg, *argnext; - if(wdarg->we_wordv) - { - argnext = (struct list*)wdarg->we_wordv[-1]; - while(arg=argnext) - { - argnext = arg->next; - free(arg); - } - free(&wdarg->we_wordv[-1]); - wdarg->we_wordv = 0; - } - wdarg->we_wordc=0; - return 0; -} diff --git a/src/lib/libast/disc/sfkeyprintf.c b/src/lib/libast/disc/sfkeyprintf.c index 91c4d680606b..ce2c6347b610 100644 --- a/src/lib/libast/disc/sfkeyprintf.c +++ b/src/lib/libast/disc/sfkeyprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -339,15 +340,17 @@ sfkeyprintf(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup_t lookup { int i; int r; - Fmt_t fmt; + Fmt_t fmt = { + .handle = handle, + .lookup = lookup, + .convert = convert, + .fmt = { + .version = SFIO_VERSION, + .form = (char*)format, + .extf = getfmt + } + }; - memset(&fmt, 0, sizeof(fmt)); - fmt.fmt.version = SFIO_VERSION; - fmt.fmt.form = (char*)format; - fmt.fmt.extf = getfmt; - fmt.handle = handle; - fmt.lookup = lookup; - fmt.convert = convert; r = sfprintf(sp, "%!", &fmt) - fmt.invisible; for (i = 0; i < elementsof(fmt.tmp); i++) if (fmt.tmp[i]) @@ -371,16 +374,18 @@ sfkeyprintf_20000308(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup { int i; int r; - Fmt_t fmt; + Fmt_t fmt = { + .version = 20030909, + .handle = handle, + .lookup = lookup, + .convert = convert, + .fmt = { + .version = SFIO_VERSION, + .form = (char*)format, + .extf = getfmt + } + }; - memset(&fmt, 0, sizeof(fmt)); - fmt.version = 20030909; - fmt.fmt.version = SFIO_VERSION; - fmt.fmt.form = (char*)format; - fmt.fmt.extf = getfmt; - fmt.handle = handle; - fmt.lookup = lookup; - fmt.convert = convert; r = sfprintf(sp, "%!", &fmt) - fmt.invisible; for (i = 0; i < elementsof(fmt.tmp); i++) if (fmt.tmp[i]) diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index a4fc7f18a8b0..661b36470c85 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -1,6 +1,5 @@ iff AST_COMMON -hdr pthread,stdarg,stddef,stdint,inttypes,types,unistd -sys types +hdr stdarg,stdint,inttypes typ __va_list stdio.h std noreturn note{ noreturn ok }end compile{ @@ -512,12 +511,8 @@ tst - -DTRY=1 - -DTRY=1 -Dvoid=char - -DTRY=2 - -DTRY=3 - -DTRY=4 output{ cat{ #ifndef _AST_STD_H - # if _hdr_stddef # include - # endif - # if _sys_types # include - # endif # if _hdr_stdint # include # else @@ -556,7 +551,6 @@ tst - note{ does this compiler have __builtin_unreachable() }end output{ * executing it, put it in a test function that is called with argc as the argument. * argc should never be zero on init, but hopefully optimizers aren't that smart. */ - #include #include "ast_release.h" void testfn(int a) { @@ -581,32 +575,6 @@ tst - note{ does this compiler have __builtin_unreachable() }end output{ echo '#define UNREACHABLE() abort()' }end -# TODO: remove when we require C99 -tst has___func__ note{ does this compiler have __func__ }end execute{ - #include - int testfn(void) - { - return strcmp(__func__,"testfn")==0; - } - int main(void) - { - return !(testfn && strcmp(__func__,"main")==0); - } -}end - -# TODO: remove when we require C99 (use __func__) -tst has___FUNCTION__ note{ does this compiler have __FUNCTION__ }end execute{ - #include - int testfn(void) - { - return strcmp(__FUNCTION__,"testfn")==0; - } - int main(void) - { - return !(testfn && strcmp(__FUNCTION__,"main")==0); - } -}end - tst has__Static_assert note{ does this compiler have _Static_assert }end execute{ int main(void) { diff --git a/src/lib/libast/features/fcntl.c b/src/lib/libast/features/fcntl.c index e66fe52d33b7..cb1d4aba4d99 100644 --- a/src/lib/libast/features/fcntl.c +++ b/src/lib/libast/features/fcntl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -34,9 +34,7 @@ #define getpagesize ______getpagesize #define ioctl ______ioctl -#if _hdr_fcntl #include -#endif #include #include diff --git a/src/lib/libast/features/float b/src/lib/libast/features/float index fd95251095ca..a95dcb1aabee 100644 --- a/src/lib/libast/features/float +++ b/src/lib/libast/features/float @@ -1,6 +1,6 @@ set nooptimize set stdio FEATURE/standards -hdr float,limits,math,values +hdr float,math,values lib,npt frexp,ldexp,finite,finitel,copysign,copysignl,powf,pow,powl FEATURE/standards math.h -lm # # The "does foo(3) compile and link" tests below are compiled and linked, but @@ -122,9 +122,7 @@ macro{ #if _hdr_float #include #endif - #if _hdr_limits #include - #endif #if _hdr_math #include #endif @@ -280,9 +278,7 @@ tst - note{ missing floating point limits }end output{ #if _hdr_float #include #endif - #if _hdr_limits #include - #endif #if _hdr_math #include #endif diff --git a/src/lib/libast/features/lib b/src/lib/libast/features/lib index 7e07aca36f6b..0e668475d627 100644 --- a/src/lib/libast/features/lib +++ b/src/lib/libast/features/lib @@ -3,8 +3,8 @@ ref -D_def_map_ast=1 cmd universe sys mman -hdr fcntl,dirent,direntry,filio,fnmatch,jioctl,libgen,limits -hdr locale,ndir,nl_types,process,spawn,utime +hdr dirent,direntry,jioctl +hdr ndir,nl_types,process,spawn,utime hdr linux/fs,linux/msdos_fs hdr wctype hdr wchar note{ and isw*() really work }end execute{ @@ -22,25 +22,20 @@ hdr wchar note{ and isw*() really work }end execute{ dat _tzname,tzname -lib BSDsetpgrp -lib _cleanup -lib bcopy,bzero,confstr,dirread -lib fchmod,fcntl,fnmatch,fork,fsync -lib getconf,getdents,getdirentries,getdtablesize -lib gethostname,getpagesize,getrlimit,getuniverse -lib glob,iswblank,iswctype,killpg,link,localeconv,madvise -lib mbtowc,mbrtowc,memalign,memdup -lib mktemp,mktime +lib confstr,dirread +lib fcntl,fsync +lib getdents,getdirentries,getdtablesize +lib gethostname,getpagesize,getrlimit +lib madvise,memalign,memdup lib opendir,openat,pathconf,pipe2,posix_close -lib rand_r -lib rewinddir,setlocale -lib setpgrp,setpgrp2,setreuid,setuid +lib rewinddir +lib setreuid,setuid lib socketpair lib clone,spawn,spawnve -lib strlcat,strlcpy -lib strmode,strftime,symlink,sysconf,sysinfo -lib telldir,tmpnam,tzset,universe,unlink,utime,wctype -lib ftruncate,truncate +lib strlcat,strlcpy,stpcpy +lib strmode,sysconf,sysinfo +lib tzset,universe,utime +lib ftruncate lib,npt strtod,strtold,strtol,strtoll,strtoul,strtoull stdlib.h lib,npt sigflag signal.h @@ -52,7 +47,7 @@ mem DIR.dd_fd sys/types.h - dirent.h - sys/dir.h mem inheritance.pgroup spawn.h mem tm.tm_zone time.h -sys dir,filio,ioctl,jioctl,localedef,ptem,resource +sys dir,filio,ioctl,jioctl,ptem,resource sys socket,stream,systeminfo,universe tst lib_poll note{ poll() args comply with the POSIX standard }end execute{ @@ -349,14 +344,6 @@ tst cross{ echo "#define _UNIV_DEFAULT \"$u\" /* default universe name */" }end -std cleanup note{ stuck with standard _cleanup }end noexecute{ - extern void exit(int); - extern void _exit(int); - extern void _cleanup(void); - void _cleanup(void) { _exit(0); } - int main(void) { printf("cleanup\n"); exit(1); } -}end - std strtod stdlib.h note{ stuck with standard strtod }end nostatic{ double strtod(const char* s, char** e) { return 0.0; } int main(void) { printf(""); return strtod("1",0) != 0; } diff --git a/src/lib/libast/features/limits.c b/src/lib/libast/features/limits.c index 73abb8aad2bc..49e0d6fd0d1c 100644 --- a/src/lib/libast/features/limits.c +++ b/src/lib/libast/features/limits.c @@ -59,9 +59,7 @@ #undef _SGIAPI #define _SGIAPI 1 -#if _hdr_limits #include -#endif #undef _SGIAPI #define _SGIAPI 0 diff --git a/src/lib/libast/features/map.c b/src/lib/libast/features/map.c index 03090db4f653..52012e6ea7e6 100644 --- a/src/lib/libast/features/map.c +++ b/src/lib/libast/features/map.c @@ -156,7 +156,7 @@ main(void) #if _npt_strtold && !_std_strtold printf("#ifndef _ISOC99_SOURCE\n"); #endif - printf("extern _ast_fltmax_t strtold(const char*, char**);\n"); + printf("extern long double strtold(const char*, char**);\n"); #if _npt_strtold && !_std_strtold printf("#endif\n"); #endif @@ -165,7 +165,7 @@ main(void) #if _npt_strtoll && !_std_strtol printf("#ifndef _ISOC99_SOURCE\n"); #endif - printf("extern _ast_intmax_t strtoll(const char*, char**, int);\n"); + printf("extern long long strtoll(const char*, char**, int);\n"); #if _npt_strtoll && !_std_strtol printf("#endif\n"); #endif @@ -174,7 +174,7 @@ main(void) #if _npt_strtoull && !_std_strtol printf("#ifndef _ISOC99_SOURCE\n"); #endif - printf("extern unsigned _ast_intmax_t strtoull(const char*, char**, int);\n"); + printf("extern unsigned long long strtoull(const char*, char**, int);\n"); #if _npt_strtoull && !_std_strtoul printf("#endif\n"); #endif diff --git a/src/lib/libast/features/sig.sh b/src/lib/libast/features/sig.sh index 9c3c56dc3ce7..faccae93e4f4 100644 --- a/src/lib/libast/features/sig.sh +++ b/src/lib/libast/features/sig.sh @@ -2,7 +2,7 @@ # # # This software is part of the ast package # # Copyright (c) 1985-2011 AT&T Intellectual Property # -# Copyright (c) 2020-2024 Contributors to ksh 93u+m # +# Copyright (c) 2020-2026 Contributors to ksh 93u+m # # and is licensed under the # # Eclipse Public License, Version 2.0 # # # diff --git a/src/lib/libast/features/stdio b/src/lib/libast/features/stdio index ae545ca4f4b1..4d7c1ac77d9c 100644 --- a/src/lib/libast/features/stdio +++ b/src/lib/libast/features/stdio @@ -225,7 +225,7 @@ cat{ extern int _doprnt(const char*, va_list, FILE*); extern int _doscan(FILE*, const char*, va_list); - extern int asprintf(char**, const char*, ...); + extern int asprintf(char **restrict, const char *restrict, ...); extern int clearerr(FILE*); extern int fclose(FILE*); extern FILE* fdopen(int, const char*); @@ -236,13 +236,13 @@ cat{ extern int fgetpos(FILE*, fpos_t*); extern char* fgets(char*, int, FILE*); extern int fileno(FILE*); - extern FILE* fopen(const char*, const char*); + extern FILE* fopen(const char *restrict, const char *restrict); extern int fprintf(FILE*, const char*, ...); extern int fpurge(FILE*); extern int fputc(int, FILE*); extern int fputs(const char*, FILE*); extern size_t fread(void*, size_t, size_t, FILE*); - extern FILE* freopen(const char*, const char*, FILE*); + extern FILE* freopen(const char *restrict, const char *restrict, FILE*); extern int fscanf(FILE*, const char*, ...); extern int fseek(FILE*, long, int); extern int fseeko(FILE*, off_t, int); @@ -267,19 +267,19 @@ cat{ extern int setbuffer(FILE*, char*, int); extern int setlinebuf(FILE*); extern int setvbuf(FILE*, char*, int, size_t); - extern int snprintf(char*, size_t, const char*, ...); - extern int sprintf(char*, const char*, ...); - extern int sscanf(const char*, const char*, ...); + extern int snprintf(char *restrict, size_t, const char *restrict, ...); + extern int sprintf(char *restrict, const char *restrict, ...); + extern int sscanf(const char *restrict, const char *restrict, ...); extern FILE* tmpfile(void); extern int ungetc(int, FILE*); - extern int vasprintf(char**, const char*, va_list); + extern int vasprintf(char **restrict, const char *restrict, va_list); extern int vfprintf(FILE*, const char*, va_list); extern int vfscanf(FILE*, const char*, va_list); extern int vprintf(const char*, va_list); extern int vscanf(const char*, va_list); - extern int vsnprintf(char*, size_t, const char*, va_list); - extern int vsprintf(char*, const char*, va_list); - extern int vsscanf(const char*, const char*, va_list); + extern int vsnprintf(char *restrict, size_t, const char *restrict, va_list); + extern int vsprintf(char *restrict, const char *restrict, va_list); + extern int vsscanf(const char *restrict, const char *restrict, va_list); extern void clearerr_unlocked(FILE*); extern int feof_unlocked(FILE*); diff --git a/src/lib/libast/features/sys b/src/lib/libast/features/sys index 8951967720d6..67b6739cff90 100644 --- a/src/lib/libast/features/sys +++ b/src/lib/libast/features/sys @@ -58,7 +58,8 @@ extern eaccess int (const char*, int) extern fsync int (int) extern ftruncate int (int, off_t) extern memalign void* (size_t, size_t) -extern strlcat size_t (char*, const char*, size_t) -extern strlcpy size_t (char*, const char*, size_t) +extern strlcat size_t (char *restrict, const char *restrict, size_t) +extern strlcpy size_t (char *restrict, const char *restrict, size_t) +extern stpcpy size_t (char *restrict, const char *restrict) print #include diff --git a/src/lib/libast/features/tmx b/src/lib/libast/features/tmx index fee8b82a3cf3..433be8c72a37 100644 --- a/src/lib/libast/features/tmx +++ b/src/lib/libast/features/tmx @@ -82,7 +82,7 @@ cat{ extern Time_t tmxdate(const char*, char**, Time_t); extern Time_t tmxduration(const char*, char**); - extern char* tmxfmt(char*, size_t, const char*, Time_t); + extern char* tmxfmt(char *restrict, size_t, const char *restrict, Time_t); extern Time_t tmxleap(Time_t); extern Tm_t* tmxmake(Time_t); extern Time_t tmxscan(const char*, char**, const char*, char**, Time_t, long); diff --git a/src/lib/libast/features/tvlib b/src/lib/libast/features/tvlib index 7dbdc2e96c38..87b6b18d1ff6 100644 --- a/src/lib/libast/features/tvlib +++ b/src/lib/libast/features/tvlib @@ -1,4 +1,3 @@ -hdr time lib clock_settime,gettimeofday,settimeofday,stime,utimes lib nanosleep,usleep lib utimensat sys/stat.h note{ complete utimensat implementation }end link{ diff --git a/src/lib/libast/features/wchar b/src/lib/libast/features/wchar index c078fa8aba1d..77247a9f4fc4 100644 --- a/src/lib/libast/features/wchar +++ b/src/lib/libast/features/wchar @@ -10,9 +10,7 @@ cat{ #endif }end -lib mbstowcs,wctomb,wcrtomb,wcslen,wcstombs,wcwidth stdlib.h stdio.h wchar.h -lib towlower,towupper stdlib.h stdio.h wchar.h -typ mbstate_t stdlib.h stdio.h wchar.h +hdr wchar nxt wchar run{ @@ -116,28 +114,6 @@ run{ #define wprintf _ast_wprintf #define wscanf _ast_wscanf - #if !_typ_mbstate_t - #undef _typ_mbstate_t - #define _typ_mbstate_t 1 - typedef char mbstate_t; - #endif - - #if !_lib_mbstowcs - extern size_t mbstowcs(wchar_t*, const char*, size_t); - #endif - #if !_lib_wctomb - extern int wctomb(char*, wchar_t); - #endif - #if !_lib_wcrtomb - extern size_t wcrtomb(char*, wchar_t, mbstate_t*); - #endif - #if !_lib_wcslen - extern size_t wcslen(const wchar_t*); - #endif - #if !_lib_wcstombs - extern size_t wcstombs(char*, const wchar_t*, size_t); - #endif - extern int fwprintf(FILE*, const wchar_t*, ...); extern int fwscanf(FILE*, const wchar_t*, ...); extern wint_t fgetwc(FILE*); @@ -150,15 +126,15 @@ run{ extern wchar_t* getws(wchar_t*); extern wint_t putwc(wchar_t, FILE*); extern wint_t putwchar(wchar_t); - extern int swprintf(wchar_t*, size_t, const wchar_t*, ...); - extern int swscanf(const wchar_t*, const wchar_t*, ...); + extern int swprintf(wchar_t *restrict, size_t, const wchar_t *restrict, ...); + extern int swscanf(const wchar_t *restrict, const wchar_t *restrict, ...); extern wint_t ungetwc(wint_t, FILE*); extern int vfwprintf(FILE*, const wchar_t*, va_list); extern int vfwscanf(FILE*, const wchar_t*, va_list); extern int vwprintf(const wchar_t*, va_list); extern int vwscanf(const wchar_t*, va_list); - extern int vswprintf(wchar_t*, size_t, const wchar_t*, va_list); - extern int vswscanf(const wchar_t*, const wchar_t*, va_list); + extern int vswprintf(wchar_t *restrict, size_t, const wchar_t *restrict, va_list); + extern int vswscanf(const wchar_t *restrict, const wchar_t *restrict, va_list); extern int wprintf(const wchar_t*, ...); extern int wscanf(const wchar_t*, ...); diff --git a/src/lib/libast/features/wctype b/src/lib/libast/features/wctype index c232d734c395..51a3d044feef 100644 --- a/src/lib/libast/features/wctype +++ b/src/lib/libast/features/wctype @@ -9,9 +9,9 @@ cat < -#if !_lib_fork -#error In 2022, libast joined the 21st century and started requiring fork(2). -#endif #include #include #include @@ -95,34 +92,6 @@ struct _sfio_s; #endif #endif -/* locale stuff */ - -#if !_hdr_locale - -struct lconv -{ - char* decimal_point; - char* thousands_sep; - char* grouping; - char* int_curr_symbol; - char* currency_symbol; - char* mon_decimal_point; - char* mon_thousands_sep; - char* mon_grouping; - char* positive_sign; - char* negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; -}; - -#endif - #undef getenv #define getenv _ast_getenv @@ -238,7 +207,7 @@ typedef struct struct /* ast.locale.* -- stuff set in setlocale.c */ { int (*collate)(const char*, const char*); /* strcoll(3), an alternative, or strcmp(3) for no collation */ - size_t (*transform)(char*, const char*, size_t); /* strxfrm(3), an alternative, or 0 for no collation */ + size_t (*transform)(char *restrict, const char *restrict, size_t); /* strxfrm(3), an alternative, or 0 for no collation */ void *uc2wc; /* iconv descriptor for converting unicode to locale's wide char */ uint32_t serial; uint32_t set; /* AST_LC_* bit flags (see above) */ @@ -254,7 +223,7 @@ typedef struct int (*alpha)(wchar_t); int (*conv)(char*, wchar_t); int (*len)(const char*, size_t); - int (*towc)(wchar_t*, const char*, size_t); + int (*towc)(wchar_t *restrict, const char *restrict, size_t); int (*width)(wchar_t); } mb; #endif @@ -265,10 +234,6 @@ extern _Ast_info_t _ast_info; /* direct macro access for bsd crossover */ -#if !defined(memzero) && !defined(_lib_memzero) -#define memzero(b,n) memset(b,0,n) -#endif - #if !defined(remove) extern int remove(const char*); #endif diff --git a/src/lib/libast/include/sfio.h b/src/lib/libast/include/sfio.h index 233d0ddf6e31..b91b49cad889 100644 --- a/src/lib/libast/include/sfio.h +++ b/src/lib/libast/include/sfio.h @@ -181,8 +181,8 @@ extern Sfio_t _Sfstdout; extern Sfio_t _Sfstderr; extern Sfio_t* sfnew(Sfio_t*, void*, size_t, int, unsigned short); -extern Sfio_t* sfopen(Sfio_t*, const char*, const char*); -extern Sfio_t* sfpopen(Sfio_t*, const char*, const char*); +extern Sfio_t* sfopen(Sfio_t*, const char *restrict, const char *restrict); +extern Sfio_t* sfpopen(Sfio_t*, const char *restrict, const char *restrict); extern Sfio_t* sfstack(Sfio_t*, Sfio_t*); extern Sfio_t* sfswap(Sfio_t*, Sfio_t*); extern Sfio_t* sftmp(size_t); @@ -213,14 +213,14 @@ extern ssize_t sfnputc(Sfio_t*, int, size_t); extern int sfungetc(Sfio_t*, int); extern ssize_t sfprintf(Sfio_t*, const char*, ...); extern char* sfprints(const char*, ...); -extern ssize_t sfaprints(char**, const char*, ...); -extern ssize_t sfsprintf(char*, size_t, const char*, ...); -extern ssize_t sfvsprintf(char*, size_t, const char*, va_list); -extern ssize_t sfvasprints(char**, const char*, va_list); +extern ssize_t sfaprints(char **restrict, const char *restrict, ...); +extern ssize_t sfsprintf(char *restrict, size_t, const char *restrict, ...); +extern ssize_t sfvsprintf(char *restrict, size_t, const char *restrict, va_list); +extern ssize_t sfvasprints(char **restrict, const char *restrict, va_list); extern ssize_t sfvprintf(Sfio_t*, const char*, va_list); extern int sfscanf(Sfio_t*, const char*, ...); -extern int sfsscanf(const char*, const char*, ...); -extern int sfvsscanf(const char*, const char*, va_list); +extern int sfsscanf(const char *restrict, const char *restrict, ...); +extern int sfvsscanf(const char *restrict, const char *restrict, va_list); extern int sfvscanf(Sfio_t*, const char*, va_list); /* io functions with discipline continuation */ diff --git a/src/lib/libast/include/sfio_t.h b/src/lib/libast/include/sfio_t.h index bf0066ac6533..65d661080eb8 100644 --- a/src/lib/libast/include/sfio_t.h +++ b/src/lib/libast/include/sfio_t.h @@ -66,59 +66,46 @@ #define SFIO_RDWRSTR (SFIO_RDWR|SFIO_STRING) /* for static initialization of an Sfio_t structure */ -#define SFNEW(data,size,file,type,disc) \ - { (unsigned char*)(data), /* next */ \ - (unsigned char*)(data), /* endw */ \ - (unsigned char*)(data), /* endr */ \ - (unsigned char*)(data), /* endb */ \ - NULL, /* push */ \ - (unsigned short)((type)&SFIO_FLAGS), /* flags */ \ - (short)(file), /* file */ \ - (unsigned char*)(data), /* data */ \ - (ssize_t)(size), /* size */ \ - -1, /* val */ \ - 0, /* extent */ \ - 0, /* here */ \ - 0, /* ngetr */ \ - {0}, /* tiny */ \ - 0, /* bits */ \ - (unsigned int)(((type)&(SFIO_RDWR))|SFIO_INIT), /* mode */ \ - (struct _sfdisc_s*)(disc), /* disc */ \ - NULL, /* pool */ \ - NULL, /* rsrv */ \ - NULL, /* proc */ \ - NULL, /* stdio */ \ - 0, /* lpos */ \ - 0, /* iosz */ \ - 0 /* getr */ \ +#define SFNEW(data,size,file,type,dsc) \ + { ._next = (unsigned char*)(data), \ + ._endw = (unsigned char*)(data), \ + ._endr = (unsigned char*)(data), \ + ._endb = (unsigned char*)(data), \ + ._flags = (unsigned short)((type)&SFIO_FLAGS), \ + ._file = (short)(file), \ + ._data = (unsigned char*)(data), \ + ._size = (ssize_t)(size), \ + ._val = -1, \ + .mode = (unsigned int)(((type)&(SFIO_RDWR))|SFIO_INIT), \ + .disc = (struct _sfdisc_s*)(dsc) \ } /* function to clear an Sfio_t structure */ #define SFCLEAR(f) \ - ( (f)->next = NULL, /* next */ \ - (f)->endw = NULL, /* endw */ \ - (f)->endr = NULL, /* endr */ \ - (f)->endb = NULL, /* endb */ \ - (f)->push = NULL, /* push */ \ - (f)->flags = 0, /* flags */ \ - (f)->file = -1, /* file */ \ - (f)->data = NULL, /* data */ \ - (f)->size = -1, /* size */ \ - (f)->val = -1, /* val */ \ - (f)->extent = -1, /* extent */ \ - (f)->here = 0, /* here */ \ - (f)->ngetr = 0, /* ngetr */ \ - (f)->tiny[0] = 0, /* tiny */ \ - (f)->bits = 0, /* bits */ \ - (f)->mode = 0, /* mode */ \ - (f)->disc = NULL, /* disc */ \ - (f)->pool = NULL, /* pool */ \ - (f)->rsrv = NULL, /* rsrv */ \ - (f)->proc = NULL, /* proc */ \ - (f)->stdio = NULL, /* stdio */ \ - (f)->lpos = 0, /* lpos */ \ - (f)->iosz = 0, /* iosz */ \ - (f)->getr = 0 /* getr */ \ + ( (f)->next = NULL, \ + (f)->endw = NULL, \ + (f)->endr = NULL, \ + (f)->endb = NULL, \ + (f)->push = NULL, \ + (f)->flags = 0, \ + (f)->file = -1, \ + (f)->data = NULL, \ + (f)->size = -1, \ + (f)->val = -1, \ + (f)->extent = -1, \ + (f)->here = 0, \ + (f)->ngetr = 0, \ + (f)->tiny[0] = 0, \ + (f)->bits = 0, \ + (f)->mode = 0, \ + (f)->disc = NULL, \ + (f)->pool = NULL, \ + (f)->rsrv = NULL, \ + (f)->proc = NULL, \ + (f)->stdio = NULL, \ + (f)->lpos = 0, \ + (f)->iosz = 0, \ + (f)->getr = 0 \ ) /* expose next stream inside discipline function; state saved in int f */ diff --git a/src/lib/libast/include/tm.h b/src/lib/libast/include/tm.h index 2ed18bb81e1c..ffbcf1d41bf0 100644 --- a/src/lib/libast/include/tm.h +++ b/src/lib/libast/include/tm.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -15,6 +15,7 @@ * Phong Vo * * Martijn Dekker * * K. Eugene Carlson * +* Johnothan King * * * ***********************************************************************/ /* @@ -154,7 +155,7 @@ extern Tm_info_t* _tm_infop_; extern time_t tmdate(const char*, char**, time_t*); extern int tmequiv(Tm_t*); extern Tm_t* tmfix(Tm_t*); -extern char* tmfmt(char*, size_t, const char*, time_t*); +extern char* tmfmt(char *restrict, size_t, const char *restrict, time_t*); extern char* tmform(char*, const char*, time_t*); extern int tmgoff(const char*, char**, int); extern void tminit(Tm_zone_t*, time_t, const char); diff --git a/src/lib/libast/man/mem.3 b/src/lib/libast/man/mem.3 index c728aeb94890..c40b31344fa4 100644 --- a/src/lib/libast/man/mem.3 +++ b/src/lib/libast/man/mem.3 @@ -38,13 +38,12 @@ .. .TH MEM 3 .SH NAME -mem \- memory buffer routines +mem \- memory buffer routine .SH SYNOPSIS .EX #include void* memdup(const void* \fIbuf\fP, size_t \fIn\fP) -void* memzero(void* \fIbuf\fP, size_t \fIn\fP); .EE .SH DESCRIPTION .L memdup @@ -58,14 +57,6 @@ and returns a pointer to the new copy. 0 is returned if .IR malloc (3) fails. -.PP -.L memzero -sets the first -.I n -bytes in -.I buf -to -.IR 0 . .SH "SEE ALSO" .br .IR str (3), diff --git a/src/lib/libast/man/sfio.3 b/src/lib/libast/man/sfio.3 index 9abbb59a37f1..8425021ed2a4 100644 --- a/src/lib/libast/man/sfio.3 +++ b/src/lib/libast/man/sfio.3 @@ -69,8 +69,8 @@ SFIO_IOINTR .nf .ft 5 Sfio_t* sfnew(Sfio_t* f, void* buf, size_t size, int fd, int flags); -Sfio_t* sfopen(Sfio_t* f, const char* string, const char* mode); -Sfio_t* sfpopen(Sfio_t* f, const char* cmd, const char* mode); +Sfio_t* sfopen(Sfio_t* f, const char *restrict string, const char *restrict mode); +Sfio_t* sfpopen(Sfio_t* f, const char *restrict cmd, const char *restrict mode); Sfio_t* sfstropen(void); Sfio_t* sftmp(size_t size); int sfclose(Sfio_t* f); @@ -107,19 +107,19 @@ void* sfreserve(Sfio_t* f, ssize_t n, int type); .Ss "DATA FORMATTING" .nf .ft 5 -int sfscanf(Sfio_t* f, const char* format, ...); -int sfsscanf(const char* s, const char* format, ...); -int sfvsscanf(const char* s, const char* format, va_list args); -int sfvscanf(Sfio_t* f, const char* format, va_list args); - -ssize_t sfprintf(Sfio_t* f, const char* format, ...); -char* sfprints(const char* format, ...); -char* sfvprints(const char* format, va_list args); -ssize_t sfaprints(char** sp, const char* format, ...); -ssize_t sfvaprints(char** sp, const char* format, va_list args); -ssize_t sfsprintf(char* s, size_t n, const char* format, ...); -ssize_t sfvsprintf(char* s, size_t n, const char* format, va_list args); -ssize_t sfvprintf(Sfio_t* f, const char* format, va_list args); +int sfscanf(Sfio_t* f, const char* format, ...); +int sfsscanf(const char *restrict s, const char *restrict format, ...); +int sfvsscanf(const char *restrict s, const char *restrict format, va_list args); +int sfvscanf(Sfio_t* f, const char* format, va_list args); + +ssize_t sfprintf(Sfio_t* f, const char* format, ...); +char* sfprints(const char* format, ...); +char* sfvprints(const char* format, va_list args); +ssize_t sfaprints(char **restrict sp, const char *restrict format, ...); +ssize_t sfvaprints(char **restrict sp, const char *restrict format, va_list args); +ssize_t sfsprintf(char *restrict s, size_t n, const char *restrict format, ...); +ssize_t sfvsprintf(char *restrict s, size_t n, const char *restrict format, va_list args); +ssize_t sfvprintf(Sfio_t* f, const char* format, va_list args); Sffmt_t; @@ -455,7 +455,7 @@ opened for both read and write, e.g., sockets. \f3flags\fP: This is composed from \f3SFIO_EOF\fP and bit values defined in the \fBBIT FLAGS\fP section. -.Ss " Sfio_t* sfopen(Sfio_t* f, const char* string, const char* mode)" +.Ss " Sfio_t* sfopen(Sfio_t* f, const char *restrict string, const char *restrict mode)" If \f3string\fP is \f3NULL\fP, \f3f\fP is a file stream and @@ -502,7 +502,7 @@ both read and write. \f3x\fP specifies exclusive mode, i.e., a file opened for writing should not already exist. -.Ss " Sfio_t* sfpopen(Sfio_t* f, const char* cmd, const char* mode)" +.Ss " Sfio_t* sfpopen(Sfio_t* f, const char *restrict cmd, const char *restrict mode)" This function opens a stream that corresponds to the coprocess \f3cmd\fP. The argument \f3mode\fP should be composed from \f3r\fP, \f3w\fP, and \f3+\fP. The argument \f3f\fP, if not \f3NULL\fP, @@ -1087,12 +1087,12 @@ when the format of the structure \f3Sffmt_t\fP changes. Note that the version number corresponds to the Sfio version number which is defined in the macro value \f3SFIO_VERSION\fP. .Ss " ssize_t sfprintf(Sfio_t* f, const char* format, ...);" -.Ss " char* sfprints(const char* format, ...);" -.Ss " char* sfvprints(const char* format, va_list args);" -.Ss " ssize_t sfaprints(char** sp, const char* format, ...);" -.Ss " ssize_t sfvaprints(char** sp, const char* format, va_list args);" -.Ss " ssize_t sfsprintf(char* s, size_t n, const char* format, ...)" -.Ss " ssize_t sfvsprintf(char* s, size_t n, const char* format, va_list args);" +.Ss " char* sfprints(const char* format, ...);" +.Ss " char* sfvprints(const char* format, va_list args);" +.Ss " ssize_t sfaprints(char **restrict sp, const char *restrict format, ...);" +.Ss " ssize_t sfvaprints(char **restrict sp, const char *restrict format, va_list args);" +.Ss " ssize_t sfsprintf(char *restrict s, size_t n, const char *restrict format, ...)" +.Ss " ssize_t sfvsprintf(char *restrict s, size_t n, const char *restrict format, va_list args);" .Ss " ssize_t sfvprintf(Sfio_t* f, const char* format, va_list args);" These functions format output data. \f3sfprintf()\fP and \f3sfvprintf()\fP write to output stream \f3f\fP. @@ -1310,8 +1310,8 @@ to be passed to the extension function \f3Sffmt_t.extf\fP. Parentheses shall be balanced. If \f3extfdata\fP is \f3*\fP, the string is obtained from the argument list. .Ss " int sfscanf(Sfio_t* f, const char* format, ...)" -.Ss " int sfsscanf(const char* s, const char* format, ...)" -.Ss " int sfvsscanf(const char* s, const char* format, va_list args)" +.Ss " int sfsscanf(const char *restrict s, const char *restrict format, ...)" +.Ss " int sfvsscanf(const char *restrict s, const char *restrict format, va_list args)" .Ss " int sfvscanf(Sfio_t* f, const char* format, va_list args)" These functions scan data items. \f3sfscanf()\fP scans from the input stream \f3f\fP diff --git a/src/lib/libast/man/strcopy.3 b/src/lib/libast/man/strcopy.3 index e3aef40555a7..50efad2a0ed4 100644 --- a/src/lib/libast/man/strcopy.3 +++ b/src/lib/libast/man/strcopy.3 @@ -50,5 +50,8 @@ into A pointer to the 0 character in .I a is returned. +Unlike +.IR stpcpy , +this function is capable of operating on overlapping buffers. .SH "SEE ALSO" -strcpy(3) +strcpy(3), stpcpy(3) diff --git a/src/lib/libast/man/tm.3 b/src/lib/libast/man/tm.3 index ab979aaab3a3..b06fb6a8367a 100644 --- a/src/lib/libast/man/tm.3 +++ b/src/lib/libast/man/tm.3 @@ -176,7 +176,7 @@ to determine its proper value after the .L tmfix() adjustments. .TP -.L "char* tmfmt(char* buf, size_t len, const char* format, time_t* clock)" +.L "char* tmfmt(char *restrict buf, size_t len, const char *restrict format, time_t* clock)" Formats the date pointed to by .L clock into the buffer diff --git a/src/lib/libast/misc/cmdarg.c b/src/lib/libast/misc/cmdarg.c index af70dd98ae8c..c670d60fb52d 100644 --- a/src/lib/libast/misc/cmdarg.c +++ b/src/lib/libast/misc/cmdarg.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -43,10 +43,8 @@ cmdrun(int argc, char** argv, Cmddisc_t* disc) Cmdarg_t* cmdopen(char** argv, int argmax, int size, const char* argpat, int flags) { - Cmddisc_t disc; + Cmddisc_t disc = { .version = CMD_VERSION }; - memset(&disc, 0, sizeof(disc)); - disc.version = CMD_VERSION; if (!(flags & CMD_SILENT)) { flags |= CMD_EXIT; diff --git a/src/lib/libast/misc/debug.c b/src/lib/libast/misc/debug.c index 4620cf12860c..f8a4cd524a35 100644 --- a/src/lib/libast/misc/debug.c +++ b/src/lib/libast/misc/debug.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,7 +33,7 @@ debug_fatal(const char* file, int line) abort(); } -#if _sys_times && _lib_getrusage +#if _lib_getrusage #include #ifndef RUSAGE_SELF diff --git a/src/lib/libast/misc/glob.c b/src/lib/libast/misc/glob.c index 98868b49d18e..8e7f7d921dd4 100644 --- a/src/lib/libast/misc/glob.c +++ b/src/lib/libast/misc/glob.c @@ -769,7 +769,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t ap->gl_begin = ap->gl_path + gp->gl_extra; pat = strcopy(ap->gl_begin, pattern + optlen); if (suflen) - pat = strcopy(pat, gp->gl_suffix); + pat = stpcpy(pat, gp->gl_suffix); if (optlen) strlcpy(gp->gl_pat = gp->gl_opt = pat + 1, pattern, optlen); else diff --git a/src/lib/libast/misc/optget.c b/src/lib/libast/misc/optget.c index 27930fedc009..a1bfbb119486 100644 --- a/src/lib/libast/misc/optget.c +++ b/src/lib/libast/misc/optget.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -451,13 +451,13 @@ secname(char* section) s = "MISCELLANEOUS "; break; default: - s = 0; + s = NULL; break; } if (s) - t = strcopy(t, s); + t = stpcpy(t, s); } - s = 0; + s = NULL; for (i = 0; i < elementsof(sections); i++) { if (section[0] == sections[i].section[0] && (section[1] == sections[i].section[1] || !sections[i].section[1])) @@ -468,10 +468,10 @@ secname(char* section) } if (!s) { - t = strcopy(t, "SECTION "); + t = stpcpy(t, "SECTION "); s = section; } - strcopy(t, s); + stpcpy(t, s); return b; } diff --git a/src/lib/libast/misc/optlib.h b/src/lib/libast/misc/optlib.h index a5f1dfd7d1ad..d2950c9ad400 100644 --- a/src/lib/libast/misc/optlib.h +++ b/src/lib/libast/misc/optlib.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * diff --git a/src/lib/libast/misc/signal.c b/src/lib/libast/misc/signal.c index 18b0e1c23892..bdb6abe5cdad 100644 --- a/src/lib/libast/misc/signal.c +++ b/src/lib/libast/misc/signal.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,7 +32,7 @@ Sig_handler_t signal(int sig, Sig_handler_t fun) { - struct sigaction na; + struct sigaction na = { .sa_handler = fun }; struct sigaction oa; int unblock; #ifdef SIGNO_MASK @@ -50,8 +50,6 @@ signal(int sig, Sig_handler_t fun) flags = sig & ~SIGNO_MASK; sig &= SIGNO_MASK; #endif - memzero(&na, sizeof(na)); - na.sa_handler = fun; #if defined(SA_INTERRUPT) || defined(SA_RESTART) switch (sig) { diff --git a/src/lib/libast/misc/vmalloc.c b/src/lib/libast/misc/vmalloc.c index c2d3884f1c52..95d52e31e705 100644 --- a/src/lib/libast/misc/vmalloc.c +++ b/src/lib/libast/misc/vmalloc.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This file is part of the ksh 93u+m package * -* Copyright (c) 2025 Contributors to ksh 93u+m * +* Copyright (c) 2025-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -10,6 +10,7 @@ * (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * * * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -28,11 +29,7 @@ typedef struct Vmblock size_t size; /* the size of the allocated block */ struct Vmblock *prev; /* previous block in list */ struct Vmblock *next; /* next block in list */ -#if __STDC_VERSION__ >= 199901L max_align_t vblock[]; /* the virtual allocated block, aligned */ -#else - max_align_t vblock[1]; /* ...C90 fallback with struct hack */ -#endif } Vmblock_t; #define VBLOCKOFFSET offsetof(Vmblock_t, vblock) diff --git a/src/lib/libast/port/mnt.c b/src/lib/libast/port/mnt.c index 4a0886bf9613..761a8eb7c4c5 100644 --- a/src/lib/libast/port/mnt.c +++ b/src/lib/libast/port/mnt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -114,7 +114,7 @@ set(Header_t* hp, const char* fs, const char* dir, const char* type, const char* flags = 0; SetErrorMode(mode); s = strcopy(hp->mnt.options = hp->opt, type); - s = strcopy(s, ",ignorecase"); + s = stpcpy(s, ",ignorecase"); if (options) { *s++ = ','; diff --git a/src/lib/libast/regex/regclass.c b/src/lib/libast/regex/regclass.c index 24c5ffd27d41..e885c68e4a9f 100644 --- a/src/lib/libast/regex/regclass.c +++ b/src/lib/libast/regex/regclass.c @@ -31,9 +31,7 @@ struct Ctype_s size_t size; regclass_t ctype; Ctype_t* next; -#if _lib_wctype wctype_t wtype; -#endif }; static Ctype_t* ctypes; @@ -44,24 +42,6 @@ static Ctype_t* ctypes; * and any local extensions that may not even have functions or macros */ -#if _need_iswblank - -int -_reg_iswblank(wint_t wc) -{ - static int initialized; - static wctype_t wt; - - if (!initialized) - { - initialized = 1; - wt = wctype("blank"); - } - return iswctype(wc, wt); -} - -#endif - static int Isalnum(int c) { return iswalnum(c); } static int Isalpha(int c) { return iswalpha(c); } static int Isblank(int c) { return iswblank(c); } @@ -86,8 +66,6 @@ static int Isword(int c) { return iswalnum(c) || c == '_'; } static int Notword(int c) { return !iswalnum(c) && c != '_'; } static int Isxdigit(int c) { return iswxdigit(c);} -#if _lib_wctype - static int Is_wc_1(int); static int Is_wc_2(int); static int Is_wc_3(int); @@ -105,9 +83,9 @@ static int Is_wc_14(int); static int Is_wc_15(int); static int Is_wc_16(int); -#endif - #define SZ(s) s,(sizeof(s)-1) +#define CTYPES 13 +#define WTYPES 16 static Ctype_t ctype[] = { @@ -124,10 +102,6 @@ static Ctype_t ctype[] = { SZ("upper"), Isupper }, { SZ("word"), Isword }, { SZ("xdigit"),Isxdigit}, - -#define CTYPES 13 - -#if _lib_wctype { 0, 0, Is_wc_1 }, { 0, 0, Is_wc_2 }, { 0, 0, Is_wc_3 }, @@ -144,18 +118,8 @@ static Ctype_t ctype[] = { 0, 0, Is_wc_14 }, { 0, 0, Is_wc_15 }, { 0, 0, Is_wc_16 }, - -#define WTYPES 16 - -#else - -#define WTYPES 0 - -#endif }; -#if _lib_wctype - static int Is_wc_1(int c) { return iswctype(c, ctype[CTYPES+0].wtype); } static int Is_wc_2(int c) { return iswctype(c, ctype[CTYPES+1].wtype); } static int Is_wc_3(int c) { return iswctype(c, ctype[CTYPES+2].wtype); } @@ -173,8 +137,6 @@ static int Is_wc_14(int c) { return iswctype(c, ctype[CTYPES+13].wtype); } static int Is_wc_15(int c) { return iswctype(c, ctype[CTYPES+14].wtype); } static int Is_wc_16(int c) { return iswctype(c, ctype[CTYPES+15].wtype); } -#endif - /* * return pointer to ctype function for :class:] in s * s points to the first char after the initial [ @@ -208,7 +170,6 @@ regclass(const char* s, char** e) lc = (Ctype_t*)setlocale(LC_CTYPE, NULL); for (cp = ctype; cp < &ctype[elementsof(ctype)]; cp++) { -#if _lib_wctype if (!zp) { if (!cp->size) @@ -216,11 +177,9 @@ regclass(const char* s, char** e) else if (!xp && cp->next && cp->next != lc) xp = cp; } -#endif if (n == cp->size && strneq(s, cp->name, n) && (!cp->next || cp->next == lc)) goto found; } -#if _lib_wctype if (!(cp = zp)) { if (!(cp = xp)) @@ -247,7 +206,6 @@ regclass(const char* s, char** e) } cp->size = n; cp->next = lc; -#endif found: if (e) *e = (char*)t + 2; diff --git a/src/lib/libast/regex/reglib.h b/src/lib/libast/regex/reglib.h index 53b29a9af871..d632ebd3bf19 100644 --- a/src/lib/libast/regex/reglib.h +++ b/src/lib/libast/regex/reglib.h @@ -182,7 +182,7 @@ typedef struct regsubop_s #define setclr(p,c) bitclr((p)->bits,c) #define settst(p,c) bittst((p)->bits,c) -#if _hdr_wchar && _lib_wctype && _lib_iswctype +#if _hdr_wchar #include /* because includes it and we generate it */ #include @@ -190,24 +190,8 @@ typedef struct regsubop_s #include #endif -#if !defined(iswblank) && !_lib_iswblank -#define _need_iswblank 1 -#define iswblank(x) _reg_iswblank(x) -extern int _reg_iswblank(wint_t); -#endif - -#if !defined(towupper) && !_lib_towupper -#define towupper(x) toupper(x) -#endif - -#if !defined(towlower) && !_lib_towlower -#define towlower(x) tolower(x) -#endif - #else -#undef _lib_wctype - #ifndef iswalnum #define iswalnum(x) isalnum(x) #endif diff --git a/src/lib/libast/regex/regnexec.c b/src/lib/libast/regex/regnexec.c index 8d6bbb7ef4fc..9709ae0e2f48 100644 --- a/src/lib/libast/regex/regnexec.c +++ b/src/lib/libast/regex/regnexec.c @@ -662,9 +662,6 @@ collmatch(Rex_t* rex, unsigned char* s, unsigned char* e, unsigned char** p) key[w] = 0; t = s; c = mbchar(t); -#if !_lib_wctype - c &= 0xff; -#endif x = 0; } else diff --git a/src/lib/libast/sfio/_sfopen.c b/src/lib/libast/sfio/_sfopen.c index 9b9847973fe8..9ac115855675 100644 --- a/src/lib/libast/sfio/_sfopen.c +++ b/src/lib/libast/sfio/_sfopen.c @@ -27,9 +27,9 @@ */ extern -Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ - const char* file, /* file/string to be opened */ - const char* mode) /* mode of the stream */ +Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ + const char *restrict file, /* file/string to be opened */ + const char *restrict mode) /* mode of the stream */ { int fd, oldfd, oflags, fflags; unsigned short sflags; diff --git a/src/lib/libast/sfio/sfdisc.c b/src/lib/libast/sfio/sfdisc.c index 281d07333e77..030dc7ffe641 100644 --- a/src/lib/libast/sfio/sfdisc.c +++ b/src/lib/libast/sfio/sfdisc.c @@ -149,7 +149,7 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) if((f->mode&SFIO_READ) && n > 0 && disc && disc->readf ) { if(!(dcca = (Dccache_t*)malloc(sizeof(Dccache_t)+(size_t)n)) ) goto done; - memclear(dcca, sizeof(Dccache_t)); + memset(dcca, 0, sizeof(Dccache_t)); dcca->disc.readf = _dccaread; dcca->disc.exceptf = _dccaexcept; diff --git a/src/lib/libast/sfio/sfhdr.h b/src/lib/libast/sfio/sfhdr.h index 589e499b5ce4..7614d93c59e7 100644 --- a/src/lib/libast/sfio/sfhdr.h +++ b/src/lib/libast/sfio/sfhdr.h @@ -51,20 +51,12 @@ /* AST always provides multibyte handling */ #undef _hdr_wchar -#undef _lib_mbrtowc -#undef _lib_wcrtomb #define _hdr_wchar 1 -#define _lib_mbrtowc 1 -#define _lib_wcrtomb 1 #if _mem_st_blksize_stat #define _stat_blksize 1 #endif -#if _lib_localeconv && _hdr_locale -#define _lib_locale 1 -#endif - #if !_mmap_worthy #undef MAP_TYPE #endif @@ -693,9 +685,6 @@ typedef struct _sftab_ #define min(x,y) ((x) < (y) ? (x) : (y)) #define max(x,y) ((x) > (y) ? (x) : (y)) -/* fast functions for memory copy and memory clear */ -#define memclear(s,n) memzero(s,n) - /* note that MEMCPY advances the associated pointers */ #define MEMCPY(to,fr,n) \ switch(n) \ diff --git a/src/lib/libast/sfio/sfopen.c b/src/lib/libast/sfio/sfopen.c index addf0f4e66b5..53ee0efd831e 100644 --- a/src/lib/libast/sfio/sfopen.c +++ b/src/lib/libast/sfio/sfopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ #include "sfhdr.h" @@ -22,11 +23,11 @@ * _sfopen() wrapper to allow user sfopen() intercept */ -extern Sfio_t* _sfopen(Sfio_t*, const char*, const char*); +extern Sfio_t* _sfopen(Sfio_t*, const char *restrict, const char *restrict); -Sfio_t* sfopen(Sfio_t* f, /* old stream structure */ - const char* file, /* file/string to be opened */ - const char* mode) /* mode of the stream */ +Sfio_t* sfopen(Sfio_t* f, /* old stream structure */ + const char *restrict file, /* file/string to be opened */ + const char *restrict mode) /* mode of the stream */ { return _sfopen(f, file, mode); } diff --git a/src/lib/libast/sfio/sfpopen.c b/src/lib/libast/sfio/sfpopen.c index 4bbdcbb301f8..c551cc146214 100644 --- a/src/lib/libast/sfio/sfpopen.c +++ b/src/lib/libast/sfio/sfpopen.c @@ -25,9 +25,9 @@ #include -Sfio_t* sfpopen(Sfio_t* f, - const char* command, /* command to execute */ - const char* mode) /* mode of the stream */ +Sfio_t* sfpopen(Sfio_t* f, + const char *restrict command, /* command to execute */ + const char *restrict mode) /* mode of the stream */ { Proc_t* proc; unsigned short sflags; diff --git a/src/lib/libast/sfio/sfprintf.c b/src/lib/libast/sfio/sfprintf.c index e638a6277028..11cf2b7091ff 100644 --- a/src/lib/libast/sfio/sfprintf.c +++ b/src/lib/libast/sfio/sfprintf.c @@ -34,7 +34,7 @@ ssize_t sfprintf(Sfio_t* f, const char* form, ...) return rv; } -ssize_t sfvsprintf(char* s, size_t n, const char* form, va_list args) +ssize_t sfvsprintf(char *restrict s, size_t n, const char *restrict form, va_list args) { Sfio_t *f; ssize_t rv; @@ -65,7 +65,7 @@ ssize_t sfvsprintf(char* s, size_t n, const char* form, va_list args) return rv; } -ssize_t sfsprintf(char* s, size_t n, const char* form, ...) +ssize_t sfsprintf(char *restrict s, size_t n, const char *restrict form, ...) { va_list args; ssize_t rv; diff --git a/src/lib/libast/sfio/sfprints.c b/src/lib/libast/sfio/sfprints.c index f1bc9fb76089..e1bf2de07491 100644 --- a/src/lib/libast/sfio/sfprints.c +++ b/src/lib/libast/sfio/sfprints.c @@ -60,7 +60,7 @@ char* sfprints(const char* form, ...) return s; } -ssize_t sfvaprints(char** sp, const char* form, va_list args) +ssize_t sfvaprints(char **restrict sp, const char *restrict form, va_list args) { char *s; size_t n; @@ -75,7 +75,7 @@ ssize_t sfvaprints(char** sp, const char* form, va_list args) } } -ssize_t sfaprints(char** sp, const char* form, ...) +ssize_t sfaprints(char **restrict sp, const char *restrict form, ...) { ssize_t n; va_list args; diff --git a/src/lib/libast/sfio/sfresize.c b/src/lib/libast/sfio/sfresize.c index 3718e746faca..b336924afed4 100644 --- a/src/lib/libast/sfio/sfresize.c +++ b/src/lib/libast/sfio/sfresize.c @@ -45,12 +45,12 @@ int sfresize(Sfio_t* f, Sfoff_t size) f->extent = (ssize_t)s; } } - memclear((char*)(f->data+size), (size_t)(f->extent-size)); + memset((char*)(f->data+size), 0, (size_t)(f->extent-size)); } else { if(SFSK(f, size, SEEK_SET, f->disc) != size) return -1; - memclear((char*)(f->data+f->extent), (size_t)(size-f->extent)); + memset((char*)(f->data+f->extent), 0, (size_t)(size-f->extent)); } } else diff --git a/src/lib/libast/sfio/sfscanf.c b/src/lib/libast/sfio/sfscanf.c index 3ff2253f7844..9c8761092df5 100644 --- a/src/lib/libast/sfio/sfscanf.c +++ b/src/lib/libast/sfio/sfscanf.c @@ -34,7 +34,7 @@ int sfscanf(Sfio_t* f, const char* form, ...) return rv; } -int sfvsscanf(const char* s, const char* form, va_list args) +int sfvsscanf(const char *restrict s, const char *restrict form, va_list args) { Sfio_t f; @@ -53,7 +53,7 @@ int sfvsscanf(const char* s, const char* form, va_list args) return sfvscanf(&f,form,args); } -int sfsscanf(const char* s, const char* form,...) +int sfsscanf(const char *restrict s, const char *restrict form,...) { va_list args; int rv; diff --git a/src/lib/libast/sfio/sfseek.c b/src/lib/libast/sfio/sfseek.c index 8c2a530f0746..86bcf52fda27 100644 --- a/src/lib/libast/sfio/sfseek.c +++ b/src/lib/libast/sfio/sfseek.c @@ -112,7 +112,7 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ f->next = f->data ? f->data + p : NULL; f->here = p; if(p > f->extent) - memclear((char*)(f->data+f->extent),(size_t)(p-f->extent)); + memset((char*)(f->data+f->extent),0,(size_t)(p-f->extent)); goto done; } diff --git a/src/lib/libast/sfio/sfstrtod.c b/src/lib/libast/sfio/sfstrtod.c index 63f5ec278137..70c55ede2d1f 100644 --- a/src/lib/libast/sfio/sfstrtod.c +++ b/src/lib/libast/sfio/sfstrtod.c @@ -64,13 +64,9 @@ Sfdouble_t _sfstrtod(const char* s, /* string to convert */ int n, c, m; int mode, fexp, sign, expsign; Sfdouble_t dval; -#if _lib_locale int decpoint = 0; int thousand = 0; SFSETLOCALE(&decpoint,&thousand); -#else -#define decpoint '.' -#endif /* skip initial blanks */ while(isspace(*s)) diff --git a/src/lib/libast/std/assert.h b/src/lib/libast/std/assert.h index 5715b49483e7..b5018742d803 100644 --- a/src/lib/libast/std/assert.h +++ b/src/lib/libast/std/assert.h @@ -1,7 +1,7 @@ /*********************************************************************** * * * This file is part of the ksh 93u+m package * -* Copyright (c) 2024 Contributors to ksh 93u+m * +* Copyright (c) 2024-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -10,12 +10,13 @@ * (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * * * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* * Since native OS assert.h headers often don't play well with libast, - * here is a simple AST implementation of assert.h as defined in C90. + * here is a simple AST implementation of assert.h as defined in C99. * It may be included more than once with or without NDEBUG defined. * * In addition, static_assert is defined as the C11 keyword @@ -28,17 +29,13 @@ #undef assert #ifdef NDEBUG # define assert(e) ((void)0) -#elif _has___func__ -# define assert(e) ((e) ? (void)0 : _ast_assertfail(#e, __func__, __FILE__, __LINE__)) -#elif _has___FUNCTION__ -# define assert(e) ((e) ? (void)0 : _ast_assertfail(#e, __FUNCTION__, __FILE__, __LINE__)) #else -# define assert(e) ((e) ? (void)0 : _ast_assertfail(#e, NULL, __FILE__, __LINE__)) +# define assert(e) ((e) ? (void)0 : _ast_assertfail(#e, __func__, __FILE__, __LINE__)) #endif #ifndef _ASSERT_H # define _ASSERT_H -extern void _ast_assertfail(const char*, const char*, const char*, int); +extern void _ast_assertfail(const char *restrict, const char *restrict, const char *restrict, int); # if _has__Static_assert && !defined(static_assert) # define static_assert _Static_assert # endif diff --git a/src/lib/libast/stdio/stdio.c b/src/lib/libast/stdio/stdio.c index 9450153c7817..a1612b1a4ac1 100644 --- a/src/lib/libast/stdio/stdio.c +++ b/src/lib/libast/stdio/stdio.c @@ -39,7 +39,7 @@ _filbuf(Sfio_t* f) } int -asprintf(char** s, const char* fmt, ...) +asprintf(char **restrict s, const char *restrict fmt, ...) { va_list args; int v; @@ -86,7 +86,7 @@ fgetpos(Sfio_t* f, fpos_t* pos) } Sfio_t* -fopen(const char* path, const char* mode) +fopen(const char *restrict path, const char *restrict mode) { return sfopen(NULL, path, mode); } @@ -131,7 +131,7 @@ fread(void* p, size_t s, size_t n, Sfio_t* f) } Sfio_t* -freopen(const char* path, const char* mode, Sfio_t* f) +freopen(const char *restrict path, const char *restrict mode, Sfio_t* f) { return sfopen(f, path, mode); } @@ -296,7 +296,7 @@ setvbuf(Sfio_t* f, char* buf, int type, size_t size) } int -snprintf(char* s, size_t n, const char* fmt, ...) +snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) { va_list args; int v; @@ -308,7 +308,7 @@ snprintf(char* s, size_t n, const char* fmt, ...) } int -sprintf(char* s, const char* fmt, ...) +sprintf(char *restrict s, const char *restrict fmt, ...) { va_list args; int v; @@ -321,7 +321,7 @@ sprintf(char* s, const char* fmt, ...) int -sscanf(const char* s, const char* fmt, ...) +sscanf(const char *restrict s, const char *restrict fmt, ...) { va_list args; int v; @@ -345,7 +345,7 @@ ungetc(int c, Sfio_t* f) } int -vasprintf(char** s, const char* fmt, va_list args) +vasprintf(char **restrict s, const char *restrict fmt, va_list args) { Sfio_t* f; int v; @@ -390,7 +390,7 @@ vscanf(const char* fmt, va_list args) } int -vsnprintf(char* s, size_t n, const char* form, va_list args) +vsnprintf(char *restrict s, size_t n, const char *restrict form, va_list args) { Sfio_t* f; int rv; @@ -418,13 +418,13 @@ vsnprintf(char* s, size_t n, const char* form, va_list args) } int -vsprintf(char* s, const char* fmt, va_list args) +vsprintf(char *restrict s, const char *restrict fmt, va_list args) { return vsnprintf(s, 4 * SFIO_BUFSIZE, fmt, args); } int -vsscanf(const char* s, const char* fmt, va_list args) +vsscanf(const char *restrict s, const char *restrict fmt, va_list args) { return sfvsscanf(s, fmt, args); } diff --git a/src/lib/libast/stdio/stdio_mb.c b/src/lib/libast/stdio/stdio_mb.c index 01386e301d0d..ccd7648db91e 100644 --- a/src/lib/libast/stdio/stdio_mb.c +++ b/src/lib/libast/stdio/stdio_mb.c @@ -158,7 +158,7 @@ putwchar(wchar_t c) } int -swprintf(wchar_t* s, size_t size, const wchar_t* fmt, ...) +swprintf(wchar_t *restrict s, size_t size, const wchar_t *restrict fmt, ...) { va_list args; int v; @@ -170,7 +170,7 @@ swprintf(wchar_t* s, size_t size, const wchar_t* fmt, ...) } int -swscanf(const wchar_t* s, const wchar_t* fmt, ...) +swscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, ...) { va_list args; int v; @@ -327,7 +327,7 @@ vfwscanf(Sfio_t* f, const wchar_t* fmt, va_list args) } int -vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) +vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list args) { Sfio_t f; int v; @@ -358,7 +358,7 @@ vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) } int -vswscanf(const wchar_t* s, const wchar_t* fmt, va_list args) +vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list args) { Sfio_t f; diff --git a/src/lib/libast/comp/wordexp.h b/src/lib/libast/string/stpcpy.c similarity index 50% rename from src/lib/libast/comp/wordexp.h rename to src/lib/libast/string/stpcpy.c index 44d0b9ffbc95..257f43b7ae0e 100644 --- a/src/lib/libast/comp/wordexp.h +++ b/src/lib/libast/string/stpcpy.c @@ -1,8 +1,8 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 1985-2013 AT&T Intellectual Property * +* Copyright (c) 2025-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -10,45 +10,39 @@ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * * (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * * * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * +* Glenn Fowler * +* David Korn * +* Phong Vo * * Johnothan King * * * ***********************************************************************/ /* - * POSIX wordexp interface definitions + * stpcpy implementation */ -#ifndef _WORDEXP_H -#define _WORDEXP_H +#include -#include +#undef _def_map_ast +#include -#define WRDE_APPEND 01 -#define WRDE_DOOFFS 02 -#define WRDE_NOCMD 04 -#define WRDE_NOSYS 0100 -#define WRDE_REUSE 010 -#define WRDE_SHOWERR 020 -#define WRDE_UNDEF 040 +#if _lib_stpcpy -#define WRDE_BADCHAR 1 -#define WRDE_BADVAL 2 -#define WRDE_CMDSUB 3 -#define WRDE_NOSPACE 4 -#define WRDE_SYNTAX 5 -#define WRDE_NOSHELL 6 +NoN(stpcpy) -typedef struct _wdarg -{ - size_t we_wordc; - char **we_wordv; - size_t we_offs; -} wordexp_t; +#else -extern int wordexp(const char*, wordexp_t*, int); -extern int wordfree(wordexp_t*); +/* + * copy f into t, return a pointer to the end of t ('\0') + * the buffers cannot overlap + */ + +extern char* +stpcpy(char *restrict t, const char *restrict f) +{ + if (!f) + return t; + while (*t++ = *f++); + return t - 1; +} -#endif /* _WORDEXP_H */ +#endif diff --git a/src/lib/libast/string/strcopy.c b/src/lib/libast/string/strcopy.c index 02b19024f571..a97704d3b966 100644 --- a/src/lib/libast/string/strcopy.c +++ b/src/lib/libast/string/strcopy.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -21,6 +22,7 @@ /* * copy t into s, return a pointer to the end of s ('\0') + * overlapping buffers are permitted */ char* diff --git a/src/lib/libast/string/strlcat.c b/src/lib/libast/string/strlcat.c index aaac16c5ac30..aa7fb8741723 100644 --- a/src/lib/libast/string/strlcat.c +++ b/src/lib/libast/string/strlcat.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -39,7 +39,7 @@ NoN(strlcat) */ extern size_t -strlcat(char* s, const char* t, size_t n) +strlcat(char *restrict s, const char *restrict t, size_t n) { size_t m; const char* o = t; diff --git a/src/lib/libast/string/strlcpy.c b/src/lib/libast/string/strlcpy.c index 0aab4a77acd9..33a960c188cf 100644 --- a/src/lib/libast/string/strlcpy.c +++ b/src/lib/libast/string/strlcpy.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -39,7 +39,7 @@ NoN(strlcpy) */ extern size_t -strlcpy(char* s, const char* t, size_t n) +strlcpy(char *restrict s, const char *restrict t, size_t n) { const char* o = t; diff --git a/src/lib/libast/string/strncopy.c b/src/lib/libast/string/strncopy.c index 13ffbc847558..e5e9e76d48e2 100644 --- a/src/lib/libast/string/strncopy.c +++ b/src/lib/libast/string/strncopy.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ @@ -23,6 +24,7 @@ * copy up to n bytes of string f into t * trailing 0 always added to t, even if n==0 * pointer to the copied 0 returned + * overlapping buffers are permitted */ char* diff --git a/src/lib/libast/string/strntoll.c b/src/lib/libast/string/strntoll.c index 3b5dbc92a484..d0cfb34c165b 100644 --- a/src/lib/libast/string/strntoll.c +++ b/src/lib/libast/string/strntoll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -21,8 +22,8 @@ */ #define S2I_function strntoll -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long #define S2I_size 1 #include "strtoi.h" diff --git a/src/lib/libast/string/strntonll.c b/src/lib/libast/string/strntonll.c index 2e144e20e84e..10de978db30a 100644 --- a/src/lib/libast/string/strntonll.c +++ b/src/lib/libast/string/strntonll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -21,8 +22,8 @@ */ #define S2I_function strntonll -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long #define S2I_multiplier 1 #define S2I_size 1 diff --git a/src/lib/libast/string/strntoull.c b/src/lib/libast/string/strntoull.c index aed8c493f0de..36f2c75839ea 100644 --- a/src/lib/libast/string/strntoull.c +++ b/src/lib/libast/string/strntoull.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -21,8 +22,8 @@ */ #define S2I_function strntoull -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long #define S2I_size 1 #define S2I_unsigned 1 diff --git a/src/lib/libast/string/strtonll.c b/src/lib/libast/string/strtonll.c index 59df7b1547e2..a5fb351d9b01 100644 --- a/src/lib/libast/string/strtonll.c +++ b/src/lib/libast/string/strtonll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -21,8 +22,8 @@ */ #define S2I_function strtonll -#define S2I_number intmax_t -#define S2I_unumber uintmax_t +#define S2I_number long long +#define S2I_unumber unsigned long long #define S2I_multiplier 1 #include "strtoi.h" diff --git a/src/lib/libast/tm/tmfmt.c b/src/lib/libast/tm/tmfmt.c index c935f0c74c52..7d6a78b58db1 100644 --- a/src/lib/libast/tm/tmfmt.c +++ b/src/lib/libast/tm/tmfmt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -14,6 +14,7 @@ * David Korn * * Phong Vo * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -31,7 +32,7 @@ */ char* -tmfmt(char* buf, size_t len, const char* format, time_t* clock) +tmfmt(char *restrict buf, size_t len, const char *restrict format, time_t* clock) { return tmxfmt(buf, len, format, tmxclock(clock)); } diff --git a/src/lib/libast/tm/tmxfmt.c b/src/lib/libast/tm/tmxfmt.c index 873d2aafae63..be9ce0466710 100644 --- a/src/lib/libast/tm/tmxfmt.c +++ b/src/lib/libast/tm/tmxfmt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2024 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -93,7 +93,7 @@ typedef struct Stack_s */ char* -tmxfmt(char* buf, size_t len, const char* format, Time_t t) +tmxfmt(char *restrict buf, size_t len, const char *restrict format, Time_t t) { char* cp; char* ep; diff --git a/src/lib/libcmd/Mamfile b/src/lib/libcmd/Mamfile index e3cec66106ee..1fc6c43ff8f7 100644 --- a/src/lib/libcmd/Mamfile +++ b/src/lib/libcmd/Mamfile @@ -6,7 +6,7 @@ note * setv MAMAKE_STRICT 5 setv INSTALLROOT ../../.. setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_NOSTRICTALIASING} -DERROR_CATALOG=\""libcmd"\" -DHOSTTYPE=\""%{mam_cc_HOSTTYPE}"\" -D_BLD_cmd +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} -DERROR_CATALOG=\""libcmd"\" -DHOSTTYPE=\""%{mam_cc_HOSTTYPE}"\" -D_BLD_cmd setv CCFLAGS setv IFFEFLAGS setv LDFLAGS diff --git a/src/lib/libcmd/cksum.c b/src/lib/libcmd/cksum.c index afbfcc0a1b48..796df56d6a35 100644 --- a/src/lib/libcmd/cksum.c +++ b/src/lib/libcmd/cksum.c @@ -451,13 +451,13 @@ b_cksum(int argc, char** argv, Shbltin_t* context) FTSENT* ent; int logical; Optdisc_t optdisc; - State_t state; + State_t state = { + .flags = SUM_SIZE, + .warn = 1 + }; cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY); - memset(&state, 0, sizeof(state)); flags = fts_flags() | FTS_META | FTS_TOP | FTS_NOPOSTORDER; - state.flags = SUM_SIZE; - state.warn = 1; logical = 1; method = 0; optinit(&optdisc, optinfo); diff --git a/src/lib/libcmd/cmd.h b/src/lib/libcmd/cmd.h index 311e25b622b6..5352604718a3 100644 --- a/src/lib/libcmd/cmd.h +++ b/src/lib/libcmd/cmd.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -13,6 +13,7 @@ * Glenn Fowler * * David Korn * * Martijn Dekker * +* Johnothan King * * * ***********************************************************************/ /* @@ -100,8 +101,7 @@ main(int argc, char** argv) buf[0] = '_'; buf[1] = 'b'; buf[2] = '_'; - strncpy(buf + 3, s, sizeof(buf) - 4); - buf[sizeof(buf) - 1] = 0; + strlcpy(buf + 3, s, sizeof(buf) - 3); if (t = strchr(buf, '.')) *t = 0; for (;;) diff --git a/src/lib/libcmd/date.c b/src/lib/libcmd/date.c index 1acbec5dab89..517c2612e005 100644 --- a/src/lib/libcmd/date.c +++ b/src/lib/libcmd/date.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -24,7 +24,7 @@ */ static const char usage[] = -"[-?\n@(#)$Id: date (AT&T Research) 2011-01-27 $\n]" +"[-?\n@(#)$Id: date (ksh 93u+m) 2026-03-11 $\n]" "[--catalog?" ERROR_CATALOG "]" "[+NAME?date - set/list/convert dates]" "[+DESCRIPTION?\bdate\b sets the current date and time (with appropriate" @@ -157,7 +157,7 @@ static const char usage[] = " after the AST library release date are not accounted for.]" "[m:modify-time|mtime?List file argument modify times.]" "[n!:network?Set network time.]" -"[p:parse?Add \aformat\a to the list of \bstrptime\b(3) parse conversion" +"[p:parse?Add \aformat\a to the list of \bstrftime\b(3) parse conversion" " formats. \aformat\a follows the same conventions as the" " \b--format\b option, with the addition of these format" " fields:]:[format]{" @@ -189,7 +189,7 @@ static const char usage[] = "\n" "[+SEE ALSO?\bcrontab\b(1), \bls\b(1), \btouch\b(1), \bfmtelapsed\b(3)," -" \bstrftime\b(3), \bstrptime\b(3), \btm\b(3)]" +" \bstrftime\b(3), \btm\b(3)]" ; #include diff --git a/src/lib/libcmd/features/utsname b/src/lib/libcmd/features/utsname index a17e90e0d5b9..dc34d46c9199 100644 --- a/src/lib/libcmd/features/utsname +++ b/src/lib/libcmd/features/utsname @@ -1,7 +1,6 @@ lib getdomainname,gethostid,gethostname,sethostname,syscall,systeminfo,uname -lib syssgi mem utsname.base_rel,utsname.idnumber,utsname.m_type,utsname.nodeext sys/utsname.h -sys syscall,systeminfo,syssgi +sys syscall,systeminfo tst cross{ u=$(p=$(getconf PATH 2>/dev/null) && PATH=$p; uname -o 2>/dev/null) diff --git a/src/lib/libcmd/join.c b/src/lib/libcmd/join.c index f98b99cb86de..cc957a082a7b 100644 --- a/src/lib/libcmd/join.c +++ b/src/lib/libcmd/join.c @@ -90,7 +90,7 @@ static const char usage[] = #include #include -#if _hdr_wchar && _hdr_wctype && _lib_iswctype +#if _hdr_wchar && _hdr_wctype #include #include diff --git a/src/lib/libcmd/stty.c b/src/lib/libcmd/stty.c index 83699631e6ea..84a2bab6650e 100644 --- a/src/lib/libcmd/stty.c +++ b/src/lib/libcmd/stty.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -921,12 +921,12 @@ b_stty(int argc, char** argv, Shbltin_t* context) int flags = 0; int fd = 0; const Tty_t* tp; - Optdisc_t disc; + Optdisc_t disc = { + .version = OPT_VERSION, + .infof = infof + }; cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_INTERACTIVE); - memset(&disc, 0, sizeof(disc)); - disc.version = OPT_VERSION; - disc.infof = infof; opt_info.disc = &disc; for (;;) { diff --git a/src/lib/libcmd/uname.c b/src/lib/libcmd/uname.c index f16a10608e6e..84c6c585e5fe 100644 --- a/src/lib/libcmd/uname.c +++ b/src/lib/libcmd/uname.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -123,7 +123,7 @@ uname(struct utsname* ut) if (gethostname(ut->nodename, sizeof(ut->nodename) - 1)) return -1; #else - strncpy(ut->nodename, "local", sizeof(ut->nodename) - 1); + strlcpy(ut->nodename, "local", sizeof(ut->nodename)); #endif #ifdef HOSTTYPE if (!(ut->sysname = sys)) @@ -330,7 +330,7 @@ b_uname(int argc, char** argv, Shbltin_t* context) s = buf; if (!flags) flags = OPT_system; - memzero(&ut, sizeof(ut)); + memset(&ut, 0, sizeof(ut)); if (uname(&ut) < 0) { error(ERROR_usage(2), "information unavailable"); @@ -405,7 +405,7 @@ b_uname(int argc, char** argv, Shbltin_t* context) t++; else t = (char*)hosttype; - strncpy(s = buf, t, sizeof(buf) - 1); + strlcpy(s = buf, t, sizeof(buf)); } output(OPT_implementation, s, "implementation"); } diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index ea5996b791ee..de3c865f5a57 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -27,7 +27,7 @@ #include #include -#if _hdr_wchar && _hdr_wctype && _lib_iswctype +#if _hdr_wchar && _hdr_wctype #include #include @@ -59,7 +59,7 @@ Wc_t* wc_init(int mode) return NULL; if (!mbwide()) wp->mb = 0; -#if _hdr_wchar && _hdr_wctype && _lib_iswctype +#if _hdr_wchar && _hdr_wctype else if (!(mode & WC_NOUTF8) && (ast.locale.set & AST_LC_utf8)) wp->mb = 1; #endif diff --git a/src/lib/libdll/Mamfile b/src/lib/libdll/Mamfile index 58bc5ff08dbf..f46c01e9b266 100644 --- a/src/lib/libdll/Mamfile +++ b/src/lib/libdll/Mamfile @@ -6,7 +6,7 @@ note * setv MAMAKE_STRICT 5 setv INSTALLROOT ../../.. setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} setv CCFLAGS setv IFFEFLAGS setv LDFLAGS diff --git a/src/lib/libsum/Mamfile b/src/lib/libsum/Mamfile index 3bd616ba4591..7a09ff5d8b8f 100644 --- a/src/lib/libsum/Mamfile +++ b/src/lib/libsum/Mamfile @@ -6,7 +6,7 @@ note * setv MAMAKE_STRICT 5 setv INSTALLROOT ../../.. setv CC cc -setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{mam_cc_PIC} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} +setv mam_cc_FLAGS %{mam_cc_TARGET} %{mam_cc_DLL} %{mam_cc_PIC} %{-debug-symbols?1?%{mam_cc_DEBUG} -D_BLD_DEBUG?%{mam_cc_OPTIMIZE}?} %{mam_cc_STDC} setv CCFLAGS setv IFFEFLAGS setv LDFLAGS diff --git a/src/lib/libsum/sum-sha2.c b/src/lib/libsum/sum-sha2.c index f3e39a327f75..90b97063422f 100644 --- a/src/lib/libsum/sum-sha2.c +++ b/src/lib/libsum/sum-sha2.c @@ -132,35 +132,6 @@ typedef uint64_t sha2_word64; /* Exactly 8 bytes */ } \ } -/* - * Macros for copying blocks of memory and for zeroing out ranges - * of memory. Using these macros makes it easy to switch from - * using memset()/memcpy() and using bzero()/bcopy(). - * - * Please define either SHA2_USE_MEMSET_MEMCPY or define - * SHA2_USE_BZERO_BCOPY depending on which function set you - * choose to use: - */ - -#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY) -/* Default to memset()/memcpy() if no option is specified */ -#define SHA2_USE_MEMSET_MEMCPY 1 -#endif -#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY) -/* Abort with an error if BOTH options are defined */ -#error Define either SHA2_USE_MEMSET_MEMCPY or SHA2_USE_BZERO_BCOPY, not both! -#endif - -#ifdef SHA2_USE_MEMSET_MEMCPY -#define MEMSET_BZERO(p,l) memset((p), 0, (l)) -#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l)) -#endif -#ifdef SHA2_USE_BZERO_BCOPY -#define MEMSET_BZERO(p,l) bzero((p), (l)) -#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l)) -#endif - - /*** THE SIX LOGICAL FUNCTIONS ****************************************/ /* * Bit shifting and rotation (used by the six SHA-XYZ logical functions: @@ -576,14 +547,14 @@ sha256_block(Sum_t* p, const void* s, size_t len) if (len >= freespace) { /* Fill the buffer completely and process it */ - MEMCPY_BCOPY(&sha->buffer[usedspace], data, freespace); + memcpy(&sha->buffer[usedspace], data, freespace); sha->bitcount += freespace << 3; len -= freespace; data += freespace; SHA256_Transform(sha, (sha2_word32*)sha->buffer); } else { /* The buffer is not yet full */ - MEMCPY_BCOPY(&sha->buffer[usedspace], data, len); + memcpy(&sha->buffer[usedspace], data, len); sha->bitcount += len << 3; /* Clean up: */ usedspace = freespace = 0; @@ -599,7 +570,7 @@ sha256_block(Sum_t* p, const void* s, size_t len) } if (len > 0) { /* There's leftovers, so save 'em */ - MEMCPY_BCOPY(sha->buffer, data, len); + memcpy(sha->buffer, data, len); sha->bitcount += len << 3; } /* Clean up: */ @@ -613,8 +584,8 @@ sha256_init(Sum_t* p) { Sha256_t* sha = (Sha256_t*)p; - MEMCPY_BCOPY(sha->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH); - MEMSET_BZERO(sha->buffer, SHA256_BLOCK_LENGTH); + memcpy(sha->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH); + memset(sha->buffer, 0, SHA256_BLOCK_LENGTH); sha->bitcount = 0; return 0; @@ -655,26 +626,26 @@ sha256_done(Sum_t* p) if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ - MEMSET_BZERO(&sha->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace); + memset(&sha->buffer[usedspace], 0, SHA256_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA256_BLOCK_LENGTH) { - MEMSET_BZERO(&sha->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace); + memset(&sha->buffer[usedspace], 0, SHA256_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ SHA256_Transform(sha, (sha2_word32*)sha->buffer); /* And set-up for the last transform: */ - MEMSET_BZERO(sha->buffer, SHA256_SHORT_BLOCK_LENGTH); + memset(sha->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); } } else { /* Set-up for the last transform: */ - MEMSET_BZERO(sha->buffer, SHA256_SHORT_BLOCK_LENGTH); + memset(sha->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *sha->buffer = 0x80; } /* Store the length of input data (in bits): */ - MEMCPY_BCOPY(&sha->buffer[SHA256_SHORT_BLOCK_LENGTH], &sha->bitcount, 8); + memcpy(&sha->buffer[SHA256_SHORT_BLOCK_LENGTH], &sha->bitcount, 8); /* Final transform: */ SHA256_Transform(sha, (sha2_word32*)sha->buffer); @@ -690,7 +661,7 @@ sha256_done(Sum_t* p) } } #else - MEMCPY_BCOPY(sha->digest, sha->state, SHA256_DIGEST_LENGTH); + memcpy(sha->digest, sha->state, SHA256_DIGEST_LENGTH); #endif /* accumulate the digests */ @@ -698,7 +669,7 @@ sha256_done(Sum_t* p) sha->digest_sum[i] ^= sha->digest[i]; /* Clean up state data: */ - MEMSET_BZERO(&sha->state, sizeof(*sha) - offsetof(Sha256_t, state)); + memset(&sha->state, 0, sizeof(*sha) - offsetof(Sha256_t, state)); usedspace = 0; return 0; @@ -940,14 +911,14 @@ sha512_block(Sum_t* p, const void* s, size_t len) if (len >= freespace) { /* Fill the buffer completely and process it */ - MEMCPY_BCOPY(&sha->buffer[usedspace], data, freespace); + memcpy(&sha->buffer[usedspace], data, freespace); ADDINC128(sha->bitcount, freespace << 3); len -= freespace; data += freespace; SHA512_Transform(sha, (sha2_word64*)sha->buffer); } else { /* The buffer is not yet full */ - MEMCPY_BCOPY(&sha->buffer[usedspace], data, len); + memcpy(&sha->buffer[usedspace], data, len); ADDINC128(sha->bitcount, len << 3); /* Clean up: */ usedspace = freespace = 0; @@ -963,7 +934,7 @@ sha512_block(Sum_t* p, const void* s, size_t len) } if (len > 0) { /* There's leftovers, so save 'em */ - MEMCPY_BCOPY(sha->buffer, data, len); + memcpy(sha->buffer, data, len); ADDINC128(sha->bitcount, len << 3); } /* Clean up: */ @@ -977,8 +948,8 @@ sha512_init(Sum_t* p) { Sha512_t* sha = (Sha512_t*)p; - MEMCPY_BCOPY(sha->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH); - MEMSET_BZERO(sha->buffer, SHA512_BLOCK_LENGTH); + memcpy(sha->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH); + memset(sha->buffer, 0, SHA512_BLOCK_LENGTH); sha->bitcount[0] = sha->bitcount[1] = 0; return 0; @@ -1017,26 +988,26 @@ sha512_done(Sum_t* p) if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ - MEMSET_BZERO(&sha->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace); + memset(&sha->buffer[usedspace], 0, SHA512_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA512_BLOCK_LENGTH) { - MEMSET_BZERO(&sha->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace); + memset(&sha->buffer[usedspace], 0, SHA512_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ SHA512_Transform(sha, (sha2_word64*)sha->buffer); /* And set-up for the last transform: */ - MEMSET_BZERO(sha->buffer, SHA512_BLOCK_LENGTH - 2); + memset(sha->buffer, 0, SHA512_BLOCK_LENGTH - 2); } } else { /* Prepare for final transform: */ - MEMSET_BZERO(sha->buffer, SHA512_SHORT_BLOCK_LENGTH); + memset(sha->buffer, 0, SHA512_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *sha->buffer = 0x80; } /* Store the length of input data (in bits): */ - MEMCPY_BCOPY(&sha->buffer[SHA512_SHORT_BLOCK_LENGTH], &sha->bitcount[0], 16); + memcpy(&sha->buffer[SHA512_SHORT_BLOCK_LENGTH], &sha->bitcount[0], 16); /* Final transform: */ SHA512_Transform(sha, (sha2_word64*)sha->buffer); @@ -1052,7 +1023,7 @@ sha512_done(Sum_t* p) } } #else - MEMCPY_BCOPY(sha->digest, sha->state, SHA512_DIGEST_LENGTH); + memcpy(sha->digest, sha->state, SHA512_DIGEST_LENGTH); #endif /* accumulate the digests */ @@ -1060,7 +1031,7 @@ sha512_done(Sum_t* p) sha->digest_sum[i] ^= sha->digest[i]; /* Clean up state data: */ - MEMSET_BZERO(&sha->state, sizeof(*sha) - offsetof(Sha512_t, state)); + memset(&sha->state, 0, sizeof(*sha) - offsetof(Sha512_t, state)); usedspace = 0; return 0; @@ -1115,8 +1086,8 @@ sha384_init(Sum_t* p) { Sha384_t* sha = (Sha384_t*)p; - MEMCPY_BCOPY(sha->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH); - MEMSET_BZERO(sha->buffer, SHA384_BLOCK_LENGTH); + memcpy(sha->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH); + memset(sha->buffer, 0, SHA384_BLOCK_LENGTH); sha->bitcount[0] = sha->bitcount[1] = 0; return 0;