From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8128 invoked by alias); 28 Apr 2012 02:21:18 -0000 Received: (qmail 8119 invoked by uid 22791); 28 Apr 2012 02:21:17 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO sourceware.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 28 Apr 2012 02:20:58 +0000 From: "mtk.manpages at gmail dot com" To: glibc-bugs@sources.redhat.com Subject: [Bug stdio/13151] fmemopen streams fail to read eof Date: Sat, 28 Apr 2012 02:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mtk.manpages at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: drepper.fsp at gmail dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00368.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=13151 --- Comment #3 from Michael Kerrisk 2012-04-28 02:20:55 UTC --- I tested a little more. See the code below. The problem seems to occur only when the specified size of the buffer does not include a null byte. If the specified size does include a null byte, then the file position is correctly set to the first null byte. The standard does clearly cover both cases: [[ The stream maintains a current position in the buffer. This position is initially set to either the beginning of the buffer (for r and w modes) or to the first null byte in the buffer (for a modes). If no null byte is found in append mode, the initial position is set to one byte after the end of the buffer. ]] Thus, glibc's fmemopen() should be setting the file position to the byte after the end of the supplied string. Instead, it sets the file position to -1. Using the test program below, here's what happens when the specified size includes the null byte: $ ./a.out 15 Initial ftell(): 12 And here's what happens if the specified size doesn't include the null byte: $ ./a.out 10 Initial ftell(): -1 /* fmemopen_a+_file_pos_bug.c */ #define _XOPEN_SOURCE 700 #include #include #include #include #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) #define BSIZE 20 int main(int argc, char **argv) { char buf[BSIZE] = {"hello, world"}; FILE *fp; if (argc < 2) { fprintf(stderr, "Usage: %s [fseek-pos]\n", argv[0]); exit(EXIT_FAILURE); } fp = fmemopen(buf, atoi(argv[1]), "a+"); if (fp == NULL) errExit("fmemopen"); printf("Initial ftell(): %ld\n", ftell(fp)); if (argc > 2) { printf("Resetting file position\n"); fseek(fp, atoi(argv[2]), SEEK_SET); printf("New ftell(): %ld\n", ftell(fp)); } } -- 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.