The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#pragma once
2
3#include <sys/types.h>
4
5/**
6 * @file string.h
7 * @brief This file contains the declarations of string manipulation functions.
8 */
9
10#ifndef NULL
11#define NULL ((void *)0)
12#endif
13
14/**
15 * @brief computes the length of the string s.
16 * @param s the string to compute the length of.
17 * @returns the length of the string s, excluding the terminating null byte ('\0').
18 */
19size_t strlen(const char *s);
20
21/**
22 * @brief compares the string s1 to the string s2.
23 * @param s1 the first string to compare.
24 * @param s2 the second string to compare.
25 * @returns an integer less than, equal to, or greater than zero if s1 is
26 */
27int strcmp(const char *s1, const char *s2);
28
29/**
30 * @brief compares the first n bytes of the string s1 to the first n bytes of the string s2.
31 * @param s1 the first string to compare.
32 * @param s2 the second string to compare.
33 * @param n the number of bytes to compare.
34 * @returns an integer less than, equal to, or greater than zero if the first n
35 */
36int strncmp(const char *s1, const char *s2, size_t n);
37
38/**
39 * @brief copies the string pointed to by src, including the terminating null byte ('\0'), to the buffer pointed to by dst.
40 * @param dst the destination buffer.
41 * @param src the source string to copy.
42 * @returns a pointer to the destination string dst.
43 */
44char *strcpy(char *dst, const char *src);
45
46/**
47 * @brief copies up to n bytes from the string pointed to by src to the buffer pointed to by dst.
48 * @param dst the destination buffer.
49 * @param src the source string to copy.
50 * @param n the maximum number of bytes to copy.
51 * @returns a pointer to the destination string dst.
52 */
53char *strncpy(char *dst, const char *src, size_t n);
54
55/**
56 * @brief appends the string pointed to by src to the end of the string pointed to by dst.
57 * @param dst the destination string to which src will be appended.
58 * @param src the source string to append.
59 * @returns a pointer to the destination string dst.
60 */
61char *strcat(char *dst, const char *src);
62
63/**
64 * @brief appends up to n bytes from the string pointed to by src to the end of the string pointed to by dst.
65 * @param dst the destination string to which src will be appended.
66 * @param src the source string to append.
67 * @param n the maximum number of bytes to append.
68 * @returns a pointer to the destination string dst.
69 */
70char *strchr(const char *s, int c);
71
72/**
73 * @brief locates the last occurrence of c (converted to a char) in the string pointed to by s.
74 * @param s the string to search.
75 * @param c the character to locate.
76 * @returns a pointer to the last occurrence of c in s, or NULL if c is not found.
77 */
78char *strrchr(const char *s, int c);
79
80/**
81 * @brief tokenizes the string str using the delimiters specified in delim.
82 * @param str the string to tokenize. On the first call, str should point to the string to tokenize. On subsequent calls, str should be NULL.
83 * @param delim a string containing the delimiters to use for tokenization.
84 * @returns a pointer to the next token found in str, or NULL if no more tokens are found.
85 */
86char *strtok(char *str, const char *delim);
87
88/**
89 * @brief copies n bytes from memory area src to memory area dst. The memory areas must not overlap.
90 * @param dst the destination memory area.
91 * @param src the source memory area.
92 * @param n the number of bytes to copy.
93 * @returns a pointer to the destination memory area dst.
94 */
95void *memcpy(void *dst, const void *src, size_t n);
96
97/**
98 * @brief fills the first n bytes of the memory area pointed to by dst with the constant byte c.
99 * @param dst the memory area to fill.
100 * @param c the byte to fill the memory area with.
101 * @param n the number of bytes to fill.
102 * @returns a pointer to the memory area dst.
103 */
104void *memset(void *dst, int c, size_t n);
105
106/**
107 * @brief compares the first n bytes of the memory areas s1 and s2.
108 * @param s1 the first memory area to compare.
109 * @param s2 the second memory area to compare.
110 * @param n the number of bytes to compare.
111 * @returns an integer less than, equal to, or greater than zero if the first n bytes of s1 are found, respectively, to be less than, to match, or be greater than the first n bytes of s2.
112 */
113int memcmp(const void *s1, const void *s2, size_t n);
114
115/**
116 * @brief copies n bytes from memory area src to memory area dst. The memory areas may overlap.
117 * @param dst the destination memory area.
118 * @param src the source memory area.
119 * @param n the number of bytes to copy.
120 * @returns a pointer to the destination memory area dst.
121 */
122void *memmove(void *dst, const void *src, size_t n);
123
124/*
125 * more of <string.h>
126 */
127size_t strnlen(const char *s, size_t max);
128char *strncat(char *dst, const char *src, size_t n);
129char *strdup(const char *s);
130char *strndup(const char *s, size_t n);
131char *strstr(const char *haystack, const char *needle);
132char *strpbrk(const char *s, const char *accept);
133size_t strspn(const char *s, const char *accept);
134size_t strcspn(const char *s, const char *reject);
135char *strtok_r(char *str, const char *delim, char **saveptr);
136int strcasecmp(const char *a, const char *b);
137int strncasecmp(const char *a, const char *b, size_t n);
138int strcoll(const char *a, const char *b);
139void *memchr(const void *s, int c, size_t n);
140const char *strerror(int errnum);
141
142/** a description of a signal ("Terminated"), or "Unknown signal N" */
143char *strsignal(int sig);
144
const char * strerror(int errnum)
return a string describing the given error number.
int strncmp(const char *s1, const char *s2, size_t n)
compares the first n bytes of the string s1 to the first n bytes of the string s2.
Definition string.c:26
void * memchr(const void *s, int c, size_t n)
int strcmp(const char *s1, const char *s2)
compares the string s1 to the string s2.
Definition string.c:15
char * strtok_r(char *str, const char *delim, char **saveptr)
int strcasecmp(const char *a, const char *b)
char * strpbrk(const char *s, const char *accept)
char * strsignal(int sig)
a description of a signal ("Terminated"), or "Unknown signal N"
char * strdup(const char *s)
int strcoll(const char *a, const char *b)
char * strcpy(char *dst, const char *src)
copies the string pointed to by src, including the terminating null byte ('\0'), to the buffer pointe...
Definition string.c:42
char * strtok(char *str, const char *delim)
tokenizes the string str using the delimiters specified in delim.
void * memmove(void *dst, const void *src, size_t n)
copies n bytes from memory area src to memory area dst.
Definition memory.c:16
char * strncpy(char *dst, const char *src, size_t n)
copies up to n bytes from the string pointed to by src to the buffer pointed to by dst.
Definition string.c:55
size_t strnlen(const char *s, size_t max)
int strncasecmp(const char *a, const char *b, size_t n)
size_t strspn(const char *s, const char *accept)
char * strcat(char *dst, const char *src)
appends the string pointed to by src to the end of the string pointed to by dst.
int memcmp(const void *s1, const void *s2, size_t n)
compares the first n bytes of the memory areas s1 and s2.
Definition memory.c:62
size_t strlen(const char *s)
computes the length of the string s.
Definition string.c:3
void * memset(void *dst, int c, size_t n)
fills the first n bytes of the memory area pointed to by dst with the constant byte c.
Definition memory.c:50
void * memcpy(void *dst, const void *src, size_t n)
copies n bytes from memory area src to memory area dst.
Definition memory.c:3
char * strstr(const char *haystack, const char *needle)
char * strchr(const char *s, int c)
appends up to n bytes from the string pointed to by src to the end of the string pointed to by dst.
char * strndup(const char *s, size_t n)
size_t strcspn(const char *s, const char *reject)
char * strncat(char *dst, const char *src, size_t n)
char * strrchr(const char *s, int c)
locates the last occurrence of c (converted to a char) in the string pointed to by s.
int accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
basic system types.