Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/libc/minimal/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ extern char *strcat(char *_MLIBC_RESTRICT dest,
extern char *strncat(char *_MLIBC_RESTRICT d, const char *_MLIBC_RESTRICT s,
size_t n);
extern char *strstr(const char *s, const char *find);
extern size_t strcspn(const char *s1, const char *s2);
extern int iscntrl(int a);

extern int memcmp(const void *m1, const void *m2, size_t n);
extern void *memmove(void *d, const void *s, size_t n);
Expand Down
36 changes: 36 additions & 0 deletions lib/libc/minimal/source/string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,42 @@ char *strncat(char *_MLIBC_RESTRICT dest, const char *_MLIBC_RESTRICT src,
return orig_dest;
}

/**
* @brief Get the length of a complementary substring
*
* @return length of the maximum initial segment of the string pointed to
* by s1 which consists entirely of bytes not from the string pointed to by s2.
*/

size_t strcspn(const char *s1, const char *s2)
{
int i, j;

for (i = 0; i < strlen(s2); ++i) {
for (j = 0; j < strlen(s1); ++j) {
if (s1[j] == s2[i]) {
return j;
}
}
}

return strlen(s1);
}

/**
* @brief Test for a control character
*
* @return non-zero if c is a control character, otherwise 0.
*/

int iscntrl(int c)
{
/* All the characters placed before the space on the ASCII table
* and the 0x7F character (DEL) are control characters.
*/
return (int)(c < ' ' || c == 0x7F);
}

/**
*
* @brief Compare two memory areas
Expand Down