10 __ssputs_r (struct _reent
*ptr
,
18 if (len
>= w
&& fp
->_flags
& (__SMBF
| __SOPT
)) {
19 /* must be asprintf family */
21 int curpos
= (fp
->_p
- fp
->_bf
._base
);
22 /* Choose a geometric growth factor to avoid
23 * quadratic realloc behavior, but use a rate less
24 * than (1+sqrt(5))/2 to accomodate malloc
25 * overhead. asprintf EXPECTS us to overallocate, so
26 * that it can add a trailing \0 without
27 * reallocating. The new allocation should thus be
28 * max(prev_size*1.5, curpos+len+1). */
29 int newsize
= fp
->_bf
._size
* 3 / 2;
30 if (newsize
< curpos
+ len
+ 1)
31 newsize
= curpos
+ len
+ 1;
32 if (fp
->_flags
& __SOPT
)
34 /* asnprintf leaves original buffer alone. */
35 str
= (unsigned char *)_malloc_r (ptr
, newsize
);
38 memcpy (str
, fp
->_bf
._base
, curpos
);
39 fp
->_flags
= (fp
->_flags
& ~__SOPT
) | __SMBF
;
43 str
= (unsigned char *)_realloc_r (ptr
, fp
->_bf
._base
,
46 /* Free unneeded buffer. */
47 _free_r (ptr
, fp
->_bf
._base
);
52 fp
->_p
= str
+ curpos
;
53 fp
->_bf
._size
= newsize
;
55 fp
->_w
= newsize
- curpos
;
59 memmove ((void *) fp
->_p
, (void *) buf
, (size_t) (w
));
66 _REENT_ERRNO(ptr
) = ENOMEM
;