aboutsummaryrefslogtreecommitdiff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile8
-rw-r--r--libio/iofscanf.c50
-rw-r--r--libio/iogetdelim.c6
-rw-r--r--libio/memstream.c35
4 files changed, 26 insertions, 73 deletions
diff --git a/libio/Makefile b/libio/Makefile
index 8d09a5ecce..02426a79c2 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -25,14 +25,14 @@ headers := stdio.h libio.h
routines := \
filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \
- iofopncook iofprintf iofputs iofread iofscanf iofsetpos ioftell \
- iofwrite iogetdelim iogetline iogets iopadn ioprims ioputs \
+ iofopncook iofprintf iofputs iofread iofsetpos ioftell \
+ iofwrite iogetdelim iogetline iogets iopadn iopopen ioprims ioputs \
ioseekoff ioseekpos iosetbuffer iosetvbuf iosprintf ioungetc \
iovsprintf iovsscanf \
\
clearerr feof ferror fgetc fileno fputc freopen fseek getc getchar \
- memstream putc putchar rewind setbuf setlinebuf vasprintf vdprintf \
- vscanf vsnprintf \
+ memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \
+ vdprintf vscanf vsnprintf \
\
libc_fatal
diff --git a/libio/iofscanf.c b/libio/iofscanf.c
deleted file mode 100644
index 512d5e515e..0000000000
--- a/libio/iofscanf.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-Copyright (C) 1993, 1995 Free Software Foundation
-
-This file is part of the GNU IO Library. This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-the resulting executable to be covered by the GNU General Public License.
-This exception does not however invalidate any other reasons why
-the executable file might be covered by the GNU General Public License. */
-
-#include "libioP.h"
-
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-int
-_IO_fscanf
-#ifdef __STDC__
- (_IO_FILE *fp, const char* format, ...)
-#else
-(fp, format, va_alist) _IO_FILE *fp; char *format; va_dcl
-#endif
-{
- int ret;
- va_list args;
- CHECK_FILE (fp, EOF);
- _IO_va_start (args, format);
- ret = _IO_vfscanf (fp, format, args, NULL);
- va_end (args);
- return ret;
-}
-
-weak_alias (_IO_fscanf, fscanf)
diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c
index a6894a5ae6..ecb360b1f5 100644
--- a/libio/iogetdelim.c
+++ b/libio/iogetdelim.c
@@ -79,11 +79,11 @@ _IO_getdelim (lineptr, n, delimiter, fp)
t = (char *) memchr ((void *) fp->_IO_read_ptr, delimiter, len);
if (t != NULL)
len = (t - fp->_IO_read_ptr) + 1;
- /* make enough space for len+1 (for final NUL) bytes. */
+ /* Make enough space for len+1 (for final NUL) bytes. */
needed = cur_len + len + 1;
if (needed > *n)
{
- if (t == NULL && needed < 2 * *n)
+ if (needed < 2 * *n)
needed = 2 * *n; /* Be generous. */
*n = needed;
*lineptr = (char *) realloc (*lineptr, needed);
@@ -97,7 +97,7 @@ _IO_getdelim (lineptr, n, delimiter, fp)
break;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
- lineptr[cur_len] = '\0';
+ (*lineptr)[cur_len] = '\0';
return cur_len;
}
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);
}