[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


errno

The errno.h header file provides the global error code variable errno.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <errno.h>
extern int errno;

WARNING!

The math library used for PowerPC Mac OS and Windows (when optimized) is not fully compliant with the 1990 ANSI C standard in that none of the math functions set errno. The MSL math libraries provide better means of error detection. Using fpclassify (which is fully portable) provides a better error reporting mechanism. The setting of errno is considered an obsolete mechanism because it is inefficient as well as un-informative. Further more various math facilities may set errno haphazardly for 68k Mac OS.

Most 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 detailed error information by assigning a value to the global variable errno. The errno variable is declared in the errno.h header file. See "Error number definitions,"

The errno variable is not cleared when a function call is successful; its value is changed only when a function that uses errno returns its own error value. It is the programmer's responsibility to assign 0 to errno before calling a function that uses it. For example usage see Listing 8.1

Error number definitions:

errno value
Description
EDOM  
Domain error. The arguments passed to the function are not within a legal domain. .  
ERANGE  
Range error. The function cannot return a value represented by its type.  
ENOERR  
No Error is equal to zero  
EPOS  
Error in stream position  
ESIGPARM  
Error Signal Paameter  
nonzero value  
Used by some standard C functions.  
Win32 Only
Description
EPERM  
Permission Error  
EACCES  
Permission denied  
EBADF  
Bad file number  
EDEADLOCK  
Resource deadlock will not occur  
EMFILE  
Too many files opened  
ENOENT  
No such file or directory  
ENFILE  
No File  
ENOSPC  
No space left on device  
EINVAL  
Invalid argument  
EIO  
Error on input or output  
ENOMEM  
Not enough memory  
ENOSYS  
Error no system  
ENAMETOOLONG  
The name of the path argument to access() exceedsPATH_MAX.  
BeOS Only
Description
EOK  
EOK is equal to ENOERR  
If _POSIX Defined
Description
EEXIST  
The named file exists  
ENOEMPTY  
The path argument names an entry that is not an empty directory  

errno example:
#include <errno.h>
#include <stdio.h>
#include <extras.h>

int main(void)
{
	char *num = "5000000000";
	long result;
	result = strtol( num, 0, 10);

	if (errno == ERANGE) 
		printf("Range error!\n");
	else
		printf("The string as a long is %ld", result);

	return 0;
}

/* Output:
Range error!
*/


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000