glibc/stdio-common/scanf13.c

187 lines
3.9 KiB
C
Raw Normal View History

* include/stdio.h (__isoc99_fscanf, __isoc99_scanf, __isoc99_sscanf, __isoc99_vscanf): New prototypes. (__isoc99_vsscanf, __isoc99_vfscanf): New prototypes, add libc_hidden_proto. * include/wchar.h (__isoc99_fwscanf, __isoc99_wscanf, __isoc99_swscanf, __isoc99_vwscanf): New prototypes. (__isoc99_vswscanf, __isoc99_vfwscanf): New prototypes, add libc_hidden_proto. * libio/stdio.h (fscanf, scanf, sscanf, vfscanf, vscanf, vsscanf): Redirect to __isoc99_* if strict ISO C99 or POSIX conformance requested. * wcsmbs/wchar.h (fwscanf, wscanf, swscanf, vfwscanf, vwscanf, vswscanf): Redirect to __isoc99_* if strict ISO C99 or POSIX conformance requested. * libio/bits/stdio-ldbl.h (fscanf, scanf, sscanf, vfscanf, vscanf, vsscanf): Redirect to __nldbl___isoc99_* if strict ISO C99 or POSIX conformance requested. * wcsmbs/bits/wchar-ldbl.h (fwscanf, wscanf, swscanf, vfwscanf, vwscanf, vswscanf): Redirect to __nldbl___isoc99_* if strict ISO C99 or POSIX conformance requested. * stdio-common/Versions (libc): Export __isoc99_scanf@@GLIBC_2.7, __isoc99_vscanf@@GLIBC_2.7, __isoc99_fscanf@@GLIBC_2.7, __isoc99_vfscanf@@GLIBC_2.7, __isoc99_sscanf@@GLIBC_2.7 and __isoc99_vsscanf@@GLIBC_2.7. * stdio-common/Makefile (routines): Add isoc99_scanf, isoc99_vscanf, isoc99_fscanf, isoc99_vfscanf, isoc99_sscanf and isoc99_vsscanf. (tests): Add scanf14. (CFLAGS-vfprintf.c, CFLAGS-fprintf.c, CFLAGS-printf.c, CFLAGS-vfwprintf.c, CFLAGS-vfscanf.c, CFLAGS-vfwscanf.c, CFLAGS-fscanf.c, CFLAGS-scanf.c, CFLAGS-isoc99_vfscanf.c, CFLAGS-isoc99_vscanf.c, CFLAGS-isoc99_fscanf.c, CFLAGS-isoc99_scanf.c): Add $(exceptions). (CFLAGS-scanf15.c): Add various -I paths to prevent the compiler from using internal headers. * wcsmbs/Versions (libc): Export __isoc99_wscanf@@GLIBC_2.7, __isoc99_vwscanf@@GLIBC_2.7, __isoc99_fwscanf@@GLIBC_2.7, __isoc99_vfwscanf@@GLIBC_2.7, __isoc99_swscanf@@GLIBC_2.7 and __isoc99_vswscanf@@GLIBC_2.7. * wcsmbs/Makefile (routines): Add isoc99_wscanf, isoc99_vwscanf, isoc99_fwscanf, isoc99_vfwscanf, isoc99_swscanf and isoc99_vswscanf. (CFLAGS-isoc99_wscanf.c, CFLAGS-isoc99_fwscanf.c, CFLAGS-isoc99_vwscanf.c, CFLAGS-isoc99_vfwscanf.c): Add $(exceptions). (CPPFLAGS): Add -D_IO_MTSAFE_IO if needed. * stdio-common/isoc99_scanf.c: New file. * stdio-common/isoc99_vsscanf.c: New file. * stdio-common/isoc99_vscanf.c: New file. * stdio-common/isoc99_vfscanf.c: New file. * stdio-common/isoc99_fscanf.c: New file. * stdio-common/isoc99_sscanf.c: New file. * wcsmbs/isoc99_fwscanf.c: New file. * wcsmbs/isoc99_vswscanf.c: New file. * wcsmbs/isoc99_swscanf.c: New file. * wcsmbs/isoc99_wscanf.c: New file. * wcsmbs/isoc99_vwscanf.c: New file. * wcsmbs/isoc99_vfwscanf.c: New file. * libio/libio.h (_IO_FLAGS2_SCANF_STD): Define. * libio/libioP.h (_IO_acquire_lock_clear_flags2_fct): Also clear _IO_FLAGS2_SCANF_STD bit from _flags2. * stdio-common/vfscanf.c (_IO_vfscanf_internal): Don't handle %as, %aS and %a[ if _IO_FLAGS2_SCANF_STD is set in _flags2. * stdio-common/scanf14.c: New test. * stdio-common/scanf15.c: New test. * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add isoc99_scanf, isoc99_fscanf, isoc99_sscanf, isoc99_vscanf, isoc99_vfscanf, isoc99_vsscanf, isoc99_wscanf, isoc99_fwscanf, isoc99_swscanf, isoc99_vwscanf, isoc99_vfwscanf and isoc99_vswscanf. * sysdeps/ieee754/ldbl-opt/Versions (libc): Export __nldbl___isoc99_scanf@@GLIBC_2.7, __nldbl___isoc99_fscanf@@GLIBC_2.7, __nldbl___isoc99_sscanf@@GLIBC_2.7, __nldbl___isoc99_vscanf@@GLIBC_2.7, __nldbl___isoc99_vfscanf@@GLIBC_2.7, __nldbl___isoc99_vsscanf@@GLIBC_2.7, __nldbl___isoc99_wscanf@@GLIBC_2.7, __nldbl___isoc99_fwscanf@@GLIBC_2.7, __nldbl___isoc99_swscanf@@GLIBC_2.7, __nldbl___isoc99_vwscanf@@GLIBC_2.7, __nldbl___isoc99_vfwscanf@@GLIBC_2.7 and __nldbl___isoc99_vswscanf@@GLIBC_2.7. * sysdeps/ieee754/ldbl-opt/nldbl-compat.h (__isoc99_scanf, __isoc99_fscanf, __isoc99_sscanf, __isoc99_vscanf, __isoc99_vfscanf, __isoc99_vsscanf, __isoc99_wscanf, __isoc99_fwscanf, __isoc99_swscanf, __isoc99_vwscanf, __isoc99_vfwscanf, __isoc99_vswscanf): Add NLDBL_DECL. * sysdeps/ieee754/ldbl-opt/nldbl-compat.c (__nldbl___isoc99_scanf, __nldbl___isoc99_fscanf, __nldbl___isoc99_sscanf, __nldbl___isoc99_vscanf, __nldbl___isoc99_vfscanf, __nldbl___isoc99_vsscanf, __nldbl___isoc99_wscanf, __nldbl___isoc99_fwscanf, __nldbl___isoc99_swscanf, __nldbl___isoc99_vwscanf, __nldbl___isoc99_vfwscanf, __nldbl___isoc99_vswscanf): New functions. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vfscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_swscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vwscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_wscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_scanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_sscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vsscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_fwscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vfwscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vswscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_vscanf.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-isoc99_fscanf.c: New file. * stdio-common/Makefile (tests): Add scanf13. (scanf13-ENV): New. * stdio-common/vfscanf.c (_IO_vfscanf_internal): Handle m modifier followed by l. (STRING_ARG): Add width argument. (_IO_vfscanf_internal) <case L_('c')>: Handle %mc. <case L_('C')>: Handle %mlc and %mC. <case L_('s'), case L_('S'), case L_('[')>: Adjust STRING_ARG arguments. * stdio-common/scanf13.c: New test. * libio/libioP.h (_IO_acquire_lock_clear_flags2_fct): Clear the _IO_FLAGS2_FORTIFY bit from _flags2 rather than _flags. type and __THROW marker of splice, vmsplice, and tee.
2007-09-18 21:04:01 +02:00
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
int
main (void)
{
char *sp1, *sp2, *sp3, *sp4;
wchar_t *lsp1, *lsp2, *lsp3, *lsp4;
int result = 0;
char buf[2048+64];
size_t i;
#define FAIL() \
do { \
result = 1; \
printf ("test at line %d failed\n", __LINE__); \
} while (0)
setlocale (LC_ALL, "de_DE.UTF-8");
if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-B",
"A%ms%10ms%4m[bcd]%4mcB", &sp1, &sp2, &sp3, &sp4) != 4)
FAIL ();
else
{
if (strcmp (sp1, "\xc3\x84-") != 0)
FAIL ();
free (sp1);
if (strcmp (sp2, "\xc3\x84-abcdefb") != 0)
FAIL ();
free (sp2);
if (strcmp (sp3, "cd") != 0)
FAIL ();
free (sp3);
if (memcmp (sp4, "\t\xc3\x84-", 4) != 0)
FAIL ();
free (sp4);
}
if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-BB",
"A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4)
FAIL ();
else
{
if (wcscmp (lsp1, L"\xc4-") != 0)
FAIL ();
free (lsp1);
if (wcscmp (lsp2, L"\xc4-abcdefbc") != 0)
FAIL ();
free (lsp2);
if (wcscmp (lsp3, L"d") != 0)
FAIL ();
free (lsp3);
if (memcmp (lsp4, L"\t\xc4-B", 4 * sizeof (wchar_t)) != 0)
FAIL ();
free (lsp4);
}
memset (buf, '/', sizeof (buf));
buf[0] = '\t';
buf[1] = ' ';
buf[2] = 0xc3;
buf[3] = 0x84;
buf[2048] = 0xc3;
buf[2049] = 0x84;
buf[2058] = '\t';
buf[2059] = 'a';
if (sscanf (buf, "%ms%mc", &sp1, &sp2) != 2)
FAIL ();
else
{
if (sp1[0] != '\xc3' || sp1[1] != '\x84'
|| sp1[2046] != '\xc3' || sp1[2047] != '\x84'
|| sp1[2056] != '\0')
FAIL ();
sp1[2046] = '/';
sp1[2047] = '/';
for (i = 2; i < 2056; i++)
if (sp1[i] != '/')
FAIL ();
free (sp1);
if (sp2[0] != '\t')
FAIL ();
free (sp2);
}
if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2)
FAIL ();
else
{
if (sp3[0] != '\xc3' || sp3[1] != '\x84'
|| sp3[2046] != '\xc3' || sp3[2047] != '\x84'
|| sp3[2048] != '\0')
FAIL ();
for (i = 2; i < 2046; i++)
if (sp3[i] != '/')
FAIL ();
free (sp3);
if (sp4[0] != '/')
FAIL ();
free (sp4);
}
if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4)
!= 4)
FAIL ();
else
{
if (memcmp (sp1, "\t \xc3\x84", 4) != 0)
FAIL ();
free (sp1);
for (i = 0; i < 1500; i++)
if (sp2[i] != '/')
FAIL ();
if (sp2[1500] != '\0')
FAIL ();
free (sp2);
for (i = 0; i < 544; i++)
if (sp3[i] != '/')
FAIL ();
if (sp3[544] != '\0')
FAIL ();
free (sp3);
if (memcmp (sp4, "\xc3\x84/", 3) != 0)
FAIL ();
free (sp4);
}
if (sscanf (buf, "%mS%mC", &lsp1, &lsp2) != 2)
FAIL ();
else
{
if (lsp1[0] != L'\xc4' || lsp1[2045] != L'\xc4'
|| lsp1[2054] != L'\0')
FAIL ();
lsp1[2045] = L'/';
for (i = 1; i < 2054; i++)
if (lsp1[i] != L'/')
FAIL ();
free (lsp1);
if (lsp2[0] != L'\t')
FAIL ();
free (lsp2);
}
if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2)
FAIL ();
else
{
if (lsp3[0] != L'\xc4' || lsp3[2045] != L'\xc4'
|| lsp3[2048] != L'\0')
FAIL ();
lsp3[2045] = L'/';
for (i = 1; i < 2048; i++)
if (lsp3[i] != L'/')
FAIL ();
free (lsp3);
if (lsp4[0] != L'/')
FAIL ();
free (lsp4);
}
if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc",
&lsp1, &lsp2, &lsp3, &lsp4) != 4)
FAIL ();
else
{
if (memcmp (lsp1, L"\t \xc4/", 4 * sizeof (wchar_t)) != 0)
FAIL ();
free (lsp1);
for (i = 0; i < 1500; i++)
if (lsp2[i] != L'/')
FAIL ();
if (lsp2[1500] != L'\0')
FAIL ();
free (lsp2);
for (i = 0; i < 543; i++)
if (lsp3[i] != L'/')
FAIL ();
if (lsp3[543] != L'\0')
FAIL ();
free (lsp3);
if (memcmp (lsp4, L"\xc4//", 3 * sizeof (wchar_t)) != 0)
FAIL ();
free (lsp4);
}
return result;
}