blob: cbada131f405eea51c1652cdc79a268701d9fc33 (
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
|
#include <string.h>
/** concatenate bounded string **/
errno_t strncat_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n)
{
__C_EXT(1, 201112L);
//__ASSERT_NONNULL(s1);
//__ASSERT_NONNULL(s2);
//__ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2));
char *append = s1 + strlen(s1);
for (size_t i = 0; i < n; i++) {
*append = s2[i];
if (*append == '\0') {
break;
}
append++;
}
if (append[-1] != '\0') {
*append = '\0';
}
return s1;
}
/***
The fn(strncat) function appends a copy of the frist arg(n) bytes of the string
at arg(s2) to the end of the string at arg(s1). The first byte of arg(s2) will
overwrite the terminating null character of arg(s1). No characters after the
first char(\0) will be copied. The resulting string will always be null
terminated.
***/
/* UNSPECIFIED: - */
/* UNDEFINED: arg(s1) and arg(s2) overlap */
/* IMPLEMENTATION: - */
/* LOCALE: - */
/* RETURN: the value of arg(s1) */
/*
CEXT1(201112)
*/
|