2019-01-01 00:11:28 +00:00
|
|
|
|
/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
|
Lesser General Public License for more details.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
|
|
|
|
#ifdef BSD
|
|
|
|
|
#include </usr/include/stdio.h>
|
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
|
#else
|
2000-09-24 20:54:13 +00:00
|
|
|
|
#include <limits.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <float.h>
|
Split DIAG_* macros to new header libc-diag.h.
Quite a few tests include libc-internal.h just for the DIAG_* macros.
Split those macros to their own file, which can be included safely in
_ISOMAC mode. I also moved ignore_value, since it seems logically
related, even though I didn't notice any tests needing it.
Also add -Wnonnull suppressions to two tests that _should_ have them,
but the error is masked when compiling against internal headers.
* include/libc-diag.h: New file. Define ignore_value,
DIAG_PUSH_NEEDS_COMMENT, DIAG_POP_NEEDS_COMMENT,
DIAG_IGNORE_NEEDS_COMMENT, and DIAG_IGNORE_Os_NEEDS_COMMENT here.
* include/libc-internal.h: Definitions of above macros moved from
here. Include libc-diag.h. Add copyright notice.
* malloc/tst-malloc.c, malloc/tst-memcheck.c, malloc/tst-realloc.c
* misc/tst-error1.c, posix/tst-dir.c, stdio-common/bug21.c
* stdio-common/scanf14.c, stdio-common/scanf4.c, stdio-common/scanf7.c
* stdio-common/test-vfprintf.c, stdio-common/tst-printf.c
* stdio-common/tst-printfsz.c, stdio-common/tst-sprintf.c
* stdio-common/tst-unlockedio.c, stdio-common/tstdiomisc.c
* stdlib/bug-getcontext.c, string/tester.c, string/tst-endian.c
* time/tst-strptime2.c, wcsmbs/tst-wcstof.c:
Include libc-diag.h instead of libc-internal.h.
* stdlib/tst-environ.c: Include libc-diag.h. Suppress -Wnonnull for
call to unsetenv (NULL).
* nptl/tst-mutex1.c: Include libc-diag.h. Suppress -Wnonnull for
call to pthread_mutexattr_destroy (NULL).
2016-11-21 01:46:30 +00:00
|
|
|
|
#include <libc-diag.h>
|
2014-12-11 21:46:21 +00:00
|
|
|
|
|
|
|
|
|
/* This whole file is picayune tests of corner cases of printf format strings.
|
|
|
|
|
The compiler warnings are not useful here. */
|
|
|
|
|
DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
2016-11-01 23:00:09 +00:00
|
|
|
|
#if __GNUC_PREREQ (7, 0)
|
2017-01-11 14:02:23 +00:00
|
|
|
|
/* Compiler warnings about snprintf output truncation should also be
|
|
|
|
|
ignored. */
|
|
|
|
|
DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-truncation");
|
2016-11-01 23:00:09 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void rfg1 (void);
|
|
|
|
|
static void rfg2 (void);
|
2002-03-13 23:27:20 +00:00
|
|
|
|
static void rfg3 (void);
|
1996-10-08 23:39:20 +00:00
|
|
|
|
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void
|
1996-10-08 23:39:20 +00:00
|
|
|
|
fmtchk (const char *fmt)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
(void) fputs(fmt, stdout);
|
|
|
|
|
(void) printf(":\t`");
|
|
|
|
|
(void) printf(fmt, 0x12);
|
|
|
|
|
(void) printf("'\n");
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void
|
1996-10-08 23:39:20 +00:00
|
|
|
|
fmtst1chk (const char *fmt)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
(void) fputs(fmt, stdout);
|
|
|
|
|
(void) printf(":\t`");
|
|
|
|
|
(void) printf(fmt, 4, 0x12);
|
|
|
|
|
(void) printf("'\n");
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void
|
1996-10-08 23:39:20 +00:00
|
|
|
|
fmtst2chk (const char *fmt)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
(void) fputs(fmt, stdout);
|
|
|
|
|
(void) printf(":\t`");
|
|
|
|
|
(void) printf(fmt, 4, 4, 0x12);
|
|
|
|
|
(void) printf("'\n");
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-03 16:14:21 +00:00
|
|
|
|
static int
|
|
|
|
|
do_test (void)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
static char shortstr[] = "Hi, Z.";
|
|
|
|
|
static char longstr[] = "Good morning, Doctor Chandra. This is Hal. \
|
|
|
|
|
I am ready for my first lesson today.";
|
1999-05-07 11:32:00 +00:00
|
|
|
|
int result = 0;
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
|
|
|
|
fmtchk("%.4x");
|
|
|
|
|
fmtchk("%04x");
|
|
|
|
|
fmtchk("%4.4x");
|
|
|
|
|
fmtchk("%04.4x");
|
|
|
|
|
fmtchk("%4.3x");
|
|
|
|
|
fmtchk("%04.3x");
|
|
|
|
|
|
|
|
|
|
fmtst1chk("%.*x");
|
|
|
|
|
fmtst1chk("%0*x");
|
|
|
|
|
fmtst2chk("%*.*x");
|
|
|
|
|
fmtst2chk("%0*.*x");
|
|
|
|
|
|
|
|
|
|
#ifndef BSD
|
1998-07-29 09:04:25 +00:00
|
|
|
|
printf("bad format:\t\"%b\"\n");
|
1996-10-12 00:56:05 +00:00
|
|
|
|
printf("nil pointer (padded):\t\"%10p\"\n", (void *) NULL);
|
1995-02-18 01:27:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
printf("decimal negative:\t\"%d\"\n", -2345);
|
|
|
|
|
printf("octal negative:\t\"%o\"\n", -2345);
|
|
|
|
|
printf("hex negative:\t\"%x\"\n", -2345);
|
|
|
|
|
printf("long decimal number:\t\"%ld\"\n", -123456L);
|
|
|
|
|
printf("long octal negative:\t\"%lo\"\n", -2345L);
|
|
|
|
|
printf("long unsigned decimal number:\t\"%lu\"\n", -123456L);
|
|
|
|
|
printf("zero-padded LDN:\t\"%010ld\"\n", -123456L);
|
2002-03-13 23:27:20 +00:00
|
|
|
|
printf("left-adjusted ZLDN:\t\"%-010ld\"\n", -123456L);
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf("space-padded LDN:\t\"%10ld\"\n", -123456L);
|
|
|
|
|
printf("left-adjusted SLDN:\t\"%-10ld\"\n", -123456L);
|
|
|
|
|
|
|
|
|
|
printf("zero-padded string:\t\"%010s\"\n", shortstr);
|
|
|
|
|
printf("left-adjusted Z string:\t\"%-010s\"\n", shortstr);
|
|
|
|
|
printf("space-padded string:\t\"%10s\"\n", shortstr);
|
|
|
|
|
printf("left-adjusted S string:\t\"%-10s\"\n", shortstr);
|
2018-11-01 17:13:55 +00:00
|
|
|
|
/* GCC 9 warns about the NULL format argument; this is deliberately
|
|
|
|
|
tested here. */
|
|
|
|
|
DIAG_PUSH_NEEDS_COMMENT;
|
|
|
|
|
#if __GNUC_PREREQ (7, 0)
|
|
|
|
|
DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-overflow=");
|
|
|
|
|
#endif
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf("null string:\t\"%s\"\n", (char *)NULL);
|
2018-11-01 17:13:55 +00:00
|
|
|
|
DIAG_POP_NEEDS_COMMENT;
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf("limited string:\t\"%.22s\"\n", longstr);
|
|
|
|
|
|
2017-10-13 18:44:39 +00:00
|
|
|
|
printf("a-style max:\t\"%a\"\n", DBL_MAX);
|
|
|
|
|
printf("a-style -max:\t\"%a\"\n", -DBL_MAX);
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf("e-style >= 1:\t\"%e\"\n", 12.34);
|
|
|
|
|
printf("e-style >= .1:\t\"%e\"\n", 0.1234);
|
|
|
|
|
printf("e-style < .1:\t\"%e\"\n", 0.001234);
|
|
|
|
|
printf("e-style big:\t\"%.60e\"\n", 1e20);
|
|
|
|
|
printf ("e-style == .1:\t\"%e\"\n", 0.1);
|
|
|
|
|
printf("f-style >= 1:\t\"%f\"\n", 12.34);
|
|
|
|
|
printf("f-style >= .1:\t\"%f\"\n", 0.1234);
|
|
|
|
|
printf("f-style < .1:\t\"%f\"\n", 0.001234);
|
|
|
|
|
printf("g-style >= 1:\t\"%g\"\n", 12.34);
|
|
|
|
|
printf("g-style >= .1:\t\"%g\"\n", 0.1234);
|
|
|
|
|
printf("g-style < .1:\t\"%g\"\n", 0.001234);
|
|
|
|
|
printf("g-style big:\t\"%.60g\"\n", 1e20);
|
|
|
|
|
|
|
|
|
|
printf (" %6.5f\n", .099999999860301614);
|
|
|
|
|
printf (" %6.5f\n", .1);
|
|
|
|
|
printf ("x%5.4fx\n", .5);
|
|
|
|
|
|
|
|
|
|
printf ("%#03x\n", 1);
|
|
|
|
|
|
2000-06-29 20:58:06 +00:00
|
|
|
|
printf ("something really insane: %.10000f\n", 1.0);
|
2000-06-29 19:35:32 +00:00
|
|
|
|
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
double d = FLT_MIN;
|
|
|
|
|
int niter = 17;
|
1996-04-03 16:31:49 +00:00
|
|
|
|
|
1995-02-18 01:27:10 +00:00
|
|
|
|
while (niter-- != 0)
|
|
|
|
|
printf ("%.17e\n", d / 2);
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("%15.5e\n", 4.9406564584124654e-324);
|
|
|
|
|
|
|
|
|
|
#define FORMAT "|%12.4f|%12.4e|%12.4g|\n"
|
|
|
|
|
printf (FORMAT, 0.0, 0.0, 0.0);
|
|
|
|
|
printf (FORMAT, 1.0, 1.0, 1.0);
|
|
|
|
|
printf (FORMAT, -1.0, -1.0, -1.0);
|
|
|
|
|
printf (FORMAT, 100.0, 100.0, 100.0);
|
|
|
|
|
printf (FORMAT, 1000.0, 1000.0, 1000.0);
|
|
|
|
|
printf (FORMAT, 10000.0, 10000.0, 10000.0);
|
|
|
|
|
printf (FORMAT, 12345.0, 12345.0, 12345.0);
|
|
|
|
|
printf (FORMAT, 100000.0, 100000.0, 100000.0);
|
|
|
|
|
printf (FORMAT, 123456.0, 123456.0, 123456.0);
|
|
|
|
|
#undef FORMAT
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
char buf[20];
|
1999-09-25 06:37:46 +00:00
|
|
|
|
char buf2[512];
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n",
|
2002-03-13 23:27:20 +00:00
|
|
|
|
snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf),
|
|
|
|
|
buf);
|
|
|
|
|
printf ("snprintf (\"%%.999999u\", 10) == %d\n",
|
2019-02-27 13:55:45 +00:00
|
|
|
|
snprintf (buf2, sizeof (buf2), "%.999999u", 10));
|
1995-02-18 01:27:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 16:29:16 +00:00
|
|
|
|
printf("%.8f\n", DBL_MAX);
|
|
|
|
|
printf("%.8f\n", -DBL_MAX);
|
1995-02-18 01:27:10 +00:00
|
|
|
|
printf ("%e should be 1.234568e+06\n", 1234567.8);
|
|
|
|
|
printf ("%f should be 1234567.800000\n", 1234567.8);
|
|
|
|
|
printf ("%g should be 1.23457e+06\n", 1234567.8);
|
|
|
|
|
printf ("%g should be 123.456\n", 123.456);
|
|
|
|
|
printf ("%g should be 1e+06\n", 1000000.0);
|
|
|
|
|
printf ("%g should be 10\n", 10.0);
|
|
|
|
|
printf ("%g should be 0.02\n", 0.02);
|
|
|
|
|
|
2002-03-15 22:08:18 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* This test rather checks the way the compiler handles constant
|
|
|
|
|
folding. gcc behavior wrt to this changed in 3.2 so it is not a
|
|
|
|
|
portable test. */
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
double x=1.0;
|
|
|
|
|
printf("%.17f\n",(1.0/x/10.0+1.0)*x-x);
|
|
|
|
|
}
|
2002-03-15 22:08:18 +00:00
|
|
|
|
#endif
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
1996-04-03 16:31:49 +00:00
|
|
|
|
{
|
|
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
|
|
sprintf(buf,"%*s%*s%*s",-1,"one",-20,"two",-30,"three");
|
|
|
|
|
|
1999-05-07 11:32:00 +00:00
|
|
|
|
result |= strcmp (buf,
|
|
|
|
|
"onetwo three ");
|
1996-04-03 16:31:49 +00:00
|
|
|
|
|
|
|
|
|
puts (result != 0 ? "Test failed!" : "Test ok.");
|
|
|
|
|
}
|
1999-05-07 11:32:00 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
|
|
sprintf (buf, "%07Lo", 040000000000ll);
|
2000-07-07 21:06:48 +00:00
|
|
|
|
printf ("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s", buf);
|
1999-05-07 11:32:00 +00:00
|
|
|
|
|
|
|
|
|
if (strcmp (buf, "40000000000") != 0)
|
|
|
|
|
{
|
|
|
|
|
result = 1;
|
|
|
|
|
fputs ("\tFAILED", stdout);
|
|
|
|
|
}
|
|
|
|
|
puts ("");
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 20:54:13 +00:00
|
|
|
|
printf ("printf (\"%%hhu\", %u) = %hhu\n", UCHAR_MAX + 2, UCHAR_MAX + 2);
|
|
|
|
|
printf ("printf (\"%%hu\", %u) = %hu\n", USHRT_MAX + 2, USHRT_MAX + 2);
|
2006-05-02 20:28:05 +00:00
|
|
|
|
printf ("printf (\"%%hhi\", %i) = %hhi\n", UCHAR_MAX + 2, UCHAR_MAX + 2);
|
|
|
|
|
printf ("printf (\"%%hi\", %i) = %hi\n", USHRT_MAX + 2, USHRT_MAX + 2);
|
|
|
|
|
|
|
|
|
|
printf ("printf (\"%%1$hhu\", %2$u) = %1$hhu\n",
|
|
|
|
|
UCHAR_MAX + 2, UCHAR_MAX + 2);
|
|
|
|
|
printf ("printf (\"%%1$hu\", %2$u) = %1$hu\n", USHRT_MAX + 2, USHRT_MAX + 2);
|
|
|
|
|
printf ("printf (\"%%1$hhi\", %2$i) = %1$hhi\n",
|
|
|
|
|
UCHAR_MAX + 2, UCHAR_MAX + 2);
|
|
|
|
|
printf ("printf (\"%%1$hi\", %2$i) = %1$hi\n", USHRT_MAX + 2, USHRT_MAX + 2);
|
2000-09-24 20:54:13 +00:00
|
|
|
|
|
2000-07-07 21:06:48 +00:00
|
|
|
|
puts ("--- Should be no further output. ---");
|
|
|
|
|
rfg1 ();
|
|
|
|
|
rfg2 ();
|
2002-03-13 23:27:20 +00:00
|
|
|
|
rfg3 ();
|
2000-07-07 21:06:48 +00:00
|
|
|
|
|
2000-09-24 20:54:13 +00:00
|
|
|
|
{
|
|
|
|
|
char bytes[7];
|
|
|
|
|
char buf[20];
|
|
|
|
|
|
|
|
|
|
memset (bytes, '\xff', sizeof bytes);
|
|
|
|
|
sprintf (buf, "foo%hhn\n", &bytes[3]);
|
|
|
|
|
if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff'
|
|
|
|
|
|| bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff')
|
|
|
|
|
{
|
|
|
|
|
puts ("%hhn overwrite more bytes");
|
|
|
|
|
result = 1;
|
|
|
|
|
}
|
|
|
|
|
if (bytes[3] != 3)
|
|
|
|
|
{
|
|
|
|
|
puts ("%hhn wrote incorrect value");
|
|
|
|
|
result = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-07 11:32:00 +00:00
|
|
|
|
return result != 0;
|
1995-02-18 01:27:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void
|
1996-10-08 23:39:20 +00:00
|
|
|
|
rfg1 (void)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
|
|
sprintf (buf, "%5.s", "xyz");
|
|
|
|
|
if (strcmp (buf, " ") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " ");
|
|
|
|
|
sprintf (buf, "%5.f", 33.3);
|
|
|
|
|
if (strcmp (buf, " 33") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 33");
|
|
|
|
|
sprintf (buf, "%8.e", 33.3e7);
|
|
|
|
|
if (strcmp (buf, " 3e+08") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 3e+08");
|
|
|
|
|
sprintf (buf, "%8.E", 33.3e7);
|
|
|
|
|
if (strcmp (buf, " 3E+08") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 3E+08");
|
|
|
|
|
sprintf (buf, "%.g", 33.3);
|
|
|
|
|
if (strcmp (buf, "3e+01") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, "3e+01");
|
|
|
|
|
sprintf (buf, "%.G", 33.3);
|
|
|
|
|
if (strcmp (buf, "3E+01") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, "3E+01");
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-15 16:03:57 +00:00
|
|
|
|
static void
|
1996-10-08 23:39:20 +00:00
|
|
|
|
rfg2 (void)
|
1995-02-18 01:27:10 +00:00
|
|
|
|
{
|
|
|
|
|
int prec;
|
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
|
|
prec = 0;
|
|
|
|
|
sprintf (buf, "%.*g", prec, 3.3);
|
|
|
|
|
if (strcmp (buf, "3") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, "3");
|
|
|
|
|
prec = 0;
|
|
|
|
|
sprintf (buf, "%.*G", prec, 3.3);
|
|
|
|
|
if (strcmp (buf, "3") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, "3");
|
|
|
|
|
prec = 0;
|
|
|
|
|
sprintf (buf, "%7.*G", prec, 3.33);
|
|
|
|
|
if (strcmp (buf, " 3") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 3");
|
|
|
|
|
prec = 3;
|
|
|
|
|
sprintf (buf, "%04.*o", prec, 33);
|
|
|
|
|
if (strcmp (buf, " 041") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 041");
|
|
|
|
|
prec = 7;
|
|
|
|
|
sprintf (buf, "%09.*u", prec, 33);
|
|
|
|
|
if (strcmp (buf, " 0000033") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 0000033");
|
|
|
|
|
prec = 3;
|
|
|
|
|
sprintf (buf, "%04.*x", prec, 33);
|
|
|
|
|
if (strcmp (buf, " 021") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 021");
|
|
|
|
|
prec = 3;
|
|
|
|
|
sprintf (buf, "%04.*X", prec, 33);
|
|
|
|
|
if (strcmp (buf, " 021") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf, " 021");
|
|
|
|
|
}
|
2002-03-13 23:27:20 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rfg3 (void)
|
|
|
|
|
{
|
|
|
|
|
char buf[100];
|
|
|
|
|
double g = 5.0000001;
|
|
|
|
|
unsigned long l = 1234567890;
|
|
|
|
|
double d = 321.7654321;
|
2002-03-15 22:08:18 +00:00
|
|
|
|
const char s[] = "test-string";
|
2002-03-13 23:27:20 +00:00
|
|
|
|
int i = 12345;
|
|
|
|
|
int h = 1234;
|
|
|
|
|
|
|
|
|
|
sprintf (buf,
|
|
|
|
|
"%1$*5$d %2$*6$hi %3$*7$lo %4$*8$f %9$*12$e %10$*13$g %11$*14$s",
|
|
|
|
|
i, h, l, d, 8, 5, 14, 14, d, g, s, 14, 3, 14);
|
|
|
|
|
if (strcmp (buf,
|
|
|
|
|
" 12345 1234 11145401322 321.765432 3.217654e+02 5 test-string") != 0)
|
|
|
|
|
printf ("got: '%s', expected: '%s'\n", buf,
|
|
|
|
|
" 12345 1234 11145401322 321.765432 3.217654e+02 5 test-string");
|
|
|
|
|
}
|
2015-08-03 16:14:21 +00:00
|
|
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
|
#include "../test-skeleton.c"
|