summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
AgeCommit message (Collapse)AuthorFilesLines
2019-11-04tree-wide: drop locale.h when locale-util.h is includedYu Watanabe1-1/+0
2019-11-04tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe1-1/+0
2019-10-31tree-wide: drop missing.hYu Watanabe1-1/+1
2019-06-19util: introduce format_bytes_full()Yu Watanabe1-41/+0
And move it into format-util.c.
2019-05-29util: add assertionsYu Watanabe1-0/+3
2019-05-29util: introduce parse_ifindex_or_ifname()Yu Watanabe1-0/+19
2018-12-06missing: drop old OOM related definitionsYu Watanabe1-0/+1
These are exposed earlier than linux-3.11. Let's just include linux/oom.h.
2018-11-30parse-util: allow parse_boolean() to take a NULL argumentLennart Poettering1-1/+2
It's pretty useful to allow parse_boolean() to take a NULL argument and return an error in that case, rather than abort. i.e. making this a runtime rather than programming error allows us to shorten code elsewhere.
2018-11-29parse-util: rework parse_dev() based on safe_atou() and ↵Lennart Poettering1-6/+20
DEVICE_MAJOR_VALID()/DEVICE_MINOR_VALID() Let's be a bit more careful when parsing major/minor pairs, and filter out more corner cases. This also means using safe_atou() rather than sscanf() to avoid weird negative unsigned handling and such.
2018-11-28networkd: add support to configure ip rule port range and protocol.Susant Sahani1-0/+20
Please see: iprule: support for ip_proto, sport and dport match options https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f686f764682745daf6a93b0a6330ba42a961f858 Closes 10622
2018-09-30trivial: fix spelling in code commentsThomas Haller1-1/+1
Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
2018-07-25parse-util: in parse_permille() check negative earlierLennart Poettering1-3/+4
If 'v' is negative, it's wrong to add the decimal to it, as we'd actually need to subtract it in this case. But given that we don't want to allow negative vaues anyway, simply check earlier whether what we have parsed so far was negative, and react to that before adding the decimal to it.
2018-06-14tree-wide: remove Lennart's copyright linesLennart Poettering1-3/+0
These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
2018-06-14tree-wide: drop 'This file is part of systemd' blurbLennart Poettering1-2/+0
This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
2018-06-13basic/parse-util: remove unnecessary parenthesesZbigniew Jędrzejewski-Szmek1-1/+1
2018-06-09parse-util: add permille parser + testsMarc Kleine-Budde1-0/+52
2018-05-17basic: split parsing of the OOM score adjust value into its own function in ↵Lennart Poettering1-0/+17
parse-util.c And port config_parse_exec_oom_score_adjust() over to use it. While we are at it, let's also fix config_parse_exec_oom_score_adjust() to accept an empty string for turning off OOM score adjustments set earlier.
2018-04-26parse-util: add explicit parsers for MTU valuesLennart Poettering1-0/+26
We use MTUs all over the place, let's add a unified, strict parser for it, that takes MTU ranges into account. We already have parse_ifindex() close-by, hence this appears to be a natural addition, in particular as the range checking is not entirely trivial to do, as it depends on the protocol used.
2018-04-06tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek1-13/+0
Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
2018-03-23Merge pull request #8534 from poettering/safe-atoi-fullZbigniew Jędrzejewski-Szmek1-28/+6
some improvements to safe_atou() to allow specification of arbitrary bases
2018-03-22macro: introduce TAKE_PTR() macroLennart Poettering1-2/+1
This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
2018-03-21parse-util: similar to safe_atou16_full() add safe_atou_full()Lennart Poettering1-2/+3
What's good for uint16_t is also good for unsigned. This is preparation for: #8140
2018-03-21parse-util: introduce safe_atou16_full()Lennart Poettering1-26/+3
safe_atou16_full() is like safe_atou16() but also takes a base parameter. safe_atou16() is then implemented as inline function on top of it, passing 0 as base. Similar safe_atoux16() is reworked as inline function too, with 16 as base.
2018-02-22Fix format-truncation compile failure by typecasting USB IDs (#8250)Patrick Uiterwijk1-0/+24
This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and uses that for parsing USB device and vendor IDs. This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes, the compiler does not know that. ../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size between 2 and 6 [-Werror=format-truncation=] Signed-off-by: Adam Williamson <awilliam@redhat.com> Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
2018-01-16parse-util: detect overflows in parse_percent_unbounded()Lennart Poettering1-4/+5
We shouldn't accept percentages beyon INT32_MAX and consider them valid.
2018-01-16parse-util: coding style fixLennart Poettering1-8/+8
Let's not rely on C's downgrade-to-bool feature to check for NUL bytes
2018-01-16locale-util: add freelocale() cleanup helperLennart Poettering1-8/+4
2018-01-02basic: introduce *_to_string_with_check() functionsYu Watanabe1-1/+2
They are used in later commits.
2017-11-19Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek1-0/+1
This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-11parse-util: add parse_errno() and parse_syscall_and_errno()Yu Watanabe1-0/+59
2017-10-04tree-wide: use IN_SET macro (#6977)Yu Watanabe1-1/+1
2017-07-31parse-util: introduce pid_is_valid()Lennart Poettering1-1/+1
Checking for validity of a PID is relatively easy, but let's add a helper cal for this too, in order to make things more readable and more similar to uid_is_valid(), gid_is_valid() and friends.
2017-06-06parse-util: introduce parse_dev() helperFranck Bui1-0/+15
2017-03-15fix includesMatija Skala1-1/+0
linux/sockios.h is needed for the SIOCGSTAMPNS macro xlocale.h is included indirectly in glibc and doesn't even exist in other libcs
2016-12-06core: introduce parse_ip_port (#4825)Susant Sahani1-0/+16
1. Listed in TODO. 2. Tree wide replace safe_atou16 with parse_ip_port incase it's used for ports.
2016-08-05util-lib: unify parsing of nice level valuesLennart Poettering1-1/+17
This adds parse_nice() that parses a nice level and ensures it is in the right range, via a new nice_is_valid() helper. It then ports over a number of users to this. No functional changes.
2016-08-04util-lib: add parse_percent_unbounded() for percentages over 100% (#3886)David Michael1-2/+9
This permits CPUQuota to accept greater values as documented.
2016-06-14util-lib: introduce parse_percent() for parsing percent specificationsLennart Poettering1-0/+19
And port a couple of users over to it.
2016-02-23tree-wide: minor formatting inconsistency cleanupsVito Caputo1-1/+1
2016-02-10tree-wide: remove Emacs lines from all filesDaniel Mack1-2/+0
This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
2016-01-13tree-wide: check if errno is greater than zero (2)Zbigniew Jędrzejewski-Szmek1-11/+11
Compare errno with zero in a way that tells gcc that (if the condition is true) errno is positive.
2015-12-01basic: re-sort includesThomas Hindoe Paaboel Andersen1-1/+1
My previous patch to only include what we use accidentially placed the added inlcudes in non-sorted order.
2015-11-30basic: include only what we useThomas Hindoe Paaboel Andersen1-1/+9
This is a cleaned up result of running iwyu but without forward declarations on src/basic.
2015-11-17calendarspec: sub-second support, v3Hristo Venev1-0/+36
2015-11-10parse-util: really refuse parsing negative values as positive ones, even on ↵Lennart Poettering1-34/+66
x86-32 strtoull() doesn't make it particularly easy to detect passed-in negative numbers, as it silently converts them to positive ones without generating any error. Since we are not interested in negative values we should hence explicitly filter them out by looking at the string directly and returning ERANGE if we see a leading "-". Fixes: #1829
2015-11-03parse-util: introduce parse_ifindex() and make use of it everywhereLennart Poettering1-0/+13
We have enough places where we parse an ifindex, hence introduce a proper parsing function for it, that verifies all parameters.
2015-10-27parse-util: Introduce new parse_range functionFilipe Brandenburger1-0/+39
This function will be useful for CPUAffinity settings that involve ranges of CPUs. Make it generic and include test coverage to prevent regressions.
2015-10-27util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]Lennart Poettering1-0/+408