1 /* Copyright (C) 1993,1997,1998,2000,2001,2002,2005
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 As a special exception, if you link the code in this file with
21 files compiled with a GNU compiler to produce an executable,
22 that does not cause the resulting executable to be covered by
23 the GNU Lesser General Public License. This exception does not
24 however invalidate any other reasons why the executable file
25 might be covered by the GNU Lesser General Public License.
26 This exception applies to code released by its copyright holders
27 in files containing the exception. */
32 #if defined _LIBC || !_G_HAVE_IO_GETLINE_INFO
35 _IO_getline (fp
, buf
, n
, delim
, extract_delim
)
42 return INTUSE(_IO_getline_info
) (fp
, buf
, n
, delim
, extract_delim
,
47 /* Algorithm based on that used by Berkeley pre-4.4 fgets implementation.
49 Read chars into buf (of size n), until delim is seen.
50 Return number of chars read (at most n).
51 Does not put a terminating '\0' in buf.
52 If extract_delim < 0, leave delimiter unread.
53 If extract_delim > 0, insert delim in output. */
56 _IO_getline_info (fp
, buf
, n
, delim
, extract_delim
, eof
)
67 if (__builtin_expect (fp
->_mode
, -1) == 0)
71 _IO_ssize_t len
= fp
->_IO_read_end
- fp
->_IO_read_ptr
;
83 if (extract_delim
> 0)
85 else if (extract_delim
< 0)
86 INTUSE(_IO_sputbackc
) (fp
, c
);
87 if (extract_delim
> 0)
97 if ((_IO_size_t
) len
>= n
)
99 t
= (char *) memchr ((void *) fp
->_IO_read_ptr
, delim
, len
);
102 _IO_size_t old_len
= ptr
-buf
;
103 len
= t
- fp
->_IO_read_ptr
;
104 if (extract_delim
>= 0)
107 if (extract_delim
> 0)
110 memcpy ((void *) ptr
, (void *) fp
->_IO_read_ptr
, len
);
111 fp
->_IO_read_ptr
= t
;
112 return old_len
+ len
;
114 memcpy ((void *) ptr
, (void *) fp
->_IO_read_ptr
, len
);
115 fp
->_IO_read_ptr
+= len
;
122 INTDEF(_IO_getline_info
)
124 #endif /* Defined _LIBC || !_G_HAVE_IO_GETLINE_INFO */