This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer
- From: "ppluzhnikov at google dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Thu, 06 Feb 2014 02:47:28 +0000
- Subject: [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=16532
Bug ID: 16532
Summary: fdopen(..., "a"); fwrite(); ftell() sequence gives
wrong answer
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: stdio
Assignee: unassigned at sourceware dot org
Reporter: ppluzhnikov at google dot com
This is a regression from 2.15.
Test case below, does not assert with glibc-2.15, but asserts with current
trunk.
If I use fopen() instead of fdopen() ["./a.out -o"] or if I fflush() after
fwrite() ["./a.out -f"], then assert goes away.
/* --- cut --- */
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
FILE *fp;
size_t written;
off_t off;
int do_flush = 0, do_fopen = 0;
int opt;
const char *const fname = "/tmp/output";
while ((opt = getopt (argc, argv, "fo")) != -1)
{
switch (opt)
{
case 'f': do_flush = 1; break;
case 'o': do_fopen = 1; break;
}
}
fp = fopen (fname, "w");
written = fwrite ("abcabc", 1, 6, fp);
assert (written == 6);
fclose (fp);
if (do_fopen)
fp = fopen (fname, "a");
else
{
int fd = open (fname, O_WRONLY, 0);
assert (fd != -1);
fp = fdopen (fd, "a");
}
assert (fp != NULL);
written = fwrite ("ghi", 1, 3, fp);
assert (written == 3);
if (do_flush)
fflush (NULL);
off = ftello (fp);
assert (off == 9);
return 0;
}
/* --- cut --- */
--
You are receiving this mail because:
You are on the CC list for the bug.