This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/13152] fmemopen does not honor append mode
- From: "mtk.manpages at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Fri, 27 Apr 2012 20:48:37 +0000
- Subject: [Bug stdio/13152] fmemopen does not honor append mode
- Auto-submitted: auto-generated
- References: <bug-13152-131@http.sourceware.org/bugzilla/>
http://sourceware.org/bugzilla/show_bug.cgi?id=13152
--- Comment #2 from Michael Kerrisk <mtk.manpages at gmail dot com> 2012-04-27 20:48:37 UTC ---
Okay -- I created an example. See below.
In the below, the "X", should appear at the end of "hello, world", rather than
overwriting the first byte.
$ ./a.out x
Initial ftell(): 12
Resetting file position
New ftell(): 0
Xello, world
=====
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
} while (0)
int
main(int argc, char **argv)
{
char buf[20] = {"hello, world"};
FILE *fp = fmemopen(buf, 20, "a+");
char c;
int j;
printf("Initial ftell(): %ld\n", ftell(fp));
if (argc > 1) {
printf("Resetting file position\n");
fseek(fp, 0, SEEK_SET);
printf("New ftell(): %ld\n", ftell(fp));
}
fflush(fp);
fprintf(fp, "X");
fflush(fp);
printf("%s\n", buf);
}
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.