c222390ea23b153dde3e2cc9eae07c200738cfa1
1 /* @(#)fgetline.c 1.13 14/03/27 Copyright 1986, 1996-2014 J. Schilling */
3 * Copyright (c) 1986, 1996-2014 J. Schilling
5 * This is an interface that exists in the public since 1982.
6 * The POSIX.1-2008 standard did ignore POSIX rules not to
7 * redefine existing public interfaces and redefined the interfaces
8 * forcing us to add a js_*() prefix to the original functions.
11 * The contents of this file are subject to the terms of the
12 * Common Development and Distribution License, Version 1.0 only
13 * (the "License"). You may not use this file except in compliance
16 * See the file CDDL.Schily.txt in this distribution for details.
17 * A copy of the CDDL is also available via the Internet at
18 * http://www.opensource.org/licenses/cddl1.txt
20 * When distributing Covered Code, include this CDDL HEADER in each
21 * file and include the License file CDDL.Schily.txt from this distribution.
24 #define fgetline __no__fgetline__
25 #define getline __no__getline__
29 #ifndef NO_GETLINE_COMPAT /* Define to disable backward compatibility */
32 #ifdef HAVE_PRAGMA_WEAK
33 #pragma weak fgetline = js_fgetline
34 #pragma weak getline = js_getline
37 EXPORT
int fgetline
__PR((FILE *, char *, int));
38 EXPORT
int getline
__PR((char *, int));
46 return (js_fgetline(f
, buf
, len
));
54 return (js_fgetline(stdin
, buf
, len
));
60 * XXX should we check if HAVE_USG_STDIO is defined and
61 * XXX use something line memccpy to speed things up ???
62 * XXX On Solaris 64 bits, we may use #define FAST_GETC_PUTC
63 * XXX and getc_unlocked()
65 #if !defined(getc) && defined(USE_FGETS_FOR_FGETLINE)
66 #include <schily/string.h>
69 js_fgetline(f
, buf
, len
)
74 char *bp
= fgets(buf
, len
, f
);
80 if (bp
[len
-1] == '\n')
91 js_fgetline(f
, buf
, len
)
96 register int c
= '\0';
97 register char *bp
= buf
;
98 register int nl
= '\n';
100 down2(f
, _IOREAD
, _IORW
);
103 if ((c
= getc(f
)) < 0)
112 * Read up to end of line
114 while ((c
= getc(f
)) >= 0 && c
!= nl
)
123 * If buffer is empty and we hit EOF, return EOF
125 if (c
< 0 && bp
== buf
)
137 return (js_fgetline(stdin
, buf
, len
));