This is the mail archive of the libc-alpha@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]

[PATCH][BZ #13152] fmemopen does not honor append mode.


Hi,

As I read
http://sourceware.org/bugzilla/show_bug.cgi?id=13152
if I understand correctly a correct behaviour should be like 
calling fmemopen starting at end of string.  This patch does exactly that.

This is not completely backward compatible. Do some applications depend 
on this broken behaviour?

	* libio/fmemopen.c (fmemopen): Honor append mode.
---
 libio/fmemopen.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libio/fmemopen.c b/libio/fmemopen.c
index 726ebd1..b32414c 100644
--- a/libio/fmemopen.c
+++ b/libio/fmemopen.c
@@ -240,15 +240,18 @@ fmemopen (void *buf, size_t len, const char *mode)
 	c->buffer[0] = '\0';
 
       c->maxpos = strnlen (c->buffer, len);
+
+      if (mode[0] == 'a')
+	{
+	  len -= c->maxpos;
+	  c->buffer += c->maxpos;
+	  c->maxpos = 0;
+	}
     }
 
+  c->pos = 0;
   c->size = len;
 
-  if (mode[0] == 'a')
-    c->pos = c->maxpos;
-  else
-    c->pos = 0;
-
   c->binmode = mode[0] && mode[1 + (mode[1] == '+')] == 'b';
 
   iof.read = fmemopen_read;
-- 
1.7.4.4


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