In C you could do just the same: https://uecker.codeberg.page/2026-10-24.html Whether you should is a different question.
In any case, you can not change the API of an existing function. But returning NULL for error has required by POSIX would have been just fine.