| Summary: | fmemopen does not honor append mode | ||
|---|---|---|---|
| Product: | glibc | Reporter: | Rich Felker <bugdal> |
| Component: | stdio | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | adhemerval.zanella, mtk.manpages |
| Priority: | P2 | Flags: | fweimer:
security-
|
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Host: | Target: | ||
| Build: | Last reconfirmed: | ||
| Project(s) to access: | ssh public key: | ||
|
Description
Rich Felker
2011-09-05 02:28:10 UTC
Do you have some example code that demonstrates this? 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);
}
I've added the following text to the fmemopen(3) man page, under bugs:
[[
Specifying append mode ("a" or "a+") for
.BR fmemopen ()
sets the initial file position to the first null byte,
but (if the file offset is reset to a location other than
the end of the stream)
does not force subsequent to append at the end of the stream.
]]
This is fixed by fdb7d390dd0d96e4a8239c46f3aa64598b90842b. Closing bug. |