Error handling code for any general function follows this template Two questions from my end--
Code:
#define FAILURE 0 //or shall it be 1 for success and 0 for failure
#define SUCCESS 1
int DoSomething() {
int status = FAILURE; //or shall we assign success by default?
if (error1)
return FAIL_A
if (error2)
return FAIL_B
return SUCCESS;
}
int GetItDone() {
status = FAIL;
Status = DoSomething();
if (PASS != status) //likewise many calls can happen later
goto END;
END:
return status;
}
The status bubble up through function calls.
The convention is 0 for success, negative values for various failures, and positive values for predicated successes.
Of these, returning 0 for success is the most frequently observed: doing otherwise would be idiosyncratic.
As for your code, setting the status to a failure code initially and changing it to success as appropriate will afford more program stability.