From ec4876105040dce9cada213a9400a43800ab9ed9 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 16 Feb 2005 09:45:15 +0000 Subject: [PATCH] 2005-01-27 Jakub Jelinek [BZ #730] * stdio-common/tst-fmemopen2.c: Include string.h. 2005-01-05 Ulrich Drepper [BZ #730] * libio/iofopncook.c (_IO_cookie_seekoff): Define. Mark offset as invalid to disable optimizations in fileops which won't work here. (_IO_cookie_jumps): Use it. (_IO_old_cookie_jumps): Likewise. * libio/fmemopen.c (fmemopen_seek): Result must be returned in *P, not the return value. * stdio-common/Makefile (tests): Add tst-fmemopen2. * stdio-common/tst-fmemopen2.c: New file. --- stdio-common/tst-fmemopen2.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 stdio-common/tst-fmemopen2.c diff --git a/stdio-common/tst-fmemopen2.c b/stdio-common/tst-fmemopen2.c new file mode 100644 index 00000000000..bcb136e8c1f --- /dev/null +++ b/stdio-common/tst-fmemopen2.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + + +static int +do_test (void) +{ + int result = 0; + char buf[100]; + FILE *fp = fmemopen (buf, sizeof (buf), "w"); + if (fp == NULL) + { + puts ("fmemopen failed"); + return 0; + } + static const char str[] = "hello world"; +#define nstr (sizeof (str) - 1) + fputs (str, fp); + off_t o = ftello (fp); + if (o != nstr) + { + printf ("first ftello returned %ld, expected %zu\n", o, nstr); + result = 1; + } + rewind (fp); + o = ftello (fp); + if (o != 0) + { + printf ("second ftello returned %ld, expected %zu\n", o, 0); + result = 1; + } + if (fseeko (fp, 0, SEEK_END) != 0) + { + puts ("fseeko failed"); + return 1; + } + o = ftello (fp); + if (o != nstr) + { + printf ("third ftello returned %ld, expected %zu\n", o, nstr); + result = 1; + } + rewind (fp); + static const char str2[] = "just hello"; +#define nstr2 (sizeof (str2) - 1) + assert (nstr2 < nstr); + fputs (str2, fp); + o = ftello (fp); + if (o != nstr2) + { + printf ("fourth ftello returned %ld, expected %zu\n", o, nstr2); + result = 1; + } + fclose (fp); + static const char str3[] = "just hellod"; + if (strcmp (buf, str3) != 0) + { + printf ("final string is \"%s\", expected \"%s\"\n", + buf, str3); + result = 1; + } + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- 2.47.2