Commit Graph

120 Commits

Author SHA1 Message Date
Lennart Poettering
f77f363c95 string-util: add str_common_prefix() helper that determines length of common prefix of two strings 2025-02-17 14:57:03 +01:00
Mike Yuan
6da2ea9fa9 basic: use _nonnull_if_nonzero_ where appropriate 2025-02-16 12:37:10 +09:00
Mike Yuan
63ed611579 string-util: modernize strextendn() a bit
l == SIZE_MAX requires no special handling, since we assert
on (s || l == 0) above.
2025-02-10 19:39:22 +01:00
Mike Yuan
146b2ed6a6 string-util: drop now unused strnappend() 2025-02-10 19:39:22 +01:00
Mike Yuan
b40694f5fc string-util: introduce strprepend() helper 2025-02-10 19:39:21 +01:00
Lennart Poettering
34467ffa3c string-util: make strjoin() just a special case of strextend()
The functions are very similar, let's make them the same. If the first
argument to strextend() is NULL instead of extending a string we'll
allocate a fresh one and return that.
2025-01-15 10:51:53 +01:00
Yu Watanabe
ac3f3026a9 string-util: modernize split_pair()
- use _cleanup_free_ attribute,
- rename output arguments,
- trigger assertion when an empty separator is passed.
2024-12-28 16:16:27 +09:00
Mike Yuan
34fb408f8b basic: replace size_multiply_overflow() with MUL_ASSIGN_SAFE where applicable 2024-09-20 22:44:34 +02:00
Mike Yuan
f0f044a456 string-util: update ptr declaration to match our coding style 2024-08-18 16:41:44 +02:00
Zbigniew Jędrzejewski-Szmek
ff3f29537c various: move ptr indicator to return value 2024-06-19 16:37:12 +02:00
Zbigniew Jędrzejewski-Szmek
bfd5a0687f various: move const ptr indicator to return value 2024-06-19 16:28:28 +02:00
Mike Yuan
e2b812c804 string-util: introduce string_is_safe_ascii helper 2024-06-16 19:07:35 +02:00
Lennart Poettering
b22635083a string-util: make sure strrepa() doesn't doubly evaluate expressions 2024-06-14 23:50:03 +01:00
Mike Yuan
ee0373cb80 journal-gatewayd: use skip_leading_chars where appropriate
Prompted by c5d6754725
2024-04-17 21:50:22 +08:00
Mike Yuan
f8c700791e string-util: modernize string_contains_word_strv a bit
Also correct the comment on flags.
2024-03-28 17:16:25 +08:00
Zbigniew Jędrzejewski-Szmek
6a705f1234 Replace strdup_or_null() by strdup_to()
I didn't know that this helper existed… It is very similar to strdup_to_full(),
but all callers can actually be replaced by strdup_to(), which has more fitting
semantics.
2024-03-20 15:18:21 +01:00
Zbigniew Jędrzejewski-Szmek
892c5902ae src/basic: add yet another strdup helper
It's a bit ugly to have both strdup_to() and strdup_to_full(). I initially
started with one variant, but then in some functions we want the additional
info, while in many other places, having 1 instead of 0 causes the return
value of whole chains of functions to be changed. It *probably* wouldn't cause
any difference, but there is at least of bunch of tests that would need to be
updated, so in the end it seems to have the two variants.

The output param is first to match free_and_strdup() and other similar
functions.
2024-03-20 15:12:12 +01:00
Mike Yuan
eba8b54130 string-util: move startswith_strv to strv 2024-01-04 16:49:05 +08:00
Lennart Poettering
63566c6b6f string-util: add strrstr() helper 2024-01-03 18:38:46 +01:00
Lennart Poettering
6a20a9d286 string-util: add strdup_or_null() helper 2023-11-07 12:23:27 +01:00
Lennart Poettering
4ed9e2619c bootctl: highlight SecureBoot enabled state in green 2023-09-28 12:07:15 +02:00
Mike Yuan
00614746e9 string-util: introduce strrepa 2023-09-02 22:59:15 +08:00
Lennart Poettering
7ef5b0a4d8 string-util: add a function to determine levenshtein distance of two strings 2023-08-21 23:19:49 +02:00
Joerg Behrmann
c46f5680ca analyze: don't warn about version spec compliant versions
This commits adds version_is_valid_versionspec and uses it in
analyze-compare-version.c.

version_is_valid_versionspec differs from version_is_valid in that it acepts
empty strings and since valid characters in a version spec version are all
ASCII letters and digits as well as "-.~^", but ",_+" allowed by
version_is_valid are not.

