Manually merged prompt.c to upstream