xref: /llvm-project-15.0.7/libc/docs/strings.rst (revision 12aae7d9)
1=============================
2String Functions in LLVM-libc
3=============================
4
5-------
6Summary
7-------
8
9This site tracks the status of the implementation of string functions in LLVM
10Libc. This includes a few extra functions that are not in string.h, such as
11functions converting strings to numbers.
12
13---------------
14Source location
15---------------
16
17-   The main source for string functions is located at:
18    ``libc/src/string``.
19
20-   The source for string conversion functions is located at:
21    ``libc/src/stdlib`` and
22    ``libc/src/__support``.
23
24-   The tests are located at:
25    ``libc/test/src/string``,
26    ``libc/test/src/stdlib``, and
27    ``libc/test/src/__support``
28    respectively.
29
30---------------------
31Implementation Status
32---------------------
33
34Primary memory functions
35========================
36
37.. TODO(gchatelet): add details about the memory functions.
38
39
40=============  =========
41Function Name  Available
42=============  =========
43bzero          YES
44bcmp           YES
45memcpy         YES
46memset         YES
47memcmp         YES
48memmove        YES
49=============  =========
50
51
52Other Raw Memory Functions
53==========================
54
55=============  =========
56Function Name  Available
57=============  =========
58memchr         YES
59memrchr        YES
60memccpy        YES
61mempcpy        YES
62=============  =========
63
64String Memory Functions
65=======================
66
67=============  =========
68Function Name  Available
69=============  =========
70stpcpy         YES
71stpncpy        YES
72strcpy         YES
73strncpy        YES
74strcat         YES
75strncat        YES
76strdup         YES
77strndup        YES
78=============  =========
79
80String Examination Functions
81============================
82
83=============  =========
84Function Name  Available
85=============  =========
86strlen         YES
87strnlen        YES
88strcmp         YES
89strncmp        YES
90strchr         YES
91strrchr        YES
92strspn         YES
93strcspn        YES
94strpbrk        YES
95strstr         YES
96strtok         YES
97strtok_r       YES
98=============  =========
99
100String Conversion Functions
101============================
102
103These functions are not in strings.h, but are still primarily string
104functions, and are therefore tracked along with the rest of the string
105functions.
106
107The String to float functions were implemented using the Eisel-Lemire algorithm
108(read more about the algorithm here: `The Eisel-Lemire ParseNumberF64 Algorithm
109<https://nigeltao.github.io/blog/2020/eisel-lemire.html>`_). This improved
110the performance of string to float and double, and allowed it to complete this
111comprehensive test 15% faster than glibc: `Parse Number FXX Test Data
112<https://github.com/nigeltao/parse-number-fxx-test-data>`_. The test was done
113with LLVM-libc built on 2022-04-14 and Debian GLibc version 2.33-6. The targets
114``libc_str_to_float_comparison_test`` and
115``libc_system_str_to_float_comparison_test`` were built and run on the test data
11610 times each, skipping the first run since it was an outlier.
117
118
119=============  =========
120Function Name  Available
121=============  =========
122atof           YES
123atoi           YES
124atol           YES
125atoll          YES
126strtol         YES
127strtoll        YES
128strtoul        YES
129strtoull       YES
130strtof         YES
131strtod         YES
132strtold        YES
133strtoimax      YES
134strtoumax      YES
135=============  =========
136
137String Error Functions
138======================
139
140=============  =========
141Function Name  Available
142=============  =========
143strerror
144strerror_s
145strerrorlen_s
146=============  =========
147
148Localized String Functions
149==========================
150
151These functions require locale.h, and will be added when locale support is
152implemented in LLVM-libc.
153
154=============  =========
155Function Name  Available
156=============  =========
157strcoll
158strxfrm
159=============  =========
160
161---------------------------
162\<name\>_s String Functions
163---------------------------
164
165Many String functions have an equivalent _s version, which is intended to be
166more secure and safe than the previous standard. These functions add runtime
167error detection and overflow protection. While they can be seen as an
168improvement, adoption remains relatively low among users. In addition, they are
169being considered for removal, see
170`Field Experience With Annex K — Bounds Checking Interfaces
171<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm>`_. For these reasons,
172there is no ongoing work to implement them.
173