about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-08-29 07:42:08 +0000
committerJakub Jelinek <jakub@redhat.com>2008-08-29 07:42:08 +0000
commit315a43aa949b25896c511fa6e2efd6be57e2e01d (patch)
tree625aa5d40df04b92dcd3bd8128d30e52a45975ac /libio
parent2fb513c60061821c7e5e7fb6014d2afd0308b7e9 (diff)
downloadglibc-315a43aa949b25896c511fa6e2efd6be57e2e01d.tar.gz
glibc-315a43aa949b25896c511fa6e2efd6be57e2e01d.tar.xz
glibc-315a43aa949b25896c511fa6e2efd6be57e2e01d.zip
Updated to fedora-glibc-20080828T1623 cvs/fedora-glibc-2_8_90-12
Diffstat (limited to 'libio')
-rw-r--r--libio/fmemopen.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libio/fmemopen.c b/libio/fmemopen.c
index f3b280092c..b618ce585d 100644
--- a/libio/fmemopen.c
+++ b/libio/fmemopen.c
@@ -1,7 +1,7 @@
 /* Fmemopen implementation.
-   Copyright (C) 2000, 2002, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2002, 2005, 2006, 2008 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by  Hanno Mueller, kontakt@hanno.de, 2000.
+   Contributed by Hanno Mueller, kontakt@hanno.de, 2000.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -82,6 +82,7 @@ struct fmemopen_cookie_struct
 {
   char *buffer;
   int mybuffer;
+  int binmode;
   size_t size;
   _IO_off64_t pos;
   size_t maxpos;
@@ -120,7 +121,7 @@ fmemopen_write (void *cookie, const char *b, size_t s)
 
   c = (fmemopen_cookie_t *) cookie;
 
-  addnullc = s == 0 || b[s - 1] != '\0';
+  addnullc = c->binmode == 0 && (s == 0 || b[s - 1] != '\0');
 
   if (c->pos + s + addnullc > c->size)
     {
@@ -165,7 +166,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w)
       break;
 
     case SEEK_END:
-      np = c->maxpos - *p;
+      np = (c->binmode ? c->size : c->maxpos) - *p;
       break;
 
     default:
@@ -248,6 +249,8 @@ fmemopen (void *buf, size_t len, const char *mode)
   else
     c->pos = 0;
 
+  c->binmode = mode[0] != '\0' && mode[1] == 'b';
+
   iof.read = fmemopen_read;
   iof.write = fmemopen_write;
   iof.seek = fmemopen_seek;