def copy_data(data_length, blocksize, infp, outfp):
    '''
    A utility function to copy data from the input file object to the output
    file object.  This function will use the most efficient copy method available,
    which is often sendfile.
    Parameters:
     data_length - The amount of data to copy.
     blocksize - How much data to copy per iteration.
     infp - The file object to copy data from.
     outfp - The file object to copy data to.
    Returns:
     Nothing.
    '''
    use_sendfile = False
    if have_sendfile:
        try:
            x_unused = infp.fileno()
            y_unused = outfp.fileno()
            use_sendfile = True
        except (AttributeError, io.UnsupportedOperation):
            pass
    if use_sendfile:
        in_offset = infp.tell()
        out_offset = outfp.tell()
        sendfile(outfp.fileno(), infp.fileno(), in_offset, data_length)
        infp.seek(in_offset + data_length)
        outfp.seek(out_offset + data_length)
    else:
        left = data_length
        readsize = blocksize
        while left > 0:
            if left < readsize:
                readsize = left
            data = infp.read(readsize)
            data_len = len(data)
            if data_len != readsize:
                data_len = left
            outfp.write(data)
            left -= data_len