The proper handling of cases 2 and 4 still need some improvement, perhaps with errno assignment or withby changing the interface to something akin to strtol or, if C++ is allowed, by throwing an exception. Also it might make sense to handle integer overflow errors.