Skip to content

Commit 82d151e

Browse files
committed
Require C99
This commit is a compilation of many old patches of mine. It removes obsolete code and enforces C99 as a build requirement. Changes: - Remove many unused tests and useless feature tests. (This was a bit more involved for <sys/types.h>, which had annoying special casing.) This included the 'check for global headers' in the iffe script. - Assume fchmod is present and use it instead of chmod in shcomp for slightly better performance. - dotpaths_lib(): Use fstat rather than stat for the PWD for better performance. - Scrap pre-C99 fallbacks for iswblank(3). - Replaced usage of the obsolescent timeofday() macro with the more portable tvgettime() function in libast, which itself uses the modern clock_gettime internally. - Replaced usage of strcopy with either strcpy or stpcpy in cases where no buffer overlap occurs. There are perhaps more places where replacement is possible (ksh93v- and ksh2020 do this far more liberally), but I'm trying to be conservative with these changes to avoid accidentally introducing bugs. - Replaced an instance of strncopy with strlcpy in keytrap() because the buffers don't overlap. - Also replaced some instances of strncpy with strlcpy (vide att#266 and f63ebd0). - Add pertinent documentation as it relates to str*copy's usage with overlapping buffers. - Backported a modified version of ksh93v-'s stpcpy fallback. - Introduced usage of C99 restrict, primarily for standards compliance in compatibility functions (though some regular functions like sfopen() do also use restrict now). - Assume C99 __func__ is available and drop now unneeded C90 feature tests. - Added a few casts to fix some compiler warnings. - Remove basic iffe probes for various C99 multibyte functions (excluding those that still need tests due to platform-specific bugs). Also removed other unnecessary probes for C99 and POSIX functionality. - Remove unnecessary mktime.c, wc.c and wordexp.c compat files (the operating system should provide these functions). - Switched to using C99-style struct init throughout the codebase. - Removed usage of bzero, bcopy, memclear and memzero in favor of ISO C memset and memcpy. - make.probe: Automatically use the latest C standard available (i.e. C23) because GCC/Clang may use something older by default whilst having support for newer standards. I have additional changes for using C99-style for loops and bools, but those have been excluded because this patch is big enough as it is. Progresses #777 (This commit doesn't include or fix the removed _c99_in_the_wild code.)
1 parent 8d24508 commit 82d151e

129 files changed

Lines changed: 641 additions & 1680 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
3030
- Fixed an issue, introduced on 2022-06-13, causing a subshell to fork
3131
unnecessarily if an EXIT pseudosignal trap is set within it.
3232

33+
- The ksh93 codebase now requires a C99 compiler to build.
34+
3335
2026-03-16:
3436

3537
- Fixed a bug in the join(1) built-in command (bound to /opt/ast/bin) that

src/cmd/INIT/README-mamake.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MAM (Make Abstract Machine) is a simple rule-based make language
44
that is implemented in just ten four-letter commands and four attributes,
55
yet allows unlimited flexibility as it can execute arbitrary shell code.
66
The program implementing MAM, `mamake`,
7-
is a portable C90 program written in a single file, `mamake.c`.
7+
is a portable C99 program written in a single file, `mamake.c`.
88
This allows ksh 93u+m,
99
or other programs using this build system,
1010
to be built using only a standard C compiler and utilities installation

src/cmd/INIT/iffe.sh

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ is_hdr() # [ - ] [ file.c ] hdr
8282
esac
8383
is hdr $1
8484
case $1 in
85-
sys/types.h | limits.h | stdio.h | unistd.h)
86-
# These are often tested for repeatedly, especially sys/types.h.
87-
# But POSIX has specified these since issue 1 (1988). It's 2023.
88-
# Skip the compile to save time, but act like a positive test.
85+
sys/types.h | limits.h | stddef.h | stdio.h | stdlib.h | unistd.h)
86+
# These are often tested for repeatedly, but POSIX has specified
87+
# these since issue 1 (1988). It's 2026. Skip the compile to save time,
88+
# but act like a positive test.
8989
: 2>$tmp.e
9090
;;
9191
*) 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
689689
}
690690
[+?\abegin\a\b{\b ... \b}end\b delimit multiline code blocks that override
691691
or augment the default code provided by \biffe\b. User supplied code
692-
blocks should be compatible with the C89/C90 C language
692+
blocks should be compatible with the C99 C language
693693
standard for maximal portability. Test code may call the function
694694
\bNOTE("...")\b to emit short text in \b--verbose\b output; only one
695695
\bNOTE()\b should be called per test for readability. In addition to
@@ -1162,7 +1162,6 @@ can=
11621162
cansep=
11631163
cctest=
11641164
file=
1165-
hdrtest=
11661165
ifelse=NONE
11671166
ifstack=
11681167
ini=
@@ -2263,51 +2262,6 @@ int x;
22632262

22642263
cc="$cc $mac"
22652264

2266-
# check for global default headers (some cc -E insist on compiling)
2267-
2268-
case $hdrtest in
2269-
'') hdrtest=1
2270-
allinc=
2271-
for x in types
2272-
do case $config in
2273-
0) c=_sys_${x}
2274-
;;
2275-
1) case $shell in
2276-
ksh) typeset -u u=$x ;;
2277-
*) u=$(echo $x | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ) ;;
2278-
esac
2279-
c=HAVE_SYS_${u}_H
2280-
;;
2281-
esac
2282-
x=sys/$x.h
2283-
echo "${allinc}#include <$x>" > $tmp.c
2284-
if is_hdr $x
2285-
then gothdr="$gothdr + $x"
2286-
case $explicit in
2287-
0) can="$can$cansep#define $c 1 /* #include <$x> ok */"
2288-
nan="$nan$cansep$c=1"
2289-
cansep=$nl
2290-
;;
2291-
esac
2292-
eval $c=1
2293-
allinc="${allinc}#include <$x>$nl"
2294-
else gothdr="$gothdr - $x"
2295-
case $explicit$all$config$undef in
2296-
0?1?|0??1)
2297-
can="$can$cansep#undef $c /* #include <$x> not ok */"
2298-
nan="$nan$cansep$c="
2299-
cansep=$nl
2300-
;;
2301-
01??) can="$can$cansep#define $c 0 /* #include <$x> not ok */"
2302-
nan="$nan$cansep$c=0"
2303-
cansep=$nl
2304-
;;
2305-
esac
2306-
fi
2307-
done
2308-
;;
2309-
esac
2310-
23112265
# add implicit headers/libraries before the checks
23122266

23132267
case $op in

0 commit comments

Comments
 (0)