I’m currently writing a C function that return a time_t value but I need to manage error cases (because this function uses I/O functions) too.
Is it correct to use (time_t) -1 as an error indicator?
I’m currently writing a C function that return a time_t value but I need
Share
Using
(time_t)-1is already used bytime()function to report a failure so does not seem an unreasonable choice:However, if it is necessary for the caller to differentiate between a time related failure or an IO related failure (or specific IO failures) you may consider adding a status type argument to your function that can be used to return additional information about the failure.