summaryrefslogtreecommitdiff
path: root/libio/memstream.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-12-05 03:35:55 +0000
committerRoland McGrath <roland@gnu.org>1995-12-05 03:35:55 +0000
commit77a58cad3fa0a286bd2581187a2463a762d711ba (patch)
tree50756d67e82e3edbe49f722662b0bed8c0cd19cc /libio/memstream.c
parentb5a08c5aca57835de5f69b8b017f09cd75f5cf7d (diff)
Tue Dec 5 02:27:32 1995 Ulrich Drepper <drepper@gnu.ai.mit.edu>
* libio/Makefile [routines]: Remove iofscanf, add iopopen, pclose. * libio/iofscanf.c: Remove file. * libio/iogetdelim.c (_IO_getdelim): Correct stupid bug at string termination. * libio/iopopen.c: New file from GNU libio. * libio/memstream.c: Fixed bug in fclose handling. Instead of providing a close callback we need a finish callback. * libio/pclose.c: New file. Derived from popen.c in GNU libio. * posix/gnu/types.h: Fixed typo. * stdio-common/errnobug.c: fputs returns EOF in error case. Do not test for != 0. * stdio-common/printf-parse.h (parse_one_spec): Do not force padding with ' ' if precision is given. Fix by HJ Lu. * stdio-common/printf_fp.c: Fix comment. * stdio-common/tfformat.c, stdio-common/tiformat.c, stdio-common/tstdiomisc.c: New files from GNU libio test suite. * stdio-common/tstgetln.c: Provide ssize_t type when testing libio. * stdio-common/vfprintf.c (outchar): Use PUTC instead of putc. (vfprintf): Cleasr args_type array before using it. When printing 0 as an integer with precision 0 nothing must be written for the number. Based on patch by HJ Lu. * stdio-common/vfscanf.c: Remove fixed input buffer. Now we have a dynamically extended buffer. * stdlib/strtod.c: Merge with version in Linux libc. This fixes some bugs with handling of very small numbers and has different solution for formaer patches. * sysdeps/i386/i586/add_n.S, sysdeps/i386/i586/sub_n.S: Rename macros r1 and r2 to t1, and t2 resp. This is necessary because glibc headers also define r1. Tue Dec 5 02:27:32 1995 Ulrich Drepper <drepper@gnu.ai.mit.edu> * libio/Makefile [routines]: Remove iofscanf, add iopopen, pclose. * libio/iofscanf.c: Remove file. * libio/iogetdelim.c (_IO_getdelim): Correct stupid bug at string termination. * libio/iopopen.c: New file from GNU libio. * libio/memstream.c: Fixed bug in fclose handling. Instead of providing a close callback we need a finish callback. * libio/pclose.c: New file. Derived from popen.c in GNU libio. * posix/gnu/types.h: Fixed typo. * stdio-common/errnobug.c: fputs returns EOF in error case. Do not test for != 0. * stdio-common/printf-parse.h (parse_one_spec): Do not force padding with ' ' if precision is given. Fix by HJ Lu. * stdio-common/printf_fp.c: Fix comment. * stdio-common/tfformat.c, stdio-common/tiformat.c, stdio-common/tstdiomisc.c: New files from GNU libio test suite. * stdio-common/tstgetln.c: Provide ssize_t type when testing libio. * stdio-common/vfprintf.c (outchar): Use PUTC instead of putc. (vfprintf): Cleasr args_type array before using it. When printing 0 as an integer with precision 0 nothing must be written for the number. Based on patch by HJ Lu. * stdio-common/vfscanf.c: Remove fixed input buffer. Now we have a dynamically extended buffer. * stdlib/strtod.c: Merge with version in Linux libc. This fixes some bugs with handling of very small numbers and has different solution for formaer patches. * sysdeps/i386/i586/add_n.S, sysdeps/i386/i586/sub_n.S: Rename macros r1 and r2 to t1, and t2 resp. This is necessary because glibc headers also define r1.
Diffstat (limited to 'libio/memstream.c')
-rw-r--r--libio/memstream.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/libio/memstream.c b/libio/memstream.c
index b1cefb0959..71519a5190 100644
--- a/libio/memstream.c
+++ b/libio/memstream.c
@@ -30,13 +30,13 @@ struct _IO_FILE_memstream
static int _IO_mem_sync __P ((_IO_FILE* fp));
-static int _IO_mem_close __P ((_IO_FILE* fp));
+static void _IO_mem_finish __P ((_IO_FILE* fp));
static const struct _IO_jump_t _IO_mem_jumps =
{
JUMP_INIT_DUMMY,
- JUMP_INIT (finish, _IO_str_finish),
+ JUMP_INIT (finish, _IO_mem_finish),
JUMP_INIT (overflow, _IO_str_overflow),
JUMP_INIT (underflow, _IO_str_underflow),
JUMP_INIT (uflow, _IO_default_uflow),
@@ -51,7 +51,7 @@ static const struct _IO_jump_t _IO_mem_jumps =
JUMP_INIT (read, _IO_default_read),
JUMP_INIT (write, _IO_default_write),
JUMP_INIT (seek, _IO_default_seek),
- JUMP_INIT (close, _IO_mem_close),
+ JUMP_INIT (close, _IO_default_close),
JUMP_INIT (stat, _IO_default_stat)
};
@@ -79,6 +79,9 @@ open_memstream (bufloc, sizeloc)
fp->_sf._s._allocate_buffer = (_IO_alloc_type) malloc;
fp->_sf._s._free_buffer = (_IO_free_type) free;
+ fp->bufloc = bufloc;
+ fp->sizeloc = sizeloc;
+
return &fp->_sf._f;
}
@@ -102,28 +105,28 @@ _IO_mem_sync (fp)
else
*fp->_IO_write_ptr = '\0';
- *mp->bufloc = fp->_IO_buf_base;
- *mp->sizeloc = _IO_blen (fp);
+ *mp->bufloc = fp->_IO_write_base;
+ *mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base;
return 0;
}
-static int _IO_mem_close (fp)
+static void
+_IO_mem_finish (fp)
_IO_FILE* fp;
{
struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp;
- int res;
- res = _IO_default_close (fp);
- if (res < 0)
- return res;
+ *mp->bufloc = (char *) realloc (fp->_IO_write_base,
+ fp->_IO_write_ptr - fp->_IO_write_base + 1);
+ if (*mp->bufloc != NULL)
+ {
+ (*mp->bufloc)[fp->_IO_write_ptr - fp->_IO_write_base] = '\0';
+ *mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base;
+ }
- *mp->bufloc = (char *) realloc (fp->_IO_buf_base, _IO_blen (fp) + 1);
- if (*mp->bufloc == NULL)
- return -1;
- (*mp->bufloc)[_IO_blen (fp)] = '\0';
- *mp->sizeloc = _IO_blen (fp);
+ fp->_IO_buf_base = NULL;
- return 0;
+ _IO_default_finish (fp);
}