summaryrefslogtreecommitdiff
path: root/src/basic/string-util.h
Commit message (Collapse)AuthorAgeFilesLines
* string-util: Add startswith_strv()Daan De Meyer2023-04-201-0/+5
| | | | | | This is the function version of STARTSWITH_SET(). We also move STARTSWITH_SET() to string-util.h as it fits more there than in strv.h and reimplement it using startswith_strv().
* string-util: add strstrafter()Lennart Poettering2023-04-141-0/+12
| | | | | | | | | strstrafter() is like strstr() but returns a pointer to the first character *after* the found substring, not on the substring itself. Quite often this is what we actually want. Inspired by #27267 I think it makes sense to add a helper for this, to avoid the potentially fragile manual pointer increment afterwards.
* string-util: add new helper for finding line starting with specific string ↵Lennart Poettering2023-03-241-0/+2
| | | | | | | in a text buffer We have implemented this manually a couple of times, and always wrong. Hence let's implement this correctly for once and use everywhere.
* string-util: add common implementation of function that converts sized ↵Lennart Poettering2023-01-211-0/+10
| | | | character buffers to NUL terminated C strings
* string-util: add new strdupcspn()/strdupspn()Lennart Poettering2023-01-201-0/+3
| | | | | | | | These combine strndup() + strspn()/strcspn() into one. There are a bunch of strndupa() calls that could use similar treatment (or should be converted to strdup[c]spn(), but this commit doesn't bother with that.
* string-util: rework empty_to_null() to not change "const" qualifier of inputLennart Poettering2022-12-211-3/+12
| | | | | | | | This changes the definition from enpty_to_null() so that we are still typesafe (i.e. only accept strings) but do not drop (or add) any const to the returned string that wasn't also on the input. Inspired by: https://github.com/systemd/systemd/pull/25805/commits/3196e2996f613a2e3568a791c503306b7c58d593
* string-util: make free_and_strdup_warn() return 1 when new string is assignedYu Watanabe2022-10-241-2/+5
|
* basic: Add strgrowpad0()Daan De Meyer2022-09-231-0/+2
|
* fundamental: Move some helpers into string-util-fundamentalJan Janssen2022-05-211-11/+0
|
* string-util: introduce strspn_from_end()Yu Watanabe2022-04-201-0/+2
|
* string-util: introduce string_replace_char()Yu Watanabe2022-04-201-0/+2
|
* core: shorten long unit names that are based on paths and append path hash ↵Michal Sekletar2022-04-081-11/+12
| | | | | | at the end Fixes #18077
* udev/net_id: add debug logging for construction of device namesZbigniew Jędrzejewski-Szmek2021-12-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I think this makes it much easier to figure out what information sources were used to generate the names, and why certain names were not generated. On my laptop: Using default interface naming scheme 'v250'. ID_NET_NAMING_SCHEME=v250 wwp0s20f0u2i12: addr_assign_type=3, MAC address is not permanent. wwp0s20f0u2i12: Parsing slot information from sysname "0000:00:14.0": success wwp0s20f0u2i12: dev_port=0 wwp0s20f0u2i12: PCI path identifier: domain=0 bus=0 slot=20 func=0 phys_port= dev_port=0 → p0s20f0 wwp0s20f0u2i12: USB name identifier: ports=2 config=1 interface=12 → u2i12 ID_NET_NAME_PATH=wwp0s20f0u2i12 Using default interface naming scheme 'v250'. ID_NET_NAMING_SCHEME=v250 ID_NET_NAME_MAC=en54ee75cb1dc0 enp0s31f6: MAC address identifier: hw_addr=54:ee:75:cb:1d:c0 → 54ee75cb1dc0 ID_OUI_FROM_DATABASE=Wistron InfoComm(Kunshan)Co.,Ltd. enp0s31f6: Parsing slot information from sysname "0000:00:1f.6": success enp0s31f6: dev_port=0 enp0s31f6: PCI path identifier: domain=0 bus=0 slot=31 func=6 phys_port= dev_port=0 → p0s31f6 ID_NET_NAME_PATH=enp0s31f6 Using default interface naming scheme 'v250'. ID_NET_NAMING_SCHEME=v250 ID_NET_NAME_MAC=en0050b6856d36 hub0: MAC address identifier: hw_addr=00:50:b6:85:6d:36 → 0050b6856d36 ID_OUI_FROM_DATABASE=GOOD WAY IND. CO., LTD. hub0: Parsing slot information from sysname "0000:00:14.0": success hub0: dev_port=0 hub0: PCI path identifier: domain=0 bus=0 slot=20 func=0 phys_port= dev_port=0 → p0s20f0 hub0: USB name identifier: ports=4.1.3 config=2 interface=0 → u4u1u3c2 ID_NET_NAME_PATH=enp0s20f0u4u1u3c2 Using default interface naming scheme 'v250'. ID_NET_NAMING_SCHEME=v250 wlp4s0: addr_assign_type=3, MAC address is not permanent. wlp4s0: Parsing slot information from sysname "0000:04:00.0": success wlp4s0: dev_port=0 wlp4s0: PCI path identifier: domain=0 bus=4 slot=0 func=0 phys_port= dev_port=0 → p4s0 ID_NET_NAME_PATH=wlp4s0
* string-util: introduce streq_skip_trailing_chars()Antony Deepak Thomas2021-09-291-0/+2
|
* sd-boot: Add memmem_safe and memory_startswithJan Janssen2021-08-161-16/+0
|
* string-util: introduce strextendf_with_separator()Yu Watanabe2021-05-201-2/+2
|
* string-util: explicitly cast character to unsignedYu Watanabe2021-05-081-1/+6
| | | | | | | | This also adds comment why we cast to unsigned. Follow-up for 7971f9030ae4bebe0d4a6845ed31584f8ab18103. Addresses the comment https://github.com/systemd/systemd/pull/19544#discussion_r628472794.
* string-util: fix build error on aarch64Yu Watanabe2021-05-071-1/+1
| | | | | | | | | | | | | | | This fixes the following error: ``` In file included from ../src/basic/af-list.h:6, from ../src/basic/af-list.c:7: ../src/basic/string-util.h: In function 'char_is_cc': ../src/basic/string-util.h:133:19: error: comparison is always true due to limited range of data type [-Werror=type-limits] 133 | return (p >= 0 && p < ' ') || p == 127; | ^~ cc1: all warnings being treated as errors ``` Fixes #19543.
* Merge pull request #18863 from keszybz/cmdline-escapingLennart Poettering2021-05-071-8/+7
|\ | | | | Escape command lines properly
| * basic/string-util: simplify how str_realloc() is usedZbigniew Jędrzejewski-Szmek2021-05-051-8/+4
| | | | | | | | All callers ignore failure anyway, so let's do that internally.
| * basic/string-util: split out helper functionZbigniew Jędrzejewski-Szmek2021-05-051-0/+3
| |
* | string-util: add strextendf() helper, that allows extending some allocated ↵Lennart Poettering2021-05-071-0/+2
|/ | | | | | | | | | | | | | | string via a format string It's not going to be efficient if called in inner loops, but it's oh so handy, and we have some code that does this: asprintf(&p, "%s…", b, …); free(b); b = TAKE_PTR(p); which can now be replaced by the quicker and easier to read: strextendf(&p, "…", …);
* fundamental: move several macros and functions into src/fundamental/Yu Watanabe2021-02-091-47/+1
| | | | | | | | | | sd-boot has a copy of a subset of codes from libbasic. This makes sd-boot share the code with libbasic, and dedup the code. Note, startswith_no_case() is dropped from sd-boot, as - it is not used, - the previous implementation is not correct, - gnu-efi does not have StrniCmp() or so.
* Add helper for case-independent string equality checksMatthias Klumpp2021-01-121-0/+4
|
* string-util: imply NULL termination of strextend() argument listLennart Poettering2021-01-061-2/+3
| | | | | The trailing NULL in the argument list is now implied (similar to what we already have in place in strjoin()).
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Merge pull request #17324 from keszybz/resolvectl-compat-outputLennart Poettering2020-10-221-0/+4
|\ | | | | resolvectl compat output
| * resolvectl: use compat status string instead of a field-by-field tableZbigniew Jędrzejewski-Szmek2020-10-201-0/+4
| | | | | | | | | | | | | | The status string is modeled after our --version output: +enabled -disabled equals=more-info For example: Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=allow-downgrade/supported
* | tests: add helper function to autodetect CI environmentsZbigniew Jędrzejewski-Szmek2020-10-221-0/+6
|/ | | | | Sadly there is no standarized way to check if we're running in some CI environment. So let's try to gather the heuristics in one helper function.
* Remove FOREACH_WORD and friendsZbigniew Jędrzejewski-Szmek2020-09-091-18/+0
|
* Add string_contains_word_strv()Zbigniew Jędrzejewski-Szmek2020-09-041-1/+5
| | | | | | I had to move STRV_MAKE to macro.h. There is a circular dependency between extract-word.h, strv.h, and string-util.h that makes it hard to define the inline function otherwise.
* basic: add string_contains_word()Zbigniew Jędrzejewski-Szmek2020-09-041-0/+1
| | | | | This wraps the common pattern of using extract_first_word() in a loop to look for a matching word.
* basic/string-util: reduce scope of variablesZbigniew Jędrzejewski-Szmek2020-08-171-11/+5
|
* Introduce strcasecmp_ptr() and use it in a few placesZbigniew Jędrzejewski-Szmek2020-06-031-0/+1
|
* string-util: make clear that split() + FOREACH_WORD() should dieLennart Poettering2020-04-021-0/+2
|
* string-util: add helper for extracting n'th line of a stringLennart Poettering2020-01-131-0/+1
|
* string-util: let's add helper for truncating string after a specified number ↵Lennart Poettering2020-01-131-0/+2
| | | | of lines
* string-util: readd string_erase()Lennart Poettering2019-12-041-0/+2
| | | | | This was dropped in 8e27167cc9b8beda2bf49789b15f0b0301b95d17, but is actually useful for some usecases still.
* tree-wide: drop alloca.h when alloc-util.h is includedYu Watanabe2019-11-041-1/+0
|
* util-lib: move yes_no() and friends to string-util.hZbigniew Jędrzejewski-Szmek2019-09-161-0/+16
|
* tree-wide: get rid of strappend()Lennart Poettering2019-07-121-1/+0
| | | | | It's a special case of strjoin(), so no need to keep both. In particular as typing strjoin() is even shoert than strappend().
* Remove string_eraseZbigniew Jędrzejewski-Szmek2019-07-101-2/+0
|
* Remove string_free_eraseZbigniew Jędrzejewski-Szmek2019-07-101-4/+0
|
* Rework cmdline printing to use unicodeZbigniew Jędrzejewski-Szmek2019-05-221-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | The functions to retrieve and print process cmdlines were based on the assumption that they contain printable ASCII, and everything else should be filtered out. That assumption doesn't hold in today's world, where people are free to use unicode everywhere. This replaces the custom cmdline reading code with a more generic approach using utf8_escape_non_printable_full(). For kernel threads, truncation is done on the parenthesized name, so we'll get "[worker]", "[worker…]", …, "[w…]", "[…", "…" as we reduce the number of available columns. This implementation is most likely slower for very long cmdlines, but I don't think this is very important. The common case is to have short commandlines, and should print those properly. Absurdly long cmdlines are the exception, which needs to be handled correctly and safely, but speed is not too important. Fixes #12532. v2: - use size_t for the number of columns. This change propagates into various other functions that call get_process_cmdline(), increasing the size of the patch, but the changes are rather trivial.
* shared/utmp-wtmp: silence gcc warning about strncpy truncationZbigniew Jędrzejewski-Szmek2019-05-071-0/+6
| | | | | | | | | Unfortunately the warning must be known, or otherwise the pragma generates a warning or an error. So let's do a meson check for it. Is it worth doing this to silence the warning? I think so, because apparently the warning was already emitted by gcc-8.1, and with the recent push in gcc to catch more such cases, we'll most likely only get more of those.
* basic: add new helper call empty_or_dash_to_null()Lennart Poettering2019-04-081-0/+4
| | | | | We have a function like this at two places already. Let's unify it in one generic location and let's port a number of users over.
* tree-wide: introduce empty_or_dash() helperLennart Poettering2019-04-081-0/+6
| | | | | At quite a few places we check isempty() || streq(…, "-"), let's add a helper to simplify that, and replace that by a single function call.
* nspawn-oci: add helper function for free_and_strdup with oom checkZbigniew Jędrzejewski-Szmek2019-03-211-0/+5
|
* util: split out nulstr related stuff to nulstr-util.[ch]Lennart Poettering2019-03-141-2/+0
|
* util: move some raw memory functions from string-util.h → memory-util.hLennart Poettering2019-03-141-26/+0
|