On 22.07.2014 21:08, Andrey Chernov wrote:
> On 22.07.2014 20:44, Andrey Chernov wrote:
>> Producing physical writes on ftell cause great performance degradation.
>> You should check for __SAPP flag before calling sflush to do this only
>> for append-mode files.
> 
> BTW, I believe that sflush() should be completely eliminated even for
> _SAPP case. Something like that instead:

Proper patch to the old version:

--- ftell.c.bak 2014-07-22 21:25:46.000000000 +0400
+++ ftell.c     2014-07-22 21:28:01.000000000 +0400
@@ -118,6 +118,11 @@
                if (HASUB(fp))
                        pos -= fp->_r;  /* Can be negative at this point. */
        } else if ((fp->_flags & __SWR) && fp->_p != NULL) {
+               if (fp->_flags & __SAPP) {
+                       pos = _sseek(fp, (fpos_t)0, SEEK_END);
+                       if (pos == -1)
+                               return (1);
+               }
                /*
                 * Writing.  Any buffered characters cause the
                 * position to be greater than that in the

Forget the code below, it breaks reading:

> if (fp->_flags & __SAPP) {
>       pos = _sseek(fp, (fpos_t)0, SEEK_END);
>       if (pos == -1)
>               return (1);
> } else if (fp->_flags & __SOFF)
>       pos = fp->_offset;
> else {
>         pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
>       if (pos == -1)
>               return (1);
> }
> 
>>
>> On 22.07.2014 20:19, Pedro F. Giffuni wrote:
>>> Author: pfg
>>> Date: Tue Jul 22 16:19:01 2014
>>> New Revision: 268984
>>> URL: http://svnweb.freebsd.org/changeset/base/268984
>>>
>>> Log:
>>>   ftello: return 1 when seeking offset on an append stream.
>>>   
>>>   Obtained from:    Apple Inc. (Libc 997.90.3)
>>>   Phabric:  D442
>>>   MFC after:        2 weeks
>>>
>>> Modified:
>>>   head/lib/libc/stdio/ftell.c
>>>
>>> Modified: head/lib/libc/stdio/ftell.c
>>> ==============================================================================
>>> --- head/lib/libc/stdio/ftell.c     Tue Jul 22 16:10:56 2014        
>>> (r268983)
>>> +++ head/lib/libc/stdio/ftell.c     Tue Jul 22 16:19:01 2014        
>>> (r268984)
>>> @@ -97,6 +97,8 @@ _ftello(FILE *fp, fpos_t *offset)
>>>      * Find offset of underlying I/O object, then
>>>      * adjust for buffered bytes.
>>>      */
>>> +   if (__sflush(fp))       /* may adjust seek offset on append stream */
>>> +           return (1);
>>>     if (fp->_flags & __SOFF)
>>>             pos = fp->_offset;
>>>     else {
>>>
>>
>>
> 
> 


-- 
http://ache.vniz.net/
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to