strerror_r()
QNX SDP8.0C Library ReferenceAPIDeveloper
Convert an error number into an error message (reentrant)
Synopsis:
#include <string.h>
int strerror_r( int errnum,
char *strerrbuf,
size_t buflen );
Arguments:
- errnum
- The error number that you want the message for. This function works for any valid errno value.
- strerrbuf
- A pointer to a buffer where the function can store the error message.
- buflen
- The length of the buffer, in bytes.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The strerror_r() function maps the error number contained in errnum to an error message, which it stores in the buffer that strerrbuf points to.
Returns:
- 0
- Success.
- EINVAL
- The value of errnum isn't a valid error number.
- ERANGE
- The buffer pointed to by strerrbuf isn't big enough to hold the generated message string.
Examples:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#define MSG_LEN 100
int main( void )
{
FILE *fp;
char msg_buff[MSG_LEN];
int error_num;
fp = fopen( "file.name", "r" );
if( fp == NULL ) {
error_num = strerror_r ( errno, msg_buff, MSG_LEN);
switch (error_num) {
case 0:
printf( "Unable to open file: %s\n", msg_buff);
break;
case EINVAL:
printf ( "strerror_r() failed: invalid error code, %d\n",
error_num);
break;
case ERANGE:
printf ( "strerror_r() failed: buffer too small: %d\n",
MSG_LEN);
break;
}
}
return EXIT_SUCCESS;
}
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |
Page updated: