Commit 3c1493a8 by H.J. Lu Committed by Jeff Law

linux.mt (IO_OBJECTS): Add iogetline.o.

        * config/linux.mt (IO_OBJECTS): Add iogetline.o.
        * config/linuxlibc1.mt: Ditto.
        * iogetline.c (_IO_getline_info): Renamed from _IO_getline.
        (_IO_getline): Just call _IO_getline_info.
        * isgetline.cc (istream::getline, istream::get, _sb_readline):
        Call _IO_getline_info instead of _IO_getline and get the EOF
        information.
        * sbgetline.cc (streambuf::sgetline): Ditto.
        * libioP.h (_IO_getline_info): New declaration.
        * iogetline.c (_IO_getline): Handle the case when there is no
        buffer.

From-SVN: r18042
parent 365ca18b
Tue Feb 17 21:56:25 1998 H.J. Lu (hjl@gnu.org)
* config/linux.mt (IO_OBJECTS): Add iogetline.o.
* config/linuxlibc1.mt: Ditto.
* iogetline.c (_IO_getline_info): Renamed from _IO_getline.
(_IO_getline): Just call _IO_getline_info.
* isgetline.cc (istream::getline, istream::get, _sb_readline):
Call _IO_getline_info instead of _IO_getline and get the EOF
information.
* sbgetline.cc (streambuf::sgetline): Ditto.
* libioP.h (_IO_getline_info): New declaration.
* iogetline.c (_IO_getline): Handle the case when there is no
buffer.
Fri Feb 13 00:57:20 1998 Krister Walfridsson (cato@df.lth.se) Fri Feb 13 00:57:20 1998 Krister Walfridsson (cato@df.lth.se)
* fileops.c: #include <unistd.h>. * fileops.c: #include <unistd.h>.
......
...@@ -16,7 +16,7 @@ _G_CONFIG_H= ...@@ -16,7 +16,7 @@ _G_CONFIG_H=
LIBIO_INCLUDE= LIBIO_INCLUDE=
# We have those in libc.a. # We have those in libc.a.
IO_OBJECTS= IO_OBJECTS= iogetline.o
STDIO_WRAP_OBJECTS= STDIO_WRAP_OBJECTS=
OSPRIM_OBJECTS= OSPRIM_OBJECTS=
STDIO_OBJECTS= STDIO_OBJECTS=
......
...@@ -11,7 +11,7 @@ LIBIO_INCLUDE= ...@@ -11,7 +11,7 @@ LIBIO_INCLUDE=
# We have those in libc.a. # We have those in libc.a.
IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o \ IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o \
filedoalloc.o fileops.o genops.o iofclose.o \ filedoalloc.o fileops.o genops.o iofclose.o \
iovsprintf.o iovsscanf.o strops.o iovsprintf.o iovsscanf.o strops.o iogetline.o
STDIO_WRAP_OBJECTS= STDIO_WRAP_OBJECTS=
OSPRIM_OBJECTS= OSPRIM_OBJECTS=
STDIO_OBJECTS= STDIO_OBJECTS=
......
/* Copyright (C) 1993, 1997 Free Software Foundation, Inc. /* Copyright (C) 1993, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This file is part of the GNU IO Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
...@@ -26,6 +26,19 @@ ...@@ -26,6 +26,19 @@
#include "libioP.h" #include "libioP.h"
#include <string.h> #include <string.h>
#if defined(_LIBC) || !_G_HAVE_IO_GETLINE_INFO
_IO_size_t
_IO_getline (fp, buf, n, delim, extract_delim)
_IO_FILE *fp;
char *buf;
_IO_size_t n;
int delim;
int extract_delim;
{
return _IO_getline_info (fp, buf, n, delim, extract_delim, (int *) 0);
}
/* Algorithm based on that used by Berkeley pre-4.4 fgets implementation. /* Algorithm based on that used by Berkeley pre-4.4 fgets implementation.
Read chars into buf (of size n), until delim is seen. Read chars into buf (of size n), until delim is seen.
...@@ -35,44 +48,65 @@ ...@@ -35,44 +48,65 @@
If extract_delim > 0, insert delim in output. */ If extract_delim > 0, insert delim in output. */
_IO_size_t _IO_size_t
_IO_getline (fp, buf, n, delim, extract_delim) _IO_getline_info (fp, buf, n, delim, extract_delim, eof)
_IO_FILE *fp; _IO_FILE *fp;
char *buf; char *buf;
_IO_size_t n; _IO_size_t n;
int delim; int delim;
int extract_delim; int extract_delim;
int *eof;
{ {
char *ptr = buf; char *ptr = buf;
if (eof) *eof = 0;
do do
{ {
_IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr; _IO_ssize_t len = fp->_IO_read_end - fp->_IO_read_ptr;
char *t;
if (len <= 0) if (len <= 0)
if (__underflow (fp) == EOF)
break;
else
len = fp->_IO_read_end - fp->_IO_read_ptr;
if ((_IO_size_t) len >= n)
len = n;
t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
if (t != NULL)
{ {
_IO_size_t old_len = ptr-buf; int c = __uflow (fp);
len = t - fp->_IO_read_ptr; if (c == EOF)
if (extract_delim >= 0) {
if (eof) *eof = c;
break;
}
if (c == delim)
{ {
++t;
if (extract_delim > 0) if (extract_delim > 0)
++len; *ptr++ = c;
else if (extract_delim < 0)
_IO_sputbackc (fp, c);
return ptr - buf;
} }
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); *ptr++ = c;
fp->_IO_read_ptr = t; n--;
return old_len + len;
} }
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); else
fp->_IO_read_ptr += len; {
ptr += len; char *t;
n -= len; if ((_IO_size_t) len >= n)
len = n;
t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len);
if (t != NULL)
{
_IO_size_t old_len = ptr-buf;
len = t - fp->_IO_read_ptr;
if (extract_delim >= 0)
{
++t;
if (extract_delim > 0)
++len;
}
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr = t;
return old_len + len;
}
memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
ptr += len;
n -= len;
}
} while (n != 0); } while (n != 0);
return ptr - buf; return ptr - buf;
} }
#endif /* Defined(_LIBC) || !_G_HAVE_IO_GETLINE_INFO */
...@@ -38,8 +38,9 @@ istream& istream::getline(char* buf, int len, char delim) ...@@ -38,8 +38,9 @@ istream& istream::getline(char* buf, int len, char delim)
if (ipfx1()) if (ipfx1())
{ {
streambuf *sb = rdbuf(); streambuf *sb = rdbuf();
_gcount = _IO_getline(sb, buf, len - 1, delim, -1); _gcount = _IO_getline_info(sb, buf, len - 1, delim, -1, &ch);
ch = sb->sbumpc(); if (ch != EOF)
ch = sb->sbumpc();
if (ch == EOF) if (ch == EOF)
set (_gcount == 0 ? (ios::failbit|ios::eofbit) : ios::eofbit); set (_gcount == 0 ? (ios::failbit|ios::eofbit) : ios::eofbit);
else if (ch != (unsigned char) delim) else if (ch != (unsigned char) delim)
...@@ -67,8 +68,9 @@ istream& istream::get(char* buf, int len, char delim) ...@@ -67,8 +68,9 @@ istream& istream::get(char* buf, int len, char delim)
if (ipfx1()) if (ipfx1())
{ {
streambuf *sbuf = rdbuf(); streambuf *sbuf = rdbuf();
long count = _IO_getline(sbuf, buf, len - 1, delim, -1); int ch;
if (count == 0 && sbuf->sgetc() == EOF) long count = _IO_getline_info(sbuf, buf, len - 1, delim, -1, &ch);
if (_gcount == 0 && ch == EOF)
set(ios::failbit|ios::eofbit); set(ios::failbit|ios::eofbit);
else else
_gcount = count; _gcount = count;
...@@ -92,8 +94,10 @@ char *_sb_readline (streambuf *sb, long& total, char terminator) ...@@ -92,8 +94,10 @@ char *_sb_readline (streambuf *sb, long& total, char terminator)
char *ptr; char *ptr;
int ch; int ch;
_IO_size_t count = _IO_getline(sb, buf, CHUNK_SIZE, terminator, -1); _IO_size_t count = _IO_getline_info(sb, buf, CHUNK_SIZE, terminator,
ch = sb->sbumpc(); -1, &ch);
if (ch != EOF)
ch = sb->sbumpc();
long old_total = total; long old_total = total;
total += count; total += count;
if (ch != EOF && ch != terminator) { if (ch != EOF && ch != terminator) {
......
...@@ -417,6 +417,8 @@ extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen, ...@@ -417,6 +417,8 @@ extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int)); extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
int, int, int *));
extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *)); extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
extern double _IO_strtod __P ((const char *, char **)); extern double _IO_strtod __P ((const char *, char **));
extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits, extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
......
...@@ -27,5 +27,5 @@ the executable file might be covered by the GNU General Public License. */ ...@@ -27,5 +27,5 @@ the executable file might be covered by the GNU General Public License. */
long streambuf::sgetline(char* buf, _IO_size_t n, char delim, int extract_delim) long streambuf::sgetline(char* buf, _IO_size_t n, char delim, int extract_delim)
{ {
return _IO_getline(this, buf, n, delim, extract_delim); return _IO_getline_info(this, buf, n, delim, extract_delim, (int *) 0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment