PatchworkOS
Loading...
Searching...
No Matches
strerror_s.c
Go to the documentation of this file.
2#include <errno.h>
3#include <stdint.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
9
10errno_t strerror_s(char* s, rsize_t maxsize, errno_t errnum)
11{
12 size_t len = strerrorlen_s(errnum);
13
14 if (s == NULL || maxsize > RSIZE_MAX || maxsize == 0)
15 {
17 return EINVAL;
18 }
19
20 if (len < maxsize)
21 {
22 strcpy(s, strerror(errnum));
23 }
24 else
25 {
26 strncpy(s, strerror(errnum), maxsize - 1);
27
28 if (maxsize > 3)
29 {
30 strcpy(&s[maxsize - 4], "...");
31 }
32 else
33 {
34 s[maxsize - 1] = '\0';
35 }
36 }
37
38 return 0;
39}
constraint_handler_t _constraintHandler
#define _CONSTRAINT_VIOLATION(e)
int errno_t
Definition errno_t.h:4
#define EINVAL
Invalid argument.
Definition errno.h:142
#define NULL
Pointer error value.
Definition NULL.h:23
__SIZE_TYPE__ rsize_t
Definition rsize_t.h:4
errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum)
Definition strerror_s.c:10
size_t strerrorlen_s(errno_t errnum)
_PUBLIC char * strerror(int errnum)
Definition strerror.c:6
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
Definition strncpy.c:3
_PUBLIC char * strcpy(char *_RESTRICT s1, const char *_RESTRICT s2)
Definition strcpy.c:3