summaryrefslogtreecommitdiffstats
path: root/lib/string.c
Commit message (Collapse)AuthorAgeFilesLines
* treewide: add SPDX-License-Identifier for files without explicit licenseAhmad Fatoum2022-01-051-0/+1
| | | | | | | | | Record GPL-2.0-only as license for all files lacking an explicit license statement. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220103120539.1730644-12-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: implement strchrnulAhmad Fatoum2021-06-281-0/+18
| | | | | | | | | | We have at least two places opencoding strchrnul, one of them needlessly iterating twice instead of once over the string. Replace both by calling a common single pass implementation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210628051934.9604-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: implement strstarts along with strendsAhmad Fatoum2021-05-031-0/+9
| | | | | | | | | | | Both can be useful when parsing file paths. They are added to different files, because only one of them is available in upstream <linux/string.h>. The other we add to <string.h>, which contains more barebox-specific string functions. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: implement and use parse_assignment helperAhmad Fatoum2020-11-271-0/+11
| | | | | | | | | | | | We have the split by '=' snippet at multiple locations that parse key=value pairs. Consolidate them to a single location. This makes code a bit easier to read at the cost of an extra 8 bytes (LZO-compressed THUMB2 barebox, static inline version is bigger). No functional change. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd-nand'Sascha Hauer2020-11-101-0/+34
|\
| * lib: Add match_string()Sascha Hauer2020-11-091-0/+34
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | of: implement of_property_write_strings for multiple stringsAhmad Fatoum2020-10-021-0/+13
|/ | | | | | | | | | | | | | | | | The current way to set a property with multiple values (e.g. compatible strings) is to have char properties[] = "st,stm32mp157c-dk2\0st,stm32mp157"; of_set_property(np, "compatible", properties, sizeof(properties), 1); Add a new helper to make this easier at the cost of one runtime reallocation: of_property_write_strings(np, "compatible, "st,stm32mp157c-dk2", "st,stm32mp157", NULL); Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc' into masterSascha Hauer2020-09-251-32/+46
|\
| * lib: string: retire deprecated strtok() in favor of reentrant strsep()Ahmad Fatoum2020-09-141-32/+3
| | | | | | | | | | | | | | | | | | | | With the recent changes to ARCH=sandbox, there are no remaining in-tree users for strtok() anymore. Out-of-tree users are better served by using the reentrant strsep(), which has existed in-tree for as long. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * sandbox: support escaping commas in --image filenamesAhmad Fatoum2020-09-141-0/+43
| | | | | | | | | | | | | | | | | | Some tools like afl-fuzz generate file names containing commas. Allow escaping the commas in the file names, so they can be passed to barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Add KASan supportSascha Hauer2020-09-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | KernelAddressSANitizer (KASAN) is a dynamic memory error detector. It provides a fast and comprehensive solution for finding use-after-free and out-of-bounds bugs. This adds support for KASan to barebox. It is basically a stripped down version taken from the Linux Kernel as of v5.9-rc1. Quoting the initial Linux commit 0b24becc810d ("kasan: add kernel address sanitizer infrastructure") describes what KASan does: | KASAN uses compile-time instrumentation for checking every memory access, | therefore GCC > v4.9.2 required. v4.9.2 almost works, but has issues with | putting symbol aliases into the wrong section, which breaks kasan | instrumentation of globals. | | Basic idea: | | The main idea of KASAN is to use shadow memory to record whether each byte | of memory is safe to access or not, and use compiler's instrumentation to | check the shadow memory on each memory access. | | Address sanitizer uses 1/8 of the memory addressable in kernel for shadow | memory and uses direct mapping with a scale and offset to translate a | memory address to its corresponding shadow address. | | For every 8 bytes there is one corresponding byte of shadow memory. | The following encoding used for each shadow byte: 0 means that all 8 bytes | of the corresponding memory region are valid for access; k (1 <= k <= 7) | means that the first k bytes are valid for access, and other (8 - k) bytes | are not; Any negative value indicates that the entire 8-bytes are | inaccessible. Different negative values used to distinguish between | different kinds of inaccessible memory (redzones, freed memory) (see | mm/kasan/kasan.h). | | To be able to detect accesses to bad memory we need a special compiler. | Such compiler inserts a specific function calls (__asan_load*(addr), | __asan_store*(addr)) before each memory access of size 1, 2, 4, 8 or 16. | | These functions check whether memory region is valid to access or not by | checking corresponding shadow memory. If access is not valid an error | printed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | string: Add nokasan variants of default memcpy/memsetSascha Hauer2020-09-211-3/+26
|/ | | | | | Add nokasan variants of __default_memcpy and default_memset. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: add sanity check to the strcmp() and strncmp()Oleksij Rempel2020-08-171-0/+4
| | | | | | | | | | | A relatively big portion of barebox init sequence is running without configured exception vector. As result we may not detect some NULL pointer dereferences (as on iMX6) or just silently freeze (as on stm32). So, add sanity check to detect this kind of issues as early as possible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: lib64: Make string functions aware of MMU configurationAndrey Smirnov2018-06-111-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimized version of memset() in memset.S if called as: memset(foo, 0, size) will try to explicitly zero out data cache with: dc zva, dst which will result in Alignement Exception (DABT) if MMU is not enabled. For more info see: - C4.4.8 "DC ZVA, Data Cache Zero by VA" - D5.2.8 "The effects of disabling a stage of address translation" in "ARM Architecture Reference Manual. ARMv8, for ARMv8-A architecture profile" In similar vein, using optimized version of memcpy() could lead to a unaligned 16-byte write (using 'stp'), which is not allowed for Device-nGnRnE type of memory (see D5.2.8) and would liead to Alignement Exception. To fix both problems expose non-optimized and optimzied versions of the function and created a wrapper to dispatch the call to either one based on if MMU is enabled or not. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string.h: Implement strndupUwe Kleine-König2018-01-051-0/+20
| | | | | | | | | I implemented this while trying to import mmc-utils into barebox. While I didn't finish this import this function might still be useful for someone?! Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* clarify strim function descriptionAleksey Kuleshov2016-08-221-1/+1
| | | | | Signed-off-by: Aleksey Kuleshov <rndfax@yandex.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: Introduce strtoboolSascha Hauer2016-04-291-0/+43
| | | | | | | | | | | | | | | | We have at least two places which convert a string to a boolean type, so create a common function for this. strtobool treats - any positive (nonzero) number as true - "0" as false - "true" (case insensitive) as true - "false" (case insensitive) as false Every other value results in an error and the input *val is not modified. The caller is expected to initialize *val with the correct default before calling strtobool. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string.c: Fix includeSascha Hauer2014-03-291-1/+1
| | | | | | | | string.c needs string.h, otherwise we get: lib/string.c:730: warning: no previous prototype for 'memdup' Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: Add (x)memdupSascha Hauer2013-11-271-0/+14
| | | | | | It's a common task to duplicate some memory. Add (x)memdup functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: introduce memchr_invSascha Hauer2013-07-221-0/+59
| | | | | | Directly taken from Linux Kernel. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lib: string: import case-insensitive string compareSebastian Hesselbarth2013-06-201-0/+60
| | | | | | This imports strnicmp, strcasecmp, and strncasecmp from Linux to barebox. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
* string: add strim for ONFI codeEric Bénard2012-07-051-0/+39
| | | | | Signed-off-by: Eric Bénard <eric@eukrea.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: remove unused bcopy functionSascha Hauer2012-04-051-24/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: add strlcpy supportJean-Christophe PLAGNIOL-VILLARD2010-08-061-0/+26
| | | | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Cc: Andrea GALLO <andrea.gallo@stericsson.com> Cc: Gael SALLES <gael.salles@stericsson.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Fix some exported namesJuergen Beisert2009-12-111-2/+2
| | | | | | | Unsure if this is the/a correct fix, but without it, my build fails. Signed-off-by: Juergen Beisert <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: add typechecking for strchr, strrchr, strstrSascha Hauer2008-08-201-4/+4
| | | | | | | These functions offered an excellent possibility to bypass compiler type checking. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* improved codingstyleMarc Kleine-Budde2007-11-291-3/+3
| | | | | | This patch improved the codingstyle Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
* export functionsSascha Hauer2007-10-041-2/+23
|
* svn_rev_639Sascha Hauer2007-07-051-0/+546