summaryrefslogtreecommitdiff
path: root/src/string/strerror.c
blob: 5f83b2c4470e22c6cdbd30837cbc806f15d5abf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "_safety.h"
#include "_readonly.h"

/** convert error number to string **/

char * strerror(int errnum)
{
	static char *errstr = NULL;

	SIGNAL_SAFE(0);

	if (errstr == NULL) {
		errstr = __readonly(RO_ALLOC, "strerror");
	}

	__readonly(RO_UNLOCK, errstr);

	switch (errnum) {
	#include "_strerror.h"
	default:
		sprintf(errstr, "unknown error [%d]", errnum);
		break;
	}

	__readonly(RO_LOCK, errstr);

	/*
	RETURN_ALWAYS(a pointer to the message string);
	*/
	return errstr;
}

CHECK_1(char *, 0, strerror, int)

/***
converts the error number ARGUMENT(errnum) to an error message
string. The string returned should not be modified, and may be overwritten by
subsequent calls.
***/

/*
STDC(1)
*/