diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-08-28 20:33:49 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-08-28 20:33:49 +0000 |
commit | 3586b2b60b6d92ce3cc3d497e84ae1e5cfcf81e4 (patch) | |
tree | 4d2932e03d37e5410698f2415257c2065a0959de /debug/tst-chk1.c | |
parent | cba5c7c07388e2a8251c470c279797dc303d4277 (diff) | |
download | glibc-3586b2b60b6d92ce3cc3d497e84ae1e5cfcf81e4.tar glibc-3586b2b60b6d92ce3cc3d497e84ae1e5cfcf81e4.tar.gz glibc-3586b2b60b6d92ce3cc3d497e84ae1e5cfcf81e4.tar.bz2 glibc-3586b2b60b6d92ce3cc3d497e84ae1e5cfcf81e4.zip |
* libio/bits/stdio2.h (__fread_chk, __fread_unlocked_chk): New
prototypes.
(__fread_alias, __fread_unlocked_alias): New aliases.
(fread): New extern inline.
(fread_unlocked): Likewise. Undef macro before definition of
the inline function.
* debug/Makefile (routines): Add fread_chk and fread_u_chk.
(CFLAGS-fread_chk.c, CFLAGS-fread_u_chk.c): Add.
* debug/Versions (libc): Export __fread_chk@@GLIBC_2.7
and __fread_unlocked_chk@@GLIBC_2.7.
* debug/fread_chk.c: New file.
* debug/fread_u_chk.c: New file.
* debug/tst-chk1.c (do_test): Add fread and fread_unlocked tests.
Diffstat (limited to 'debug/tst-chk1.c')
-rw-r--r-- | debug/tst-chk1.c | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 993dab63b2..26ace28970 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. @@ -746,6 +746,75 @@ do_test (void) CHK_FAIL_END #endif + rewind (stdin); + + if (fread (buf, 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread (buf, sizeof (buf), 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread (buf, sizeof (buf), l0 + 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + if (fread (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) + FAIL (); + CHK_FAIL_END + + CHK_FAIL_START + if (fread (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) + FAIL (); + CHK_FAIL_END +#endif + + rewind (stdin); + + if (fread_unlocked (buf, 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread_unlocked (buf, sizeof (buf), 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread_unlocked (buf, 1, 4, stdin) != 4 + || memcmp (buf, "abcdFGHI\na", 10)) + FAIL (); + if (fread_unlocked (buf, 4, 1, stdin) != 1 + || memcmp (buf, "efghFGHI\na", 10)) + FAIL (); + + rewind (stdin); + + if (fread_unlocked (buf, l0 + 1, sizeof (buf), stdin) != sizeof (buf) + || memcmp (buf, "abcdefgh\nA", 10)) + FAIL (); + if (fread_unlocked (buf, sizeof (buf), l0 + 1, stdin) != 1 + || memcmp (buf, "BCDEFGHI\na", 10)) + FAIL (); + +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + if (fread_unlocked (buf, 1, sizeof (buf) + 1, stdin) != sizeof (buf) + 1) + FAIL (); + CHK_FAIL_END + + CHK_FAIL_START + if (fread_unlocked (buf, sizeof (buf) + 1, l0 + 1, stdin) != 1) + FAIL (); + CHK_FAIL_END +#endif + lseek (fileno (stdin), 0, SEEK_SET); if (read (fileno (stdin), buf, sizeof (buf) - 1) != sizeof (buf) - 1 |