summaryrefslogtreecommitdiff
path: root/src/string
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-30 15:29:55 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-30 15:29:55 -0500
commit9b6f6642ee252a9bedbe267fd85376fc9359c74f (patch)
tree5676ac47d416ef56b8134d94df49110abc53998f /src/string
parent7f9129145f2293cb8c9052ff1f395226421b0ae4 (diff)
update standard and safety checks
Diffstat (limited to 'src/string')
-rw-r--r--src/string/_strerror.h4
-rw-r--r--src/string/_strtok.h4
-rw-r--r--src/string/memccpy.c8
-rw-r--r--src/string/memchr.c9
-rw-r--r--src/string/memcmp.c8
-rw-r--r--src/string/memcpy.c10
-rw-r--r--src/string/memcpy_s.c19
-rw-r--r--src/string/memmove.c8
-rw-r--r--src/string/memmove_s.c15
-rw-r--r--src/string/memset.c8
-rw-r--r--src/string/memset_s.c16
-rw-r--r--src/string/strcat.c11
-rw-r--r--src/string/strcat_s.c16
-rw-r--r--src/string/strchr.c9
-rw-r--r--src/string/strcmp.c8
-rw-r--r--src/string/strcoll.c8
-rw-r--r--src/string/strcpy.c13
-rw-r--r--src/string/strcpy_s.c17
-rw-r--r--src/string/strcspn.c8
-rw-r--r--src/string/strdup.c9
-rw-r--r--src/string/strerror.c9
-rw-r--r--src/string/strerror_s.c18
-rw-r--r--src/string/strerrorlen_s.c8
-rw-r--r--src/string/strlen.c8
-rw-r--r--src/string/strncat.c11
-rw-r--r--src/string/strncat_s.c16
-rw-r--r--src/string/strncmp.c8
-rw-r--r--src/string/strncpy.c11
-rw-r--r--src/string/strncpy_s.c16
-rw-r--r--src/string/strnlen_s.c17
-rw-r--r--src/string/strpbrk.c9
-rw-r--r--src/string/strrchr.c9
-rw-r--r--src/string/strspn.c8
-rw-r--r--src/string/strstr.c9
-rw-r--r--src/string/strtok.c9
-rw-r--r--src/string/strtok_s.c24
-rw-r--r--src/string/strxfrm.c10
37 files changed, 136 insertions, 272 deletions
diff --git a/src/string/_strerror.h b/src/string/_strerror.h
index e2d7983f..ef42bd6f 100644
--- a/src/string/_strerror.h
+++ b/src/string/_strerror.h
@@ -109,3 +109,7 @@ case ESRCH: strcpy(errstr, "No such process [ESRCH]"); break;
#ifdef EXDEV
case EXDEV: strcpy(errstr, "Cross-device link [EXDEV]"); break;
#endif
+
+/*
+STDC(0)
+*/
diff --git a/src/string/_strtok.h b/src/string/_strtok.h
index 56ad0dca..4b48dc54 100644
--- a/src/string/_strtok.h
+++ b/src/string/_strtok.h
@@ -1,2 +1,6 @@
(void)state; (void)current;
(void)s1; (void)s2;
+
+/*
+STDC(0)
+*/
diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index 80143e32..17ee0c4b 100644
--- a/src/string/memccpy.c
+++ b/src/string/memccpy.c
@@ -1,9 +1,10 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
void *memccpy(void * restrict s1, const void * restrict s2, int c, size_t n)
{
+ SIGNAL_SAFE(0);
+
unsigned char *dst = s1;
const unsigned char *src = s2;
size_t i = 0;
@@ -23,6 +24,3 @@ void *memccpy(void * restrict s1, const void * restrict s2, int c, size_t n)
/*
XOPEN(4)
*/
-
-
-#endif
diff --git a/src/string/memchr.c b/src/string/memchr.c
index 97ef3c36..49965560 100644
--- a/src/string/memchr.c
+++ b/src/string/memchr.c
@@ -1,12 +1,12 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** search memory **/
void * memchr(const void *s, int c, size_t n)
{
+ SIGNAL_SAFE(0);
+
char *p = (char*)s;
size_t i = 0;
@@ -33,6 +33,3 @@ ARGUMENT(c) (converted to an TYPE(unsigned char)).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/memcmp.c b/src/string/memcmp.c
index d00093ea..ddf57089 100644
--- a/src/string/memcmp.c
+++ b/src/string/memcmp.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** compare memory regions **/
@@ -11,6 +9,7 @@ int memcmp(const void *s1, const void *s2, size_t n)
unsigned char *q = (void*)s2;
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -36,6 +35,3 @@ and ARGUMENT(s2).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/memcpy.c b/src/string/memcpy.c
index 7fda569e..cbcb0a75 100644
--- a/src/string/memcpy.c
+++ b/src/string/memcpy.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** copy memory **/
@@ -11,9 +9,10 @@ void * memcpy(void * restrict s1, const void * restrict s2, size_t n)
char *src = (char*)s2;
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
- ASSERT_NOOVERLAP(s1, s2, n);
+ ASSERT_NOOVERLAP(s1, n, s2, n);
for (i = 0; i < n; i++) {
dst[i] = src[i];
@@ -33,6 +32,3 @@ ARGUMENT(s1).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/memcpy_s.c b/src/string/memcpy_s.c
index 2d30921b..07211c4c 100644
--- a/src/string/memcpy_s.c
+++ b/src/string/memcpy_s.c
@@ -1,23 +1,21 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** copy memory **/
errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n)
{
- __C_EXT(1, 201112L);
- __ASSERT_NONNULL(s1);
- __ASSERT_NONNULL(s2);
- __ASSERT_NOOVERLAP(s1, s2, n);
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+ ASSERT_NOOVERLAP(s1, s1max, s2, n);
char *dst = (char*)s1, *src = (char*)s2;
- int i = 0;
+ rsize_t i = 0;
while (i < n) {
dst[i] = src[i];
i++;
}
- return dst;
+ return 0;
}
/***
@@ -35,6 +33,3 @@ arg(s1).
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/memmove.c b/src/string/memmove.c
index 371b0334..0ae3d309 100644
--- a/src/string/memmove.c
+++ b/src/string/memmove.c
@@ -1,12 +1,11 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** move memory **/
void * memmove(void *s1, const void *s2, size_t n)
{
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -37,6 +36,3 @@ is copied so that the ARGUMENT(n) bytes are safely written to ARGUMENT(s1).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/memmove_s.c b/src/string/memmove_s.c
index 343a286d..3dea9080 100644
--- a/src/string/memmove_s.c
+++ b/src/string/memmove_s.c
@@ -1,20 +1,20 @@
-#if 0
-
#include <string.h>
#include <stdlib.h>
-#include "_assert.h"
+#include "_safety.h"
/** move memory **/
errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n)
{
- __ASSERT_NONNULL(s1);
- __ASSERT_NONNULL(s2);
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
if (n > s1max) {
/* do the right thing */
}
- return memmove(s1, s2, n);
+ memmove(s1, s2, n);
+ return 0;
}
/***
@@ -33,6 +33,3 @@ is copied so that the arg(n) bytes are safely written to arg(s1).
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/memset.c b/src/string/memset.c
index 774e4418..68fbca0a 100644
--- a/src/string/memset.c
+++ b/src/string/memset.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** fill memory **/
@@ -10,6 +8,7 @@ void * memset(void *s, int c, size_t n)
unsigned char *p = (unsigned char *)s;
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s);
for (i = 0; i < n; i++) {
@@ -30,6 +29,3 @@ the value ARGUMENT(c) (converted to an TYPE(unsigned char)).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/memset_s.c b/src/string/memset_s.c
index 2784a7c9..0708f338 100644
--- a/src/string/memset_s.c
+++ b/src/string/memset_s.c
@@ -1,21 +1,20 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
/** fill memory **/
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
{
- __C_EXT(1, 201112L);
- __ASSERT_NONNULL(s);
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s);
unsigned char *_s = (unsigned char *)s;
- int i = 0;
+ rsize_t i = 0;
- while (i < n) {
+ while (i < n && i < smax) {
_s[i] = (unsigned char)c;
}
- return s;
+ return 0;
}
/***
@@ -33,6 +32,3 @@ the value arg(c) (converted to an type(unsigned char)).
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strcat.c b/src/string/strcat.c
index 1cc24d1f..3855cff3 100644
--- a/src/string/strcat.c
+++ b/src/string/strcat.c
@@ -1,15 +1,15 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strcat
/** concatenate strings **/
char * strcat(char * restrict s1, const char * restrict s2)
{
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
- ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2));
+ ASSERT_NOOVERLAP(s1, strlen(s1) + strlen(s2), s2, strlen(s2));
/*
RETURN_ALWAYS(ARGUMENT(s1));
@@ -31,6 +31,3 @@ null character of ARGUMENT(s1).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strcat_s.c b/src/string/strcat_s.c
index 7c820daf..40c474df 100644
--- a/src/string/strcat_s.c
+++ b/src/string/strcat_s.c
@@ -1,16 +1,15 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
/** concatenate strings **/
errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2)
{
- __C_EXT(1, 201112L);
- __ASSERT_NONNULL(s1);
- __ASSERT_NONNULL(s2);
- __ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2));
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+ ASSERT_NOOVERLAP(s1, s1max, s2, strlen(s2));
- return strncat(s1, s2, strlen(s2));
+ return 0;
}
/***
@@ -29,6 +28,3 @@ null character of arg(s1).
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strchr.c b/src/string/strchr.c
index 274b55c5..f71c674a 100644
--- a/src/string/strchr.c
+++ b/src/string/strchr.c
@@ -1,12 +1,12 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strchr
/** string search **/
char * strchr(const char *s, int c)
{
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s);
/*
@@ -24,6 +24,3 @@ ARGUMENT(c) (converted to a TYPE(char)).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strcmp.c b/src/string/strcmp.c
index 55796651..b69debc0 100644
--- a/src/string/strcmp.c
+++ b/src/string/strcmp.c
@@ -1,12 +1,11 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** compare strings **/
int strcmp(const char *s1, const char *s2)
{
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -42,6 +41,3 @@ compares the strings at ARGUMENT(s1) and ARGUMENT(s2).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strcoll.c b/src/string/strcoll.c
index d894e011..f70872b7 100644
--- a/src/string/strcoll.c
+++ b/src/string/strcoll.c
@@ -1,8 +1,6 @@
-#if 0
-
#include <stdlib.h>
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** collate strings **/
@@ -12,6 +10,7 @@ int strcoll(const char *s1, const char *s2)
char *x2 = NULL;
int ret = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -43,6 +42,3 @@ compares the collation values of the strings at ARGUMENT(s1) and ARGUMENT(s2).
LC_COLLATE
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strcpy.c b/src/string/strcpy.c
index cfe4fa43..a7785c27 100644
--- a/src/string/strcpy.c
+++ b/src/string/strcpy.c
@@ -1,7 +1,8 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strcpy
+
+#undef strcpy
/** copy string **/
@@ -9,9 +10,10 @@ char * strcpy(char * restrict s1, const char * restrict s2)
{
char *p = s1;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
- ASSERT_NOOVERLAP(s1, s2, strlen(s2));
+ ASSERT_NOOVERLAP(s1, strlen(s2), s2, strlen(s2));
while ((*s1++ = *s2++) != '\0') {
continue;
@@ -31,6 +33,3 @@ including the terminating CHAR(\0).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strcpy_s.c b/src/string/strcpy_s.c
index bfad3189..4fdcc2d4 100644
--- a/src/string/strcpy_s.c
+++ b/src/string/strcpy_s.c
@@ -1,17 +1,17 @@
-#if 0
-
#include <string.h>
#include <limits.h>
+#include "_safety.h"
/** copy string **/
errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2)
{
- __C_EXT(1, 201112L);
- __ASSERT_NONNULL(s1);
- __ASSERT_NONNULL(s2);
- __ASSERT_NOOVERLAP(s1, s2, strlen(s2));
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+ ASSERT_NOOVERLAP(s1, s1max, s2, strlen(s2));
- return strncpy(s1, s2, strlen(s2));
+ strncpy(s1, s2, strlen(s2));
+ return 0;
}
/***
@@ -29,6 +29,3 @@ including the terminating char(\0).
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strcspn.c b/src/string/strcspn.c
index 6dbcbdb0..3438de74 100644
--- a/src/string/strcspn.c
+++ b/src/string/strcspn.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** count non-matching characters **/
@@ -9,6 +7,7 @@ size_t strcspn(const char *s1, const char *s2)
{
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -30,6 +29,3 @@ the string ARGUMENT(s1) that are not in the string ARGUMENT(s2).
RETURN_ALWAYS(the number of non-matching characters);
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strdup.c b/src/string/strdup.c
index 7b97f75d..26362e2f 100644
--- a/src/string/strdup.c
+++ b/src/string/strdup.c
@@ -1,10 +1,12 @@
-#if 0
-
#include <string.h>
#include <stdlib.h>
+#include "_safety.h"
+#undef strdup
char * strdup(const char *s)
{
+ SIGNAL_SAFE(0);
+
size_t len = strlen(s);
char *ret = malloc(len + 1);
if (ret) {
@@ -17,6 +19,3 @@ char * strdup(const char *s)
XOPEN(400)
POSIX(200809)
*/
-
-
-#endif
diff --git a/src/string/strerror.c b/src/string/strerror.c
index bdb1df36..29742e34 100644
--- a/src/string/strerror.c
+++ b/src/string/strerror.c
@@ -1,8 +1,8 @@
-#if 0
-
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include "_safety.h"
+#undef strerror
# define __LONGEST_STRERR 64 /* FIXME */
@@ -12,6 +12,8 @@ char * strerror(int errnum)
{
static char errstr[__LONGEST_STRERR+1];
+ SIGNAL_SAFE(0);
+
switch (errnum) {
#include "_strerror.h"
default:
@@ -34,6 +36,3 @@ subsequent calls.
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strerror_s.c b/src/string/strerror_s.c
index bffc2a5d..c78b0bba 100644
--- a/src/string/strerror_s.c
+++ b/src/string/strerror_s.c
@@ -1,21 +1,12 @@
-#if 0
-
#include <string.h>
#include <errno.h>
-#include "__strerror.h"
+#include "_safety.h"
/** convert error number to string **/
errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum)
{
- __C_EXT(1, 201112L);
- if (errnum > __nstrerror || __strerror[errnum] == NULL) {
- if (snprintf(s, maxsize, "Uknown error [%d]", errnum) < maxsize) {
- return 0;
- }
- return 1;
- }
-
- strncpy(s, __strerror[errnum], maxsize);
+ SIGNAL_SAFE(0);
+ (void)s; (void)maxsize; (void)errnum;
return errnum;
}
@@ -35,6 +26,3 @@ subsequent calls.
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strerrorlen_s.c b/src/string/strerrorlen_s.c
index 0679dc2f..c3ed5666 100644
--- a/src/string/strerrorlen_s.c
+++ b/src/string/strerrorlen_s.c
@@ -1,10 +1,9 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
size_t strerrorlen_s(errno_t errnum)
{
- __C_EXT(1, 201112L);
+ SIGNAL_SAFE(0);
char buffer[1024];
strerror_s(buffer, sizeof(buffer), errnum);
return strlen(buffer);
@@ -13,6 +12,3 @@ size_t strerrorlen_s(errno_t errnum)
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strlen.c b/src/string/strlen.c
index e083012f..44210c7c 100644
--- a/src/string/strlen.c
+++ b/src/string/strlen.c
@@ -1,13 +1,12 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** find string length **/
size_t strlen(const char *s)
{
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s);
for (i = 0; s[i] != '\0'; i++) {
@@ -26,6 +25,3 @@ including the terminating null character.
RETURN_ALWAYS(the length of the string);
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strncat.c b/src/string/strncat.c
index 3e51cbca..8a99f5b4 100644
--- a/src/string/strncat.c
+++ b/src/string/strncat.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strncat
/** concatenate bounded string **/
@@ -10,9 +9,10 @@ char * strncat(char * restrict s1, const char * restrict s2, size_t n)
char *append = NULL;
size_t i;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
- ASSERT_NOOVERLAP(s1, s2, strlen(s1) + strlen(s2));
+ ASSERT_NOOVERLAP(s1, n, s2, strlen(s1) + strlen(s2));
append = s1 + strlen(s1);
@@ -42,6 +42,3 @@ terminated.
RETURN_ALWAYS(ARGUMENT(s1));
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strncat_s.c b/src/string/strncat_s.c
index fa68151c..989ad763 100644
--- a/src/string/strncat_s.c
+++ b/src/string/strncat_s.c
@@ -1,14 +1,13 @@
-#if 0
-
#include <string.h>
+#include "_safety.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));
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+ (void)s1max; //ASSERT_NOOVERLAP(s1, s1max, s2, strlen(s1) + strlen(s2));
char *append = s1 + strlen(s1);
for (size_t i = 0; i < n; i++) {
@@ -23,7 +22,7 @@ errno_t strncat_s(char * restrict s1, rsize_t s1max, const char * restrict s2, r
*append = '\0';
}
- return s1;
+ return 0;
}
/***
@@ -44,6 +43,3 @@ terminated.
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strncmp.c b/src/string/strncmp.c
index 30e83aa8..c5dd573a 100644
--- a/src/string/strncmp.c
+++ b/src/string/strncmp.c
@@ -1,12 +1,11 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** compare bound strings **/
int strncmp(const char *s1, const char *s2, size_t n)
{
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -33,6 +32,3 @@ ARGUMENT(s2), or until the first CHAR(\0), whichever comes first.
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strncpy.c b/src/string/strncpy.c
index 0bea303a..10786ebd 100644
--- a/src/string/strncpy.c
+++ b/src/string/strncpy.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strncpy
/** copy bounded string **/
@@ -9,9 +8,10 @@ char * strncpy(char * restrict s1, const char * restrict s2, size_t n)
{
size_t i;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
- ASSERT_NOOVERLAP(s1, s2, n);
+ ASSERT_NOOVERLAP(s1, n, s2, n);
for (i = 0; i < n; i++) {
s1[i] = s2[i];
@@ -36,6 +36,3 @@ terminated.
RETURN_ALWAYS(ARGUMENT(s1));
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strncpy_s.c b/src/string/strncpy_s.c
index 2dd2cfdb..1fdb3cb5 100644
--- a/src/string/strncpy_s.c
+++ b/src/string/strncpy_s.c
@@ -1,14 +1,13 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
/** copy bounded string **/
errno_t strncpy_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, n);
+ SIGNAL_SAFE(0);
+ ASSERT_NONNULL(s1);
+ ASSERT_NONNULL(s2);
+ ASSERT_NOOVERLAP(s1, s1max, s2, n);
size_t i;
for (i = 0; i < n; i++) {
@@ -22,7 +21,7 @@ errno_t strncpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2, r
s1[i++] = '\0';
}
- return s1;
+ return 0;
}
/***
@@ -43,6 +42,3 @@ terminated.
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strnlen_s.c b/src/string/strnlen_s.c
index f46ddcb2..3755f7d8 100644
--- a/src/string/strnlen_s.c
+++ b/src/string/strnlen_s.c
@@ -1,22 +1,13 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
size_t strnlen_s(const char *s, size_t maxsize)
{
- __C_EXT(1, 201112L);
- size_t i = 0;
- while (i < maxlen) {
- if (s[i] == '\0')
- return i;
- i++;
- }
- return i;
+ SIGNAL_SAFE(0);
+ (void)s;
+ return maxsize;
}
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strpbrk.c b/src/string/strpbrk.c
index 4b99b623..d238ad89 100644
--- a/src/string/strpbrk.c
+++ b/src/string/strpbrk.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strpbrk
/** count matching characters **/
@@ -9,6 +8,7 @@ char * strpbrk(const char *s1, const char *s2)
{
size_t i;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -30,6 +30,3 @@ RETURN_FAILURE(CONSTANT(NULL));
RETURN_SUCCESS(a pointer to the located character);
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strrchr.c b/src/string/strrchr.c
index c85cb046..d7c50e31 100644
--- a/src/string/strrchr.c
+++ b/src/string/strrchr.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strrchr
/** search string from end **/
@@ -9,6 +8,7 @@ char * strrchr(const char *s, int c)
{
int i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s);
for (i = strlen(s) + 1; i >= 0; i--) {
@@ -32,6 +32,3 @@ string ARGUMENT(s).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strspn.c b/src/string/strspn.c
index 9762d953..4d6231e7 100644
--- a/src/string/strspn.c
+++ b/src/string/strspn.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** count matching characters **/
@@ -9,6 +7,7 @@ size_t strspn(const char *s1, const char *s2)
{
size_t i = 0;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -30,6 +29,3 @@ up of characters from ARGUMENT(s2).
RETURN_ALWAYS(the number of matching characters);
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strstr.c b/src/string/strstr.c
index 4a8d9767..cc2da14a 100644
--- a/src/string/strstr.c
+++ b/src/string/strstr.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strstr
/** search for substring **/
@@ -11,6 +10,7 @@ char * strstr(const char *s1, const char *s2)
size_t l2 = 0;
char *p = (char*)s1;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
@@ -39,6 +39,3 @@ character of ARGUMENT(s1).
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strtok.c b/src/string/strtok.c
index e031e55a..862581c7 100644
--- a/src/string/strtok.c
+++ b/src/string/strtok.c
@@ -1,7 +1,6 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
+#undef strtok
/** split string into tokens **/
@@ -11,6 +10,7 @@ char * strtok(char * restrict s1, const char * restrict s2)
static char **state = &current;
/* TODO */
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s2);
/*
@@ -38,6 +38,3 @@ CHAR(\0), terminating the token.
/*
STDC(1)
*/
-
-
-#endif
diff --git a/src/string/strtok_s.c b/src/string/strtok_s.c
index ef2c0075..7721a108 100644
--- a/src/string/strtok_s.c
+++ b/src/string/strtok_s.c
@@ -1,30 +1,14 @@
-#if 0
-
#include <string.h>
+#include "_safety.h"
+#undef strtok_s
char * strtok_s(char * restrict s1, rsize_t * restrict s1max, const char * restrict s2, char **restrict ptr)
{
- __C_EXT(1, 201112L);
- int i = 0;
-
- if (s == NULL)
- s = *lasts;
-
- while (i < strlen (s)) {
- if (strchr (sep, s[i]) == NULL) {
- i++;
- } else {
- s[i] = '\0';
- *lasts = &(s[i+1]);
- return s;
- }
- }
+ SIGNAL_SAFE(0);
+ (void)s1; (void)s1max; (void)s2; (void)ptr;
return NULL;
}
/*
CEXT1(201112)
*/
-
-
-#endif
diff --git a/src/string/strxfrm.c b/src/string/strxfrm.c
index 498e8e5c..2431ba6e 100644
--- a/src/string/strxfrm.c
+++ b/src/string/strxfrm.c
@@ -1,7 +1,5 @@
-#if 0
-
#include <string.h>
-#include "_assert.h"
+#include "_safety.h"
/** transform string **/
@@ -9,11 +7,12 @@ size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n)
{
/* TODO */
(void)s1; (void)s2; (void)n;
+ SIGNAL_SAFE(0);
ASSERT_NONNULL(s2);
if (n != 0) {
ASSERT_NONNULL(s1);
- ASSERT_NOOVERLAP(s1, s2, n);
+ ASSERT_NOOVERLAP(s1, n, s2, n);
}
return 0;
@@ -31,6 +30,3 @@ UNDEFINED(ARGUMENT(n) is not ZERO and ARGUMENT(s1) is CONSTANT(NULL))
RETURN_ALWAYS(the length of the transformed string, not including the terminating CHAR(\0));
STDC(1)
*/
-
-
-#endif