Commit Graph
132 Commits
Author SHA1 Message Date
Yu Watanabe 69350ee3e3 string-util: introduce strextendv_with_separator() 2025-11-01 00:58:42 +09:00
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Mike Yuan d9bf815093 string-util: introduce strprepend_with_separator() 2025-06-11 12:50:51 +09:00
Mike Yuan 180341e732 basic,shared: mark eligible functions with _pure_/_const_
Following the recent witch hunt done to static inline functions
I figure we should at least give the compiler some more hint
on optimizations.
2025-05-26 20:26:58 +02:00
Daan De Meyer 0c15577abe basic + fundamental: Clean up includes
Split out of #37344.
2025-05-25 10:06:07 +02:00
Alberto Planas ba2d8107e2 string-util: add find_line[_after] functions
As a wrapper for `find_line_startswith`, `find_line_after` search for
the exact line and return the pointer for the next line, or NULL if
missing.

`find_line` with search for the exact line and return the pointer to the
beginning of the line.

Signed-off-by: Alberto Planas <aplanas@suse.com>
2025-05-20 10:29:33 +02:00
Daan De Meyer 3b7d332047 macro: Reduce transitive includes 2025-05-09 11:33:31 +02:00
anonymix007 f504ce8407 fundamental: Move common string constants from basic/string-util.h to string-util-fundamental.h 2025-05-07 18:10:51 +03:00
Daan De Meyer efc529cfbd Add missing alloc-util.h to string-util.h
Used by strndupa_safe() and strdupa_safe().

Follow up for 02207b54d5
2025-05-06 17:38:11 +02:00
Daan De Meyer 02207b54d5 alloc-util: Move strdupa_safe() and strndupa_safe() to string-util.h 2025-05-06 15:42:01 +02:00
Daan De Meyer e4a08721c3 string-util: Remove utf8.h and alloc-util.h includes 2025-05-06 13:27:54 +02:00
Daan De Meyer 93a1f7921a basic: Stop including log.h in macro.h
Now that the necessary functions from log.h have been moved to macro.h,
we can stop including log.h in macro.h. This requires modifying source
files all over the tree to include log.h instead.
2025-04-18 14:19:15 +02:00
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: https://github.com/systemd/systemd/pull/25805/commits/3196e2996f613a2e3568a791c503306b7c58d593
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