summaryrefslogtreecommitdiffstats
path: root/include/strutils.h
Commit message (Collapse)AuthorAgeFilesLines
* include/strutils: fix potential null pointer dereferenceSami Kerola2019-05-161-1/+3
| | | | | | | | Recent lscpu fix caused gcc -Wnull-dereference to go off that this change addresses. Reference: b94acada9ed0e11a7e82f8f60280c5b6058e4250 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lscpu: move trailing null after removing characters from a stringSami Kerola2019-05-161-0/+1
| | | | | | | | | From the test input string ':' characters are removed: cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2 Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/strutils: add functions to replace and remove chars from stringKarel Zak2019-04-111-0/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: support two decimal places in size_to_human_string() outputKarel Zak2019-02-121-3/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: add str2memcpy() and mem2strcpy()Karel Zak2018-10-031-0/+28
| | | | | | | | str2memcpy() - copy zero terminated string to optionally terminated buffer mem2strcpy() - copy from buffer to zero terminated string Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: return from xstrmode()Karel Zak2018-09-141-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/strutils: remove unnecessary castKarel Zak2018-07-201-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: use strutils to trim whitespace from inputVaclav Dolezal2017-08-291-1/+1
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
* lib: fix strutils.h, remove STRTOXX_EXIT_CODERuediger Meier2017-06-221-5/+2Star
| | | | | | | | | 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: return end pointer by isdigit_string()Karel Zak2017-01-281-2/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,strutils: add strtoux[16|32|64]_or_err functionsHeiko Carstens2016-11-091-0/+3
| | | | | | | 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>
* lib/strutils: make left and right trims more robustSami Kerola2016-09-291-2/+7
| | | | | | | Do not follow null pointer, and stop going any further when ltrim_whitespace() is at the end of a string. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: ignore redundant slashesKarel Zak2016-08-081-1/+1
| | | | | | | | | | | | | | | ///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>
* lib/timeutils: add strxxx_iso() functionsKarel Zak2016-05-111-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: remove duplicate codeKarel Zak2016-04-221-4/+9
| | | | | | | | For petty long time we have strdup_to_struct_member() macro to avoid duplicate code when strdup() strings in setter functions. Let's use it for libmount. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve conversion from root= to the devnameKarel Zak2016-03-151-0/+1
| | | | | | | | 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>
* 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>
* rtcwake: improve read_clock_mode()Sami Kerola2015-06-291-0/+3
| | | | | | | | 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/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix string_add_to_idarray() int vs. size_tKarel Zak2015-04-221-1/+1
| | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | * 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/+2
| | | | | | | To allow sharing the code with other utilities. Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* strutils: fix unsigned integer overflows [AddressSanitizer]Sami Kerola2014-12-191-3/+6
| | | | | | | | | | | include/strutils.h:174:10: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long') include/strutils.h:178:6: runtime error: unsigned integer overflow: 18446744073709551615 + 1 cannot be represented in type 'size_t' (aka 'unsigned long') Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: move string trim function to strutils.hKarel Zak2014-08-251-0/+37
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* strutils: add skip_space() functionOndrej Oprala2013-11-081-0/+18
| | | | | | | | [kzak@redhat.com: - add also skip_blank(), - remove duplicate implementation from libmount] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: optimalize {starts,ends}with()Karel Zak2013-09-101-3/+40
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: move *swith() functions to private librarySami Kerola2013-08-291-0/+4
| | | | | | | | 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/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: simplify strtosize(), return info about suffixKarel Zak2013-03-111-0/+21
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: add callback for ask-numbers APIKarel Zak2013-03-111-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Implement mempcpy() in terms of memcpy() if mempcpy() is unavailableDaniel Trebbien2013-01-311-0/+3
|
* lib/strutils: add string_add_to_idarray() - parse and add to id listMilan Broz2012-07-261-0/+4
| | | | | Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: create type specific strtoxx_or_err()Karel Zak2012-05-151-2/+12
| | | | | | | 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/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: add strtosize_or_err, clean upKarel Zak2012-03-301-0/+7
| | | | | | | | | | | | * add strtosize_or_err(), we use strtosize() + err() on many places * add STRTOXX_EXIT_CODE to overwrite the default EXIT_FAILURE * remove else-after-noreturn (e.g. if (foo) err(...); else err(...)) * clean up indent... Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: ignore tailing slash in netfs source pathsPetr Uzel2011-11-081-0/+2
| | | | | | Addresses: https://bugzilla.novell.com/show_bug.cgi?id=728480 Signed-off-by: Petr Uzel <petr.uzel@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,strutils: add default value to parse_range()Davidlohr Bueso2011-10-171-1/+1
| | | | | | | | This function currently sets the low or high values to 0 when the string doesn't contain a value, like '123:' or ':123'. In order to make it more flexible, we allow it to be passed an arbitrary value. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* lib,strutils: share parse_range()Davidlohr Bueso2011-10-121-0/+2
| | | | | | | This function is currently only being used by partx(8), but it's handy and generic enough that we can use it elsewhere as well. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* lib: [strutils] add strtod_or_err() functionSami Kerola2011-09-291-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include: [strutils.c] add list parsersKarel Zak2011-07-271-0/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: add strtoul_or_err() functionSami Kerola2011-06-011-0/+1
| | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* This adds a second parameter to size_to_human_string() to return aFrancesco Cosoleto2011-05-261-1/+10
| | | | | | | | | | | | | | | string with a different format based on the following flags: SIZE_SUFFIX_1LETTER = "1K" SIZE_SUFFIX_3LETTER = "1KiB", SIZE_SUFFIX_SPACE = "1 KiB" or "1 K" [kzak@redhat.com: - rename flags to SIZE_SUFFIX_* format, - fix suffix[] buffer size - add 3 letter version to the test] Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* strutils: new wrapper function strtoll_or_errSami Kerola2011-02-211-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* partx: complete rewriteDavidlohr Bueso2010-12-091-0/+1
| | | | | | Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [strutils] move strmode() from namei.c to strutils.cKarel Zak2010-11-241-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [strutils] general purpose string handling functionsDavidlohr Bueso2010-11-231-0/+26
This patch replaces a few functions used throughout the source: * Renames getnum (from schedutils) to strtol_or_err * Moves strtosize (from lib/strtosize.c) * Moves xstrncpy (from include/xstrncpy.h) * Adds strnlen, strnchr and strndup if not available (remove it from libmount utils) A few Makefile.am files were modified to compile accordingly along with trivial renaming in schedutils source code. Signed-off-by: Davidlohr Bueso <dave@gnu.org>