If BUF is null, return the size of buffer required.