diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2007-09-18 19:04:01 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2007-09-18 19:04:01 +0000 |
| commit | 874aa52349cc111d1f6ea5dff24bb14c306714e0 (patch) | |
| tree | 40cc28100e18b8b9d8311038b0d3f9dd38bcfe0f /stdio-common | |
| parent | 883f7943f242c174c49bc82d51fe8332ad50d573 (diff) | |
| download | glibc-874aa52349cc111d1f6ea5dff24bb14c306714e0.tar.xz glibc-874aa52349cc111d1f6ea5dff24bb14c306714e0.zip | |
* 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.
Diffstat (limited to 'stdio-common')
| -rw-r--r-- | stdio-common/Makefile | 26 | ||||
| -rw-r--r-- | stdio-common/Versions | 4 | ||||
| -rw-r--r-- | stdio-common/isoc99_fscanf.c | 40 | ||||
| -rw-r--r-- | stdio-common/isoc99_scanf.c | 42 | ||||
| -rw-r--r-- | stdio-common/isoc99_sscanf.c | 37 | ||||
| -rw-r--r-- | stdio-common/isoc99_vfscanf.c | 35 | ||||
| -rw-r--r-- | stdio-common/isoc99_vscanf.c | 34 | ||||
| -rw-r--r-- | stdio-common/isoc99_vsscanf.c | 47 | ||||
| -rw-r--r-- | stdio-common/scanf13.c | 187 | ||||
| -rw-r--r-- | stdio-common/scanf14.c | 63 | ||||
| -rw-r--r-- | stdio-common/scanf15.c | 54 | ||||
| -rw-r--r-- | stdio-common/vfscanf.c | 273 |
12 files changed, 784 insertions, 58 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 84aebf4945..f87ac560aa 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -34,7 +34,9 @@ routines := \ tmpfile tmpfile64 tmpnam tmpnam_r tempnam tempname \ getline getw putw \ remove rename renameat \ - flockfile ftrylockfile funlockfile + flockfile ftrylockfile funlockfile \ + isoc99_scanf isoc99_vscanf isoc99_fscanf isoc99_vfscanf isoc99_sscanf \ + isoc99_vsscanf install-others = $(inst_includedir)/bits/stdio_lim.h @@ -55,7 +57,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \ tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \ tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \ - bug19 bug19a tst-popen2 + bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 test-srcs = tst-unbputc tst-printf @@ -91,14 +93,34 @@ CFLAGS-tempname.c = -fexceptions CFLAGS-psignal.c = -fexceptions CFLAGS-vprintf.c = -fexceptions CFLAGS-cuserid.c = -fexceptions + +CFLAGS-vfprintf.c += $(exceptions) +CFLAGS-fprintf.c += $(exceptions) +CFLAGS-printf.c += $(exceptions) +CFLAGS-vfwprintf.c += $(exceptions) +CFLAGS-vfscanf.c += $(exceptions) +CFLAGS-vfwscanf.c += $(exceptions) +CFLAGS-fscanf.c += $(exceptions) +CFLAGS-scanf.c += $(exceptions) +CFLAGS-isoc99_vfscanf.c += $(exceptions) +CFLAGS-isoc99_vscanf.c += $(exceptions) +CFLAGS-isoc99_fscanf.c += $(exceptions) +CFLAGS-isoc99_scanf.c += $(exceptions) CFLAGS-errlist.c = $(fno-unit-at-a-time) CFLAGS-siglist.c = $(fno-unit-at-a-time) +# The following is a hack since we must compile scanf15.c without any +# GNU extension. The latter are needed, though, when internal headers +# are used. So made sure we see the installed headers first. +CFLAGS-scanf15.c = -I../libio -I../stdlib -I../wcsmbs -I../time -I../string \ + -I../wctype + # We know the test has a format string problem. CFLAGS-tst-sprintf.c = -Wno-format tst-sscanf-ENV = LOCPATH=$(common-objpfx)localedata tst-swprintf-ENV = LOCPATH=$(common-objpfx)localedata test-vfprintf-ENV = LOCPATH=$(common-objpfx)localedata +scanf13-ENV = LOCPATH=$(common-objpfx)localedata bug14-ENV = LOCPATH=$(common-objpfx)localedata bug15-ENV = LOCPATH=$(common-objpfx)localedata diff --git a/stdio-common/Versions b/stdio-common/Versions index 2f64429346..1501fa2ffd 100644 --- a/stdio-common/Versions +++ b/stdio-common/Versions @@ -49,6 +49,10 @@ libc { GLIBC_2.4 { renameat; } + GLIBC_2.7 { + __isoc99_scanf; __isoc99_vscanf; __isoc99_fscanf; __isoc99_vfscanf; + __isoc99_sscanf; __isoc99_vsscanf; + } GLIBC_PRIVATE { # global variables _itoa_lower_digits; diff --git a/stdio-common/isoc99_fscanf.c b/stdio-common/isoc99_fscanf.c new file mode 100644 index 0000000000..5b8c16e788 --- /dev/null +++ b/stdio-common/isoc99_fscanf.c @@ -0,0 +1,40 @@ +/* Copyright (C) 1991, 1997, 2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <libioP.h> +#include <stdarg.h> +#include <stdio.h> + +/* Read formatted input from STREAM according to the format string FORMAT. */ +/* VARARGS2 */ +int +__isoc99_fscanf (FILE *stream, const char *format, ...) +{ + va_list arg; + int done; + + _IO_acquire_lock_clear_flags2 (stream); + stream->_flags2 |= _IO_FLAGS2_SCANF_STD; + + va_start (arg, format); + done = INTUSE(_IO_vfscanf) (stream, format, arg, NULL); + va_end (arg); + + _IO_release_lock (stream); + return done; +} diff --git a/stdio-common/isoc99_scanf.c b/stdio-common/isoc99_scanf.c new file mode 100644 index 0000000000..a90fe7018c --- /dev/null +++ b/stdio-common/isoc99_scanf.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 2002, 2004, 2006, 2007 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdarg.h> +#include <stdio.h> +#include <libioP.h> + + +/* Read formatted input from stdin according to the format string FORMAT. */ +/* VARARGS1 */ +int +__isoc99_scanf (const char *format, ...) +{ + va_list arg; + int done; + + _IO_acquire_lock_clear_flags2 (stdin); + stdin->_flags2 |= _IO_FLAGS2_SCANF_STD; + + va_start (arg, format); + done = INTUSE(_IO_vfscanf) (stdin, format, arg, NULL); + va_end (arg); + + _IO_release_lock (stdin); + return done; +} diff --git a/stdio-common/isoc99_sscanf.c b/stdio-common/isoc99_sscanf.c new file mode 100644 index 0000000000..9500ccb464 --- /dev/null +++ b/stdio-common/isoc99_sscanf.c @@ -0,0 +1,37 @@ +/* Copyright (C) 1991, 1995, 1996, 1998, 2002, 2003, 2004, 2006, 2007 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdarg.h> +#include <stdio.h> +#include <libioP.h> + +/* Read formatted input from S, according to the format string FORMAT. */ +/* VARARGS2 */ +int +__isoc99_sscanf (const char *s, const char *format, ...) +{ + va_list arg; + int done; + + va_start (arg, format); + done = __isoc99_vsscanf (s, format, arg); + va_end (arg); + + return done; +} diff --git a/stdio-common/isoc99_vfscanf.c b/stdio-common/isoc99_vfscanf.c new file mode 100644 index 0000000000..10b04c3bc7 --- /dev/null +++ b/stdio-common/isoc99_vfscanf.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 1997, 2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <libioP.h> +#include <stdio.h> + +/* Read formatted input from STREAM according to the format string FORMAT. */ +/* VARARGS2 */ +int +__isoc99_vfscanf (FILE *stream, const char *format, _IO_va_list args) +{ + int done; + + _IO_acquire_lock_clear_flags2 (stream); + stream->_flags2 |= _IO_FLAGS2_SCANF_STD; + done = INTUSE(_IO_vfscanf) (stream, format, args, NULL); + _IO_release_lock (stream); + return done; +} +libc_hidden_def (__isoc99_vfscanf) diff --git a/stdio-common/isoc99_vscanf.c b/stdio-common/isoc99_vscanf.c new file mode 100644 index 0000000000..f7858f042b --- /dev/null +++ b/stdio-common/isoc99_vscanf.c @@ -0,0 +1,34 @@ +/* Copyright (C) 1991, 1997, 2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <libioP.h> +#include <stdio.h> + +/* Read formatted input from STDIN according to the format string FORMAT. */ +/* VARARGS2 */ +int +__isoc99_vscanf (const char *format, _IO_va_list args) +{ + int done; + + _IO_acquire_lock_clear_flags2 (stdin); + stdin->_flags2 |= _IO_FLAGS2_SCANF_STD; + done = INTUSE(_IO_vfscanf) (stdin, format, args, NULL); + _IO_release_lock (stdin); + return done; +} diff --git a/stdio-common/isoc99_vsscanf.c b/stdio-common/isoc99_vsscanf.c new file mode 100644 index 0000000000..f10919c79a --- /dev/null +++ b/stdio-common/isoc99_vsscanf.c @@ -0,0 +1,47 @@ +/* Copyright (C) 1993, 1997-2003, 2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + 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. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + As a special exception, if you link the code in this file with + files compiled with a GNU compiler to produce an executable, + that does not cause the resulting executable to be covered by + the GNU Lesser General Public License. This exception does not + however invalidate any other reasons why the executable file + might be covered by the GNU Lesser General Public License. + This exception applies to code released by its copyright holders + in files containing the exception. */ + +#include <libioP.h> +#include <stdio.h> +#include "../libio/strfile.h" + +int +__isoc99_vsscanf (const char *string, const char *format, _IO_va_list args) +{ + int ret; + _IO_strfile sf; +#ifdef _IO_MTSAFE_IO + sf._sbf._f._lock = NULL; +#endif + _IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL); + _IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps; + _IO_str_init_static_internal (&sf, (char*)string, 0, NULL); + sf._sbf._f._flags2 |= _IO_FLAGS2_SCANF_STD; + ret = INTUSE(_IO_vfscanf) ((_IO_FILE *) &sf._sbf, format, args, NULL); + return ret; +} +libc_hidden_def (__isoc99_vsscanf) diff --git a/stdio-common/scanf13.c b/stdio-common/scanf13.c new file mode 100644 index 0000000000..e53cde29c7 --- /dev/null +++ b/stdio-common/scanf13.c @@ -0,0 +1,187 @@ +#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]; + wchar_t wbuf[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) |
