This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/13152] fmemopen does not honor append mode


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]