summaryrefslogtreecommitdiffstats
path: root/lib/path.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/path: make sure ul_path_read_buffer() derminate resultKarel Zak2019-06-171-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: use xstrncpy()Karel Zak2019-05-201-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix resource leak [coverity scan]Karel Zak2019-05-151-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix possible NULL dereferencing [coverity scan]Karel Zak2019-05-151-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix ul_path_get_dirfd() usage [coverity scan]Karel Zak2019-05-151-1/+5
| | | | | | ul_path_get_dirfd() returns negative number on error... Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: consolidate ul_path_mkpath() usageKarel Zak2019-05-151-74/+28Star
| | | | | | | * always use errno from ul_path_mkpath() * keep code simple and short as possible Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix possible NULL pointer dereferencing [coverity scan]Karel Zak2019-05-151-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add xreaddir()Karel Zak2019-04-111-15/+0Star
| | | | | | | Remove duplicate code and keep only one implementation in include/fileutils.h. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: remove extra semi-colonsKarel Zak2019-03-191-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix typos [codespell]Sami Kerola2019-02-181-2/+2
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* choom: fix negative adjust score usageKarel Zak2018-12-101-0/+22
| | | | | | | | It's really bad idea to use uint64_t (ul_path_write_u64(()) when write signed number. Addresses: https://github.com/karelzak/util-linux/issues/723 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: allow to close dirfdKarel Zak2018-12-071-3/+19
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: remove unused expressionRuediger Meier2018-06-251-1/+1
| | | | | | | error: expression result unused [-Werror,-Wunused-value] prefix = optarg, "failed to parse range start"; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: allow dir-path formattingKarel Zak2018-06-211-3/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: fix ul_path_read_string() usageKarel Zak2018-06-211-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: improve debug message on redirectKarel Zak2018-06-211-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: simplify debug messageKarel Zak2018-06-211-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_prefix_fopen(), improve cpuset funcsKarel Zak2018-06-211-2/+27
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: don't use extra '/'Karel Zak2018-06-211-4/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add more debug messagesKarel Zak2018-06-211-2/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: make ul_path_read_ usable with NULL handlerKarel Zak2018-06-211-11/+22
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_read_buffer()Karel Zak2018-06-211-0/+29
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_get_abspath()Karel Zak2018-06-211-1/+33
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix ul_path_read_string() usageKarel Zak2018-06-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: make possible to call sysfs_blkdev_deinit_path() in loopKarel Zak2018-06-211-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix read string to be backwardly compatibleKarel Zak2018-06-211-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path lib/sysfs: add debugKarel Zak2018-06-211-1/+37
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: new implementationKarel Zak2018-06-211-139/+907
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The goal is to avoid duplicate code in path.c and sysfs.c and make it possible to define prefix for paths for all sysfs and procfs based utils. Now we have /proc snapshots (for tests) for lscpu only. It would be nice to have the same (for sysfs) for lsblk and another tools. * very simple API to read numbers, strings and symlinks * based on openat() pc = ul_new_path("/sys/block/sda"); ul_path_read_u64(pc, &size, "size"); ul_path_read_u64(pc, &lsz, "queue/logical_block_size"); * printf-like API to generate paths, for example: ul_path_readf_u64(pc, &num, "sda%d/size", partno) * allow to define prefix to redirect hardcoded paths to another location, for example: pc = ul_new_path("/sys/block/sda"); ul_path_set_prefix(pc, "/my/regression/dump"); ul_path_read_u64(pc, &num, "size"); to read /my/regression/dump/sys/block/sda/size * allow to extend the API by "dialects", for example for sysfs: pc = ul_new_path(NULL); sysfs_blkdev_init_path(pc, devno, NULL); and use ul_path_* functions to read from @pc initialized by sysfs_blkdev_init_path() * add test_path binary Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: make path_set_prefix() independent on cpu_set_tKarel Zak2017-10-231-15/+14Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: fix, using freed memoryRuediger Meier2017-06-291-3/+3
| | | | | | | | | | | | | Simply avoiding strdup(). Error handling improved. This was the Clang Analyzer warning: Memory Error, Use-after-free sys-utils/lsmem.c:259:3: warning: Use of memory after it is freed err(EXIT_FAILURE, _("Failed to open %s"), path); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: add error handling to path_vcreate()Ruediger Meier2017-06-291-9/+25
| | | | | | | Do not operate on truncated/random paths. Note, path_strdup() can now really return NULL, to be handled in next commit. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: fix crash, pathbuf overflowRuediger Meier2017-06-271-4/+10
| | | | | | | | | | | | | | Before: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" Segmentation fault (core dumped) After: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" lscpu: invalid argument to --sysroot: File name too long Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: ifdef path_set_prefix() like in path.hRuediger Meier2016-02-111-2/+2
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* docs: fix two "maybe be" duplications in program commentsBenno Schulenberg2015-01-261-5/+2Star
| | | | | | Also improve the grammar of the comments and some neighbours. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* lib/path: add path_strdup()Karel Zak2014-01-061-0/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: standardize some "cannot read" and "seek failed" error messagesBenno Schulenberg2013-10-091-4/+4
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-031-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add path_read_u64()Karel Zak2012-11-231-0/+22
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: rename functions to be more explicitKarel Zak2012-11-231-8/+10
| | | | | | ... and to have names compatible with lib/sysfs.c Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: cleanup cpu_set_t usageKarel Zak2012-11-021-1/+4
| | | | | | | - make taskset depend on cpu_set_t - make cpuset.c optional for libcommon and lib/path.c Signed-off-by: Karel Zak <kzak@redhat.com>
* translation: unify file open error messagesSami Kerola2012-07-161-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include: rename writeall.h to all-io.hPetr Uzel2012-05-151-1/+1
| | | | Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* docs: corrections to FSF license files, and postal addressSami Kerola2012-02-241-3/+3
| | | | | | | | | | | | | | The COPYING and Documentation/licenses/COPYING* files are being replaced by files from GNU web site. http://www.gnu.org/licenses/gpl-2.0.txt http://www.gnu.org/licenses/lgpl-2.1.txt Postal addresses to FSF in other files are updated to match with the address in license files. Reference: http://lists.gnu.org/archive/html/freefont-announce/2005-04/msg00001.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib,path: use write_all()Heiko Carstens2011-09-271-1/+2
| | | | | | | | | From: Heiko Carstens <heiko.carstens@de.ibm.com> Since write() doesn't necessarily write the complete buffer with one call we better use write_all() which takes care of this. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* chcpu: convert to use lib/path.cHeiko Carstens2011-09-271-0/+26
| | | | | | | Use the common path access functions. In order to simplify chcpu also implement and use path_writestr() which writes a string to the path specified. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* lib,path: move path access functions from lscpu into lib/path.cHeiko Carstens2011-09-271-0/+191
A couple of these functions already have been copied to chcpu.c, so it makes sense to move these functions into an own file. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>