welibc
A clear, secure, and well documented standard C library
string.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2015 - 2021, Walt Elam
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 
15  3. Neither the name of the copyright holder nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  POSSIBILITY OF SUCH DAMAGE.
30 *******************************************************************************/
31 /***************************************************************************//**
32  @file string.h
33 
34  @brief Declares types, functions, and macros for manipulating arrays of
35  character type and other objects treated as arrays of character
36  type.
37 *******************************************************************************/
38 #ifndef _STRING_H
39 #define _STRING_H
40 
41 /* Type of the result of the sizeof operator */
42 #ifndef _SIZE_T
43 #define _SIZE_T
44 typedef unsigned long size_t;
45 #endif /* _SIZE_T */
46 
47 /* Null pointer constant */
48 #ifndef _NULL
49 #define _NULL
50 #define NULL ((void *) 0)
51 #endif /* _NULL */
52 
53 /* Copying functions */
54 void *
55 memcpy(void *s1, const void *s2, size_t n);
56 
57 void *
58 memmove(void *s1, const void *s2, size_t n);
59 
60 char *
61 strcpy(char *s1, const char *s2);
62 
63 char *
64 strncpy(char *s1, const char *s2, size_t n);
65 
66 /* Concatenation functions */
67 char *
68 strcat(char *s1, const char *s2);
69 
70 char *
71 strncat(char *s1, const char *s2, size_t n);
72 
73 /* Comparison functions */
74 int
75 memcmp(const void *s1, const void *s2, size_t n);
76 
77 int
78 strcmp(const char *s1, const char *s2);
79 
80 int
81 strncmp(const char *s1, const char *s2, size_t n);
82 
83 /* Search functions */
84 void *
85 memchr(const void *s, int c, size_t n);
86 
87 char *
88 strchr(const char *s, int c);
89 
90 size_t
91 strcspn(const char *s1, const char *s2);
92 
93 char *
94 strpbrk(const char *s1, const char *s2);
95 
96 char *
97 strrchr(const char *s, int c);
98 
99 size_t
100 strspn(const char *s1, const char *s2);
101 
102 char *
103 strstr(const char *s1, const char *s2);
104 
105 char *
106 strtok(char *s1, const char *s2);
107 
108 /* Miscellaneous functions */
109 void *
110 memset(void *s, int c, size_t n);
111 
112 char *
113 strerror(int errnum);
114 
115 size_t
116 strlen(const char *s);
117 
118 #endif /* _STRING_H */
119 
strlen
size_t strlen(const char *s)
Computes the length of a string.
Definition: strlen.c:51
strcpy
char * strcpy(char *s1, const char *s2)
Copies a string with null terminator from s2 into s1.
Definition: strcpy.c:54
strerror
char * strerror(int errnum)
Maps an error number to an error message string.
Definition: strerror.c:54
strcmp
int strcmp(const char *s1, const char *s2)
Compares the strings pointed to be s1 and s2.
Definition: strcmp.c:54
strchr
char * strchr(const char *s, int c)
Locate the first occurrence of a character in a string.
Definition: strchr.c:53
strcat
char * strcat(char *s1, const char *s2)
Concatenates two strings.
Definition: strcat.c:60
memcpy
void * memcpy(void *s1, const void *s2, size_t n)
Copies n characters from s2 into s1.
Definition: memcpy.c:60
memchr
void * memchr(const void *s, int c, size_t n)
Searches for a given character.
Definition: memchr.c:54
memset
void * memset(void *s, int c, size_t n)
Copies the value c into the first n characters of object s.
Definition: memset.c:52
size_t
unsigned long size_t
Definition: string.h:44
memmove
void * memmove(void *s1, const void *s2, size_t n)
Copies n characters from s2 into s1.
Definition: memmove.c:59
strcspn
size_t strcspn(const char *s1, const char *s2)
Find the length of the span of complementary characters to s2 in s1.
Definition: strcspn.c:52
strncpy
char * strncpy(char *s1, const char *s2, size_t n)
Copies no more than n characters with null terminator from s2 to s1.
Definition: strncpy.c:58
strrchr
char * strrchr(const char *s, int c)
Locate the last occurrence of a character in a string.
Definition: strrchr.c:53
strspn
size_t strspn(const char *s1, const char *s2)
Find the length of the span of characters in s2 in s1.
Definition: strspn.c:52
strstr
char * strstr(const char *s1, const char *s2)
Locate the first occurrence of a string in a another string.
Definition: strstr.c:53
strncat
char * strncat(char *s1, const char *s2, size_t n)
Concatenates two strings, appending no more than n characters.
Definition: strncat.c:62
strpbrk
char * strpbrk(const char *s1, const char *s2)
Locate the first occurrence of any of s2 in s1.
Definition: strpbrk.c:51
strtok
char * strtok(char *s1, const char *s2)
Breaks a string into a sequence of tokens split on a given delimiter.
Definition: strtok.c:77
memcmp
int memcmp(const void *s1, const void *s2, size_t n)
Compares the first n characters of s1 and s2.
Definition: memcmp.c:68
strncmp
int strncmp(const char *s1, const char *s2, size_t n)
Compares the strings pointed to be s1 and s2.
Definition: strncmp.c:56