errno()

A global variable for storing error result.

  #include <errno.h> 
  extern int errno;   
Remarks

Many functions in the standard library return a special value when an error occurs. Often the programmer needs to know about the nature of the error. Some functions provide more detailed error information by assigning a value to the global variable errno. A value of zero specifies that there is no error. A non-zero value specifies that a function encountered an error.

An EWL function only assigns a value to errno when an error occurs. It is the programmer's responsibility to assign 0 to errno before calling a function that uses it.

The table below lists the values that EWL functions use to report an error condition.
Table 1. EWL Date and Time Management Macros
Error Code Description
EDOM A numerical argument is not within the acceptable range of values that a function requires.
EILSEQ An operation to convert to or from a multibyte character sequence could not be completed.
ERANGE A result could not be computed because it would be beyond the range of values that can be stored in its data type.
Listing: Example of errno() Usage

#include <errno.h> 
#include <stdio.h> 
#include <extras.h> 
int main(void) 
{ 
char *num = "999999999999999999999999999999999"; 
long result; 
errno = 0; /* Assume no error. */ 
result = strtol( num, 0, 10); 
if (errno == 0) 
printf("The string as a long is %ld", result); 
else 
printf("Conversion error\n"); 
return 0; 
} 
Output: 
Conversion error