summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/strutils: keep static analyzer happy [coverity scan]Karel Zak2019-05-151-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: parse_size() fix frac digit calculationKarel Zak2019-05-131-10/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Old code: ./test_strutils --size 0.5MiB 0.5MiB : 512000 : 500K : 500 KiB ./test_strutils --size 0.50MiB 0.50MiB : 5120000 : 4.9M : 4.9 MiB New code: ./test_strutils --size 0.5MiB 0.5MiB : 524288 : 512K : 512 KiB ./test_strutils --size 0.50MiB 0.50MiB : 524288 : 512K : 512 KiB Note that the new implementation also does not use float points, because we need to support PiB and so on... it seems good enough for things like: ./test_strutils --size 7.13G 7.13G : 7656104581 : 7.1G : 7.1 GiB ./test_strutils --size 7.16G 7.16G : 7690675814 : 7.2G : 7.2 GiB to avoid situation where cfdisk creates partition with completely crazy numbers. Addresses: https://github.com/karelzak/util-linux/issues/782 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: parse_size() fix frac with zerosKarel Zak2019-05-131-7/+12
| | | | | | Fix 0.001G as well as accept 0.000G as valid number. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: support two decimal places in size_to_human_string() outputKarel Zak2019-02-121-4/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: return from xstrmode()Karel Zak2018-09-141-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: follow const in parse_size()Karel Zak2018-07-201-13/+15
| | | | | | | | | * don't cast from char to const char * don't share endptr from strtoxxx() with rest of the code as the end pointer is char, but code works with const chars Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: remove redundant conditionKarel Zak2018-07-181-1/+1
| | | | | | | [util-linux-2.32.1/lib/strutils.c:122]: (style) Redundant condition: If 'EXPR == '0'', the comparison 'EXPR' is always true. Reported-by: David Binderman <dcb314@hotmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix strnlen() fallbackKarel Zak2018-05-281-2/+2
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/643 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: fix strutils.h, remove STRTOXX_EXIT_CODERuediger Meier2017-06-221-0/+6
| | | | | | | | | As discussed on the mailing list. We fix all places where the non-working define STRTOXX_EXIT_CODE was used. Regarding tunelp, also see 7e3c80a7. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/strutils: fix typos in huge size suffixesKarel Zak2017-04-031-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: return end pointer by isdigit_string()Karel Zak2017-01-281-2/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use unique ifdefs for testsKarel Zak2017-01-041-2/+2
| | | | | | | Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more robust. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,strutils: add strtoux[16|32|64]_or_err functionsHeiko Carstens2016-11-091-6/+38
| | | | | | | Add helper functions which allow to parse hexadecimal numbers. Based on a patch from Clemens von Mann. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* libmount: ignore redundant slashesKarel Zak2016-08-081-28/+72
| | | | | | | | | | | | | | | ///aaa/bbb and /aaa/bbb/ are the same paths. This is important especially with NFS where number of slashes are not the same in the /proc/self/mountinfo and fstab or utab. The regular URI is euler://tmp but /proc contains euler:/tmp Reported-by: Ales Novak <alnovak@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-1/+1
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* lib/timeutils: add strxxx_iso() functionsKarel Zak2016-05-111-0/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: use int for fgetc()Karel Zak2016-04-041-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* partx: fix --nr usageKarel Zak2016-03-221-1/+1
| | | | | Reported-by: Serge van den Boom <serge+util-linux@vdboom.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve conversion from root= to the devnameKarel Zak2016-03-151-0/+9
| | | | | | | | Currently the code supports /dev/name or PARTUUID= only. We also need to support 'maj:min' and 'hexhex' notations. Reported-by: George Spelvin <linux@horizon.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: never cast void* from malloc(3) and friendsRuediger Meier2016-03-071-1/+1
| | | | | | | | | | Such cast could hide serious compiler warnings in case we are missing includes (e.g. <stdlib.h> or "xalloc.h"). See http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/strutils: parse_size(), sync errno and return valueRuediger Meier2016-02-211-2/+4
| | | | | | | | Maybe strtosize_or_err() is the only function which uses this errno (wrongly). But it doesnt hurt to maintain rc as well as errno. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/strutils: add more ERANGE messagesRuediger Meier2016-02-211-12/+16
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/strutils: fix errno usage in strtoint functionsRuediger Meier2016-02-211-10/+11
| | | | | | | | | | | | | | | Don't use undefined errno: $ ./logger --no-act -t "wtf" --id="" message logger: failed to parse id: '': No such file or directory Don't print useless EINVAL message but ERANGE only: $ ./logger --no-act -t "wtf" --id="XX" message logger: failed to parse id: 'XX': Invalid argument Note the ERANGE-only improvement does not change anything on Linux/c99 as strtoul(3) only set ERANGE there. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib: rename strmode() and setmode()Ruediger Meier2016-02-181-1/+1
| | | | | | On BSD they are part of the standard C library. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: fix some printf format stringsRuediger Meier2016-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the warnings below for OSX clang and add a few more casts for timeval: lib/at.c:131:27: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'off_t' (aka 'long long') [-Wformat] printf("%16jd bytes ", st.st_size); ~~~~~ ^~~~~~~~~~ lib/strutils.c:522:52: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix); ~~~ ^~~~ lib/sysfs.c:468:42: warning: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] len = snprintf(buf, sizeof(buf), "%ju", num); ~~~ ^~~ libuuid/src/gen_uuid.c:316:34: warning: format specifies type 'unsigned long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Wformat] clock_seq, last.tv_sec, last.tv_usec, adjustment); ^~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/strutil: fix parse_switch resource leak [coverity scan]Andreas Henriksson2015-08-311-2/+5
| | | | Signed-off-by: Andreas Henriksson <andreas@fatal.se>
* lib/strutils: make strmode() more genericKarel Zak2015-06-301-17/+19
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rtcwake: improve read_clock_mode()Sami Kerola2015-06-291-0/+12
| | | | | | | | Make skipping two lines more robust, and add message about unexpected adjfile contents when running with --verbose. Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strv: add new functions (from systemd)Karel Zak2015-05-151-0/+100
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix string_add_to_idarray() int vs. size_tKarel Zak2015-04-221-3/+2Star
| | | | | | | | | | | | | | | | | | | | The function uses "int" as argument, but for array size (and index) is better to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk) and "int" in lib/strutils.c then result is unexpected behavior on ppc64. # sfdisk --list -o DEVICE,START,SIZE /dev/sdb Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 32768 bytes Disklabel type: gpt Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539 lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed. The patch cleanup all code to use size_t everywhere. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: extend parse_switch() to accept more optionsKarel Zak2015-02-241-6/+24
| | | | | | | * allow to specify more 0|1 pairs * allow to specify error message Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: move parse_switch() from setterm(1) to librarySami Kerola2015-02-241-0/+8
| | | | | | | To allow sharing the code with other utilities. Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: accept not just 'B' but also lowercase 'b' in a size suffixBenno Schulenberg2015-02-021-2/+2
| | | | | | | Just line 'M' and 'm' are accepted for mega, 'G' and 'g' for giga, 'S' and 's' for sectors, and so on. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: fix some typosSami Kerola2014-07-131-1/+1
| | | | | | | Found with misspell-check version 2.0d. Reference: https://github.com/lyda/misspell-check Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libsmartcols: rewrite test code to tree(1)-like utilKarel Zak2014-04-081-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix parse_size() return codeKarel Zak2014-03-111-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: support dec.points in parse_size()Karel Zak2014-03-111-2/+43
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: use proper return codes in parse_size()Karel Zak2014-03-111-9/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: optimalize {starts,ends}with()Karel Zak2013-09-101-66/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: move *swith() functions to private librarySami Kerola2013-08-291-0/+67
| | | | | | | | Avoid code dublication in libmount and time-util. Proposed-by: Karel Zak <kzak@redhat.com> Reference: http://markmail.org/message/h7zexvqsieqngtmx Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strutils: add strtotimeval_or_err()Karel Zak2013-03-131-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: simplify strtosize(), return info about suffixKarel Zak2013-03-111-37/+28Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: add callback for ask-numbers APIKarel Zak2013-03-111-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Implement mempcpy() in terms of memcpy() if mempcpy() is unavailableDaniel Trebbien2013-01-311-0/+7
|
* lib/strutils: add string_add_to_idarray() - parse and add to id listMilan Broz2012-07-261-0/+27
| | | | | Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: circumvent missing localeconv()maximilian attems2012-06-051-1/+1
| | | | | | | Add stub too nls.h, include it instead of locale.h. Code in strutils handles already returned NULL. Signed-off-by: maximilian attems <max@stro.at>
* lib/strutils: create type specific strtoxx_or_err()Karel Zak2012-05-151-21/+74
| | | | | | | We need [un]signed int ([u]int32_t) on many places. It's also more readable and robust to use uintXX_t types than for example "long long". Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: add string_to_bitmask()Karel Zak2012-05-031-0/+43
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Fix typos found by misspellingsBernhard Voelker2012-04-231-1/+1
| | | | | | | | | | | | | | | The tool misspellings (https://github.com/lyda/misspell-check) detected several typos. Command used: $ git ls-files | grep -v ^po/ | misspellings -f - * isosize: Fix typo in usage string. * configure.ac: Fix typo in help string of --enable-most-builds option. * fdisk: Fix typo in man page. * libblkid, blkid, mount: Likewise. * Fix various typos in docs and in source code comments. Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
* strutils: return success on test programDavidlohr Bueso2012-04-101-1/+1
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>