Also give a more specific warning message on invalid characters.
2023-07-18 15:57:15 +01:00
Yu Watanabe
86c2a76e09 Merge pull request #28132 from rpigott/dhcp-captive-portal
Implement RFC8910: captive portal dhcp options
2023-07-03 14:51:56 +09:00
Ronan Pigott
7040fd381a dhcp-client: parse RFC8910 captive portal dhcp option 2023-06-29 16:42:16 -07:00
Lennart Poettering
6b9f600772 string-util: add strextendn() helper 2023-06-27 13:49:46 +02:00
Lennart Poettering
f5c6b4f4d9 string-util: move version_is_valid() into generic code
While we are at it, replace the sloppy use of filename_is_valid() by the
less sloppy filename_part_is_valid() (as added by the preceeding
commit), since we don#t want to be too restrictive here. (After all,
version strings invalid as standalone filenames might be valid as part
of filenames, and hence we should allow them).
2023-06-20 19:02:31 +02:00
zhmylove
61cecfa0d8 journalctl: add --truncate-newline option 2023-06-16 09:31:47 +02:00
Daan De Meyer
70cc7ed97e string-util: Add startswith_strv()
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().
2023-04-20 13:43:37 +02:00
Lennart Poettering
d791013ff5 string-util: add strstrafter()
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.
2023-04-14 16:56:15 +02:00
Lennart Poettering
7b82d95f8d string-util: add new helper for finding line starting with specific string 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.
2023-03-24 18:30:20 +01:00
Lennart Poettering
7153213e40 string-util: add common implementation of function that converts sized character buffers to NUL terminated C strings 2023-01-21 10:45:25 +01:00
Lennart Poettering
e8bec6242b string-util: add new strdupcspn()/strdupspn()
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.
2023-01-20 17:27:51 +01:00
Lennart Poettering
ef2409cbde string-util: rework empty_to_null() to not change "const" qualifier of input
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: 3196e2996f
2022-12-21 22:41:16 +01:00
Yu Watanabe
a56dd1580d string-util: make free_and_strdup_warn() return 1 when new string is assigned 2022-10-24 18:55:11 +09:00
Daan De Meyer
2812017cfb basic: Add strgrowpad0() 2022-09-23 14:10:07 +02:00
Jan Janssen
7b19627697 fundamental: Move some helpers into string-util-fundamental 2022-05-21 15:11:13 +01:00
Yu Watanabe
146f4482b2 string-util: introduce strspn_from_end() 2022-04-20 02:15:01 +09:00
Yu Watanabe
072f5f9b18 string-util: introduce string_replace_char() 2022-04-20 02:14:35 +09:00
Michal Sekletar
1d0727e76f core: shorten long unit names that are based on paths and append path hash at the end
Fixes #18077
2022-04-08 15:18:24 +02:00
Zbigniew Jędrzejewski-Szmek
edee65a6a4 udev/net_id: add debug logging for construction of device names
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
2021-12-17 19:07:42 +01:00
Antony Deepak Thomas
8034b42ca6 string-util: introduce streq_skip_trailing_chars() 2021-09-29 12:57:30 +09:00
Jan Janssen
43ee1fe086 sd-boot: Add memmem_safe and memory_startswith 2021-08-16 10:50:58 +02:00
Yu Watanabe
6b13ca8ada string-util: introduce strextendf_with_separator() 2021-05-20 18:16:51 +09:00
Yu Watanabe
3d56acef7f string-util: explicitly cast character to unsigned
This also adds comment why we cast to unsigned.

Follow-up for 7971f9030a.

Addresses the comment https://github.com/systemd/systemd/pull/19544#discussion_r628472794.
2021-05-08 14:24:51 +02:00
Yu Watanabe
7971f9030a string-util: fix build error on aarch64
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.
2021-05-07 21:55:55 +02:00
Lennart Poettering
37ef2fc9f7 Merge pull request #18863 from keszybz/cmdline-escaping
Escape command lines properly
2021-05-07 17:29:39 +02:00
Lennart Poettering
e9b88a6d4e string-util: add strextendf() helper, that allows extending some allocated 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, "…", …);
2021-05-07 09:10:59 +02:00
Zbigniew Jędrzejewski-Szmek
523e1b14a1 basic/string-util: simplify how str_realloc() is used
All callers ignore failure anyway, so let's do that internally.
2021-05-05 12:12:42 +02:00