summaryrefslogblamecommitdiff
path: root/src/string/strerror_r.c
blob: 907dcf079a9a39c977ef52523c4fb564676f5217 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12





                                                 





                                                   
                              

                              

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

int strerror_r(int err, char *buf, size_t buflen)
{
	char *msg = strerror(err);
	size_t l = strlen(msg);
	if (l >= buflen) {
		if (buflen) {
			memcpy(buf, msg, buflen-1);
			buf[buflen-1] = 0;
		}
		return ERANGE;
	}
	memcpy(buf, msg, l+1);
	return 0;
}