def parse_cstring_from_stream(stream, stream_pos=None):
    " Parse a C-string from the given stream. The string is returned without\n        the terminating \x00 byte. If the terminating byte wasn't found, None\n        is returned (the stream is exhausted).\n        If stream_pos is provided, the stream is seeked to this position before\n        the parsing is done. Otherwise, the current position of the stream is\n        used.\n        Note: a bytes object is returned here, because this is what's read from\n        the binary file.\n    "
    if stream_pos is not None:
        stream.seek(stream_pos)
    CHUNKSIZE = 64
    chunks = []
    found = False
    while True:
        chunk = stream.read(CHUNKSIZE)
        end_index = chunk.find(b'\x00')
        if end_index >= 0:
            chunks.append(chunk[:end_index])
            found = True
            break
        else:
            chunks.append(chunk)
        if len(chunk) < CHUNKSIZE:
            break
    return b''.join(chunks) if found else None
