FreeBSD Bugzilla – Attachment 162664 Details for
Bug 204156
fmemopen tests failing after r289863
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Source file (stripped of "ATF-ness")
fmemopen2_test.c (text/x-csrc), 3.25 KB, created by
Enji Cooper
on 2015-11-01 05:14:31 UTC
(
hide
)
Description:
Source file (stripped of "ATF-ness")
Filename:
MIME Type:
Creator:
Enji Cooper
Created:
2015-11-01 05:14:31 UTC
Size:
3.25 KB
patch
obsolete
>/*- >Copyright (C) 2013 Pietro Cerutti <gahr@FreeBSD.org> > >Redistribution and use in source and binary forms, with or without >modification, are permitted provided that the following conditions >are met: >1. Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. >2. Redistributions in binary form must reproduce the above copyright > notice, this list of conditions and the following disclaimer in the > documentation and/or other materials provided with the distribution. > >THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND >ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE >FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >SUCH DAMAGE. >*/ > >/* > * Test basic FILE * functions (fread, fwrite, fseek, fclose) against > * a FILE * retrieved using fmemopen() > */ > >#include <sys/cdefs.h> >__FBSDID("$FreeBSD: user/ngie/more-tests/lib/libc/tests/stdio/fmemopen2_test.c 288382 2015-09-29 17:54:28Z delphij $"); > >#include <assert.h> >#include <errno.h> >#include <stdio.h> >#include <string.h> >#include <strings.h> > >#define ATF_REQUIRE assert > >int >main(void) >{ > /* > * Here we test that a read operation doesn't go past the end of the > * data actually written, and that a SEEK_END seeks from the end of the > * data, not of the whole buffer. > */ > FILE *fp; > char buf[512] = {'\0'}; > char str[] = "Test data length. "; > char str2[] = "Do we have two sentences?"; > char str3[sizeof(str) + sizeof(str2) -1]; > long pos; > size_t nofw, nofr; > int rc; > > /* Open a FILE * for updating our buffer. */ > fp = fmemopen(buf, sizeof(buf), "w+"); > ATF_REQUIRE(fp != NULL); > > /* Write our string into the buffer. */ > nofw = fwrite(str, 1, sizeof(str), fp); > ATF_REQUIRE(nofw == sizeof(str)); > > /* > * Now seek to the end and check that ftell > * gives us sizeof(str). > */ > rc = fseek(fp, 0, SEEK_END); > ATF_REQUIRE(rc == 0); > pos = ftell(fp); > ATF_REQUIRE(pos == sizeof(str)); > > /* Close the FILE *. */ > rc = fclose(fp); > ATF_REQUIRE(rc == 0); > > /* Reopen the buffer for appending. */ > fp = fmemopen(buf, sizeof(buf), "a+"); > ATF_REQUIRE(fp != NULL); > > /* We should now be writing after the first string. */ > nofw = fwrite(str2, 1, sizeof(str2), fp); > ATF_REQUIRE(nofw == sizeof(str2)); > > /* Rewind the FILE *. */ > rc = fseek(fp, 0, SEEK_SET); > ATF_REQUIRE(rc == 0); > > /* Make sure we're at the beginning. */ > pos = ftell(fp); > ATF_REQUIRE(pos == 0); > > /* Read the whole buffer. */ > nofr = fread(str3, 1, sizeof(buf), fp); > ATF_REQUIRE(nofr == sizeof(str3)); > > /* Make sure the two strings are there. */ > ATF_REQUIRE(strncmp(str3, str, sizeof(str) - 1) == 0); > ATF_REQUIRE(strncmp(str3 + sizeof(str) - 1, str2, sizeof(str2)) == 0); > > /* Close the FILE *. */ > rc = fclose(fp); > ATF_REQUIRE(rc == 0); > > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 204156
: 162664