Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

strerror — describe an error code

strerror converts an error code to a message. The returned text depends on the implementation and locale.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <string.h>
char *strerror(int errnum);

strerror(errnum) from <string.h> returns a message for any int value, usually obtained from errno. It describes a code; it does not detect operation failure.

Despite the char * return type, do not modify the returned array. A subsequent call to strerror may overwrite the array's contents. Do not use the returned pointer after the thread that obtained it exits. If you need the text after another call or after that thread exits, copy it beforehand.

Concurrent calls may cause data races. Do not assume specific message wording. The example passes EDOM without deliberately causing an error.

Examples

#include <errno.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    const char *message = strerror(EDOM);
    printf("message_available=%d\n", message != NULL && message[0] != '\0');
    return 0;
}

Result

message_available=1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources