partial libcore port