xref: /illumos-gate/usr/src/test/libc-tests/tests/printf-intmax/printf-intmax.ksh (revision 15bc9d2e3c060641e4e049885e76eb22ee913eec)
1#! /usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2025 Hans Rosenfeld
15#
16
17unalias -a
18export LANG=C.UTF-8
19export LC_ALL=C.UTF-8
20
21FAILED=0
22
23cleanup ()
24{
25    rm -f ${TEMP}/c{89,99}.exp
26    rm -f ${TEMP}/c99.{32,64}
27    rm -f ${TEMP}/c89
28    rmdir ${TEMP}
29}
30
31compare ()
32{
33    if cmp -s ${TEMP}/$1 ${TEMP}/$2; then
34        echo "$2 test passed"
35    else
36        FAILED=1
37        echo "$2 test failed" >2
38        diff -u ${TEMP}/$1 ${TEMP}/$2
39    fi
40}
41
42TESTS=/opt/libc-tests/tests
43TEMP=$(mktemp -d -t intmax)
44
45[[ -z "${TEMP}" ]] && exit 1
46
47trap cleanup EXIT
48
49cat >${TEMP}/c89.exp <<EOF
50long long: 0xffffffffffffffff
51intmax_t: 0xffffffff
52EOF
53
54(( $? != 0 )) && exit 1
55
56cat >${TEMP}/c99.exp <<EOF
57long long: 0xffffffffffffffff
58intmax_t: 0xffffffffffffffff
59EOF
60
61(( $? != 0 )) && exit 1
62
63${TESTS}/printf-intmax.32 >${TEMP}/c99.32
64${TESTS}/printf-intmax.64 >${TEMP}/c99.64
65${TESTS}/printf-intmax.c89 >${TEMP}/c89
66
67compare c89.exp c89
68compare c99.exp c99.32
69compare c99.exp c99.64
70
71(( FAILED != 0 )) && exit 1
72
73exit 0
74