

def read(s, cc):
    f = cc(s)
    fd = f.params[0]
    buf = f.params[1]
    size = f.params[2]
    s.log.function_call(f, 'read(fd={}, ptr={}, size={})', fd, buf, size)
    output = OutputBuffer(s, buf)
    if fd.symbolic:
        raise ValueError('wtf')
    if (fd.value > len(s.files)):
        return f.ret(value=0)
    else:
        file = s.files[fd.value]
        offset = file['offset']
        output = OutputBuffer(s, buf)
        real_fd = None
        if (file['path'] not in ['stdin', 'stdout', 'stderr']):
            real_fd = open(file['path'], 'rb')
        if size.symbolic:
            raise NotImplementedError()
        elif (real_fd is None):
            for i in xrange(0, size.value):
                b = bv.Symbol(8, 'file_{}_{:x}'.format(fd.value, offset))
                output.append(b)
                file['bytes'][offset] = b
                offset += 1
        else:
            real_fd.seek(offset, 0)
            for i in range(0, size.value):
                byte = real_fd.read(1)
                if (len(byte) == 1):
                    if (byte == '#'):
                        b = bv.Symbol(8, 'file_{}_{:x}'.format(fd.value, offset))
                    else:
                        b = bv.Constant(8, ord(byte))
                    output.append(b)
                    file['bytes'][offset] = b
                    offset += 1
                else:
                    break
        file['offset'] = offset
        if (real_fd is not None):
            real_fd.close()
    return f.ret(value=size)

dataset/ETHPy150Open c01db33f/concolica/library_emulation/unix.py read/original