1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if defined(LIBC_SCCS) && !defined(lint) 34static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/stdio/fflush.c 275665 2014-12-10 08:18:22Z delphij $"); |
38 39#include "namespace.h" 40#include <errno.h> 41#include <stdio.h> 42#include "un-namespace.h" 43#include "libc_private.h" 44#include "local.h" 45 --- 73 unchanged lines hidden (view full) --- 119 */ 120 fp->_p = p; 121 fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; 122 123 for (; n > 0; n -= t, p += t) { 124 t = _swrite(fp, (char *)p, n); 125 if (t <= 0) { 126 /* Reset _p and _w. */ |
127 if (p > fp->_p) { 128 /* Some was written. */ |
129 memmove(fp->_p, p, n); |
130 fp->_p += n; 131 if ((fp->_flags & (__SLBF | __SNBF)) == 0) 132 fp->_w -= n; 133 } |
134 fp->_flags |= __SERR; 135 return (EOF); 136 } 137 } 138 return (0); 139} 140 141static int 142sflush_locked(FILE *fp) 143{ 144 int ret; 145 146 FLOCKFILE(fp); 147 ret = __sflush(fp); 148 FUNLOCKFILE(fp); 149 return (ret); 150} |