Lots of C APIs that you might want to call from julia uses a special thread local global integer errno
to indicate errors because C only allows one return value and does not provide exceptions to indicate errors. Usually the function interface will define a special return value to indicate an error, and let set errno
to a number that represents an index into an array of standard error messages. Some functions, like unix strtoul
, do not have a special value to indicate error, but says it will change errno to an appropriate value if an error is encountered. This will require a cautious programmer to set errno = 0;
before calling the function and check if it is different from 0
after calling the function.
errno = 0;
arg = strtoul (buf, NULL, 0);
if (errno)
perror ("strtoul");