fvwrite.c (947d1011715bdb966f59b6d6a6b39e971c0a08ea) | fvwrite.c (64a965e7078acf9079cbe7f2c001852d4f6f2832) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38#if 0 39static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; 40#endif 41static const char rcsid[] = | 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 --- 25 unchanged lines hidden (view full) --- 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) 38#if 0 39static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; 40#endif 41static const char rcsid[] = |
42 "$Id: fvwrite.c,v 1.6 1997/12/24 13:17:13 ache Exp $"; | 42 "$Id: fvwrite.c,v 1.7 1997/12/24 23:23:18 ache Exp $"; |
43#endif /* LIBC_SCCS and not lint */ 44 45#include <stdio.h> | 43#endif /* LIBC_SCCS and not lint */ 44 45#include <stdio.h> |
46#include <stdlib.h> |
|
46#include <string.h> 47#include "local.h" 48#include "fvwrite.h" 49 50/* 51 * Write some memory regions. Return zero on success, EOF on error. 52 * 53 * This routine is large and unsightly, but most of the ugliness due --- 52 unchanged lines hidden (view full) --- 106 * String output is a special case: write as many bytes 107 * as fit, but pretend we wrote everything. This makes 108 * snprintf() return the number of bytes needed, rather 109 * than the number used, and avoids its write function 110 * (so that the write function can be invalid). 111 */ 112 do { 113 GETIOV(;); | 47#include <string.h> 48#include "local.h" 49#include "fvwrite.h" 50 51/* 52 * Write some memory regions. Return zero on success, EOF on error. 53 * 54 * This routine is large and unsightly, but most of the ugliness due --- 52 unchanged lines hidden (view full) --- 107 * String output is a special case: write as many bytes 108 * as fit, but pretend we wrote everything. This makes 109 * snprintf() return the number of bytes needed, rather 110 * than the number used, and avoids its write function 111 * (so that the write function can be invalid). 112 */ 113 do { 114 GETIOV(;); |
115 if ((fp->_flags & (__SALC | __SSTR)) == 116 (__SALC | __SSTR) && fp->_w < len) { 117 size_t blen = fp->_p - fp->_bf._base; 118 119 /* 120 * Alloc an extra 128 bytes (+ 1 for NULL) 121 * so we don't call realloc(3) so often. 122 */ 123 fp->_w = len + 128; 124 fp->_bf._size = blen + len + 128; 125 fp->_bf._base = 126 realloc(fp->_bf._base, fp->_bf._size + 1); 127 if (fp->_bf._base == NULL) 128 goto err; 129 fp->_p = fp->_bf._base + blen; 130 } |
|
114 w = fp->_w; 115 if (fp->_flags & __SSTR) { 116 if (len < w) 117 w = len; 118 if (w > 0) { 119 COPY(w); /* copy MIN(fp->_w,len), */ 120 fp->_w -= w; 121 fp->_p += w; --- 75 unchanged lines hidden --- | 131 w = fp->_w; 132 if (fp->_flags & __SSTR) { 133 if (len < w) 134 w = len; 135 if (w > 0) { 136 COPY(w); /* copy MIN(fp->_w,len), */ 137 fp->_w -= w; 138 fp->_p += w; --- 75 unchanged lines hidden --- |