Update contrib.
3 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
7 /* No user fns here. Pesch 15apr92. */
10 * Copyright (c) 1990 The Regents of the University of California.
11 * All rights reserved.
13 * Redistribution and use in source and binary forms are permitted
14 * provided that the above copyright notice and this paragraph are
15 * duplicated in all such forms and that any documentation,
16 * advertising materials, and other materials related to such
17 * distribution and use acknowledge that the software was developed
18 * by the University of California, Berkeley. The name of the
19 * University may not be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 #include <sys/types.h>
30 #include <sys/unistd.h>
35 * Allocate a file buffer, or switch to unbuffered I/O.
36 * Per the ANSI C standard, ALL tty devices default to line buffered.
38 * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
39 * optimization) right after the _fstat() that finds the buffer size.
43 __smakebuf (register FILE *fp)
45 register size_t size, couldbetty;
49 if (fp->_flags & __SNBF)
51 fp->_bf._base = fp->_p = fp->_nbuf;
55 if (fp->_file < 0 || _fstat_r (fp->_data, fp->_file, &st) < 0)
59 /* do not try to optimise fseek() */
64 couldbetty = (st.st_mode & S_IFMT) == S_IFCHR;
65 size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize;
67 * Optimize fseek() only if it is a regular file.
68 * (The test for __sseek is mainly paranoia.)
70 if ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek)
73 fp->_blksize = st.st_blksize;
78 if ((p = _malloc_r (fp->_data, size)) == NULL)
81 fp->_bf._base = fp->_p = fp->_nbuf;
86 fp->_data->__cleanup = _cleanup_r;
88 fp->_bf._base = fp->_p = (unsigned char *) p;
90 if (couldbetty && isatty (fp->_file))