openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsync/3.1.3-r0/rsync-3.1.3/fileio.c
static int write_sparse(int f, int use_seek, OFF_T offset, const char* buf,
                        int len)
{
    int l1 = 0, l2 = 0;
    int ret;

    for (l1 = 0; l1 < len && buf[l1] == 0; l1++)
    {
    }
    for (l2 = 0; l2 < len - l1 && buf[len - (l2 + 1)] == 0; l2++)
    {
    }

    sparse_seek += l1;

    if (l1 == len)
        return len;

    if (sparse_seek)
    {
        if (sparse_past_write >= preallocated_len)
        {
            if (do_lseek(f, sparse_seek, SEEK_CUR) < 0)
                return -1;
        }
        else if (do_punch_hole(f, sparse_past_write, sparse_seek) < 0)
        {
            sparse_seek = 0;
            return -1;
        }
    }
    sparse_seek = l2;
    sparse_past_write = offset + len - l2;

    if (use_seek)
    {
        /* The in-place data already matches. */
        if (do_lseek(f, len - (l1 + l2), SEEK_CUR) < 0)
            return -1;
        return len;
    }

    while ((ret = write(f, buf + l1, len - (l1 + l2))) <= 0)
    {
        if (ret < 0 && errno == EINTR)
            continue;
        sparse_seek = 0;
        return ret;
    }

    if (ret != (int)(len - (l1 + l2)))
    {
        sparse_seek = 0;
        return l1 + ret;
    }

    return len;
}
/* Note that the offset is just the caller letting us know where
 * the current file position is in the file. The use_seek arg tells
 * us that we should seek over matching data instead of writing it. */
Note that the offset is just the caller letting us know where
the current file position is in the file. The use_seek arg tells
us that we should seek over matching data instead of writing it.
Note that the offset is just the caller letting us know where the current file position is in the file . The use_seek arg tells us that we should seek over matching data instead of writing it .
static int write_sparse(int f, int use_seek, OFF_T offset, const char* buf,
                        int len)
{
    int l1 = 0, l2 = 0;
    int ret;
    for (l1 = 0; l1 < len && buf[l1] == 0; l1++)
    {
    }
    for (l2 = 0; l2 < len - l1 && buf[len - (l2 + 1)] == 0; l2++)
    {
    }
    sparse_seek += l1;
    if (l1 == len)
        return len;
    if (sparse_seek)
    {
        if (sparse_past_write >= preallocated_len)
        {
            if (do_lseek(f, sparse_seek, SEEK_CUR) < 0)
                return -1;
        }
        else if (do_punch_hole(f, sparse_past_write, sparse_seek) < 0)
        {
            sparse_seek = 0;
            return -1;
        }
    }
    sparse_seek = l2;
    sparse_past_write = offset + len - l2;
    if (use_seek)
    {
        if (do_lseek(f, len - (l1 + l2), SEEK_CUR) < 0)
            return -1;
        return len;
    }
    while ((ret = write(f, buf + l1, len - (l1 + l2))) <= 0)
    {
        if (ret < 0 && errno == EINTR)
            continue;
        sparse_seek = 0;
        return ret;
    }
    if (ret != (int)(len - (l1 + l2)))
    {
        sparse_seek = 0;
        return l1 + ret;
    }
    return len;
}
static int write_sparse ( int f , int use_seek , OFF_T offset , const char * buf , int len ) { int l1 = 0 , l2 = 0 ; int ret ; for ( l1 = 0 ; l1 < len && buf [ l1 ] == 0 ; l1 ++ ) { } for ( l2 = 0 ; l2 < len - l1 && buf [ len - ( l2 + 1 ) ] == 0 ; l2 ++ ) { } sparse_seek += l1 ; if ( l1 == len ) return len ; if ( sparse_seek ) { if ( sparse_past_write >= preallocated_len ) { if ( do_lseek ( f , sparse_seek , SEEK_CUR ) < 0 ) return -1 ; } else if ( do_punch_hole ( f , sparse_past_write , sparse_seek ) < 0 ) { sparse_seek = 0 ; return -1 ; } } sparse_seek = l2 ; sparse_past_write = offset + len - l2 ; if ( use_seek ) { if ( do_lseek ( f , len - ( l1 + l2 ) , SEEK_CUR ) < 0 ) return -1 ; return len ; } while ( ( ret = write ( f , buf + l1 , len - ( l1 + l2 ) ) ) <= 0 ) { if ( ret < 0 && errno == EINTR ) continue ; sparse_seek = 0 ; return ret ; } if ( ret != ( int ) ( len - ( l1 + l2 ) ) ) { sparse_seek = 0 ; return l1 + ret ; } return len ; }
Note that the offset is just the caller letting us know where
 the current file position is in the file.
Note that the offset is just the caller letting us know where the current file position is in the file .
/* The in-place data already matches. */