Commit Graph

53 Commits

Author SHA1 Message Date
Karel Zak 0461279ab3 pg: do not use atoi()
Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-25 10:24:35 +02:00
Karel Zak 1d5c14ae1a misc: improve string to number conversions
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-24 16:42:53 +02:00
Egor Chelak 1b10fa0ef7 cast NULL to char * when using execl
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.

The call in newgrp.c was changed for consistency.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-10-29 19:49:07 +02:00
Karel Zak 42fa381b9d pg: fix wcstombs() use
The size (3rd) argument should be ignored if the 1st *dest is NULL, but it seems gcc & glibc headers
are more pedantic now:

ext-utils/pg.c:456:13: error: argument 1 is null but the corresponding size argument 3 value is 2048 [-Werror=nonnull]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-01 11:54:07 +02:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 62fa0883be text-utils: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:40:43 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Karel Zak 3947ca4ca9 build-sys: ncurses headers cleanup
* assume ncursesw headers in ncursesw/ directory only
* prefer long paths, <term.h> and <ncurses.h> should be last
  possibility
* fix typos

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-31 11:01:46 +02:00
Karel Zak 2ac1bc84d7 text-utils: use proper paths to term.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-30 17:15:37 +02:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Ruediger Meier 332123f2b6 misc: fix some compiler warnings
libsmartcols/samples/fromfile.c:59:2: warning: passing argument 3 of 'string_to_bitmask' from incompatible pointer type
  text-utils/pg.c:79:0: warning: "TABSIZE" redefined
  libblkid/src/read.c:455:13: warning: 'debug_dump_dev' defined but not used [-Wunused-function]
  libblkid/src/probe.c:769:13: warning: unused function 'cdrom_size_correction' [-Wunused-function]
  /usr/include/sys/termios.h:3:2: warning: "this file includes <sys/termios.h> which is deprecated, use <termios.h> instead" [-W#warnings]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:24 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Ruediger Meier eaac9f88f9 misc: fix some includes
features.h:  any glibc header includes this already
libgen.h:    was unused there
sys/uio.h:   for writev(3p)
sys/queue.h  seems like it was never used

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:04:56 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola 7d2600e2d0 docs: update deprecation banners
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:11 +02:00
Karel Zak 938029c668 pg: use LC_ALL
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-18 11:38:02 +02:00
Jari Aalto 34e38ad0c3 pg.c: Add --help and --version
[kzak@redhat.com: - use USAGE_{HELP,VERISON} macros]

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-18 10:49:35 +02:00
Sami Kerola 944ab4b931 pg: check writing to a file was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:26:06 +02:00
Karel Zak 765056b372 pg: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 16:16:46 +01:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:17 +01:00
Sami Kerola bb7ae5bfa7 pg: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:53:59 +02:00
Sami Kerola 7d35cf4e57 pg: do not turn off warnigns artificially
Compiler warnings often mean something, fiddling with them is not good
practise.  Besides the 'proglem' removed macro tried to 'fix' does not
even occur when compiling with modern gcc.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:47:43 +02:00
Sami Kerola 69f3ff5e7e pg: use unistd.h STDOUT_FILENO
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:47:42 +02:00
Sami Kerola f494ef65e0 pg: add noreturn function attributes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:47:40 +02:00
Sami Kerola 8b8f3fa5d9 pg: add const qualifiers where suitable
Includes a fix also to one assignment warning (see below).

text-utils/pg.c:1477:24: warning: assignment discards 'const' qualifier \
from pointer target type [enabled by default]

[kzak@redhat.com: - use const char rather than xstrdup() for static /bin/sh string]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-15 16:34:59 +02:00
Sami Kerola 5ad961719d pg: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:19:35 +02:00
Sami Kerola f2d2af5e3c pg: refactor argument handing
Add function parse_arguments(), which has the same code block that was in
over long, and too deeply intended, main().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:19:35 +02:00
Sami Kerola 2e472189c1 pg: check numeric user inputs
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-15 15:54:25 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Petr Uzel e12c9866b5 include: rename writeall.h to all-io.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:32:27 +02:00
Sami Kerola b87cbe8486 text-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:45:41 +02:00
Sami Kerola 397f499613 pg: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola b6415f1243 pg: correct version printing in help screen
Commit also adds -V option.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Karel Zak f144a2f543 pg: fix write_all() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-17 00:30:13 +02:00
Karel Zak ba14e04d72 pg: fix compiler warnings [-Wunused-result]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-02 13:55:30 +02:00
Sami Kerola a699625d79 pg: return value warning fix
void function 'makeprint' should not return void expression

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-01 09:07:54 +02:00
Sami Kerola f13616a064 pg: use size_t for wcstombs() return code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-01 09:07:47 +02:00
Davidlohr Bueso f3a342a429 pg: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 14:03:08 +01:00
Mike Frysinger 45b1087e74 pg: command enters infinite loop
In a multibyte locale such as en_GB.UTF-8, the pg command cannot handle files
containing a form feed character (ASCII 0x0c) at the start of a line. The
program enters an infinite loop.

I've traced the problem to the function endline_for_mb in file pg.c. The code
assumes that the libc function wcwidth will return a nonnegative value, which
is not true for a form feed character. wcwidth returns -1 and the unsigned
variable "pos" goes into underflow.

I'll attach a patch which tests whether the character is printable before
calling wcwidth. If not, it uses instead the width of the constant L'?' which
is later used to replace nonprintable characters. I trust that we can assume
printability of this constant :-)

Steps to Reproduce:
1. Select a multibyte locale (tested with en_GB.UTF-8)
2. Create a file with a form feed character (0x0c) at the start of a line.
3. Try to display this file using the pg command.

Reported-by: Mark Calderbank <m.calderbank@iname.com>
Reported-by: Mike Frysinger <vapier@gentoo.org>
Addresses: https://bugs.gentoo.org/297717
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-01-04 09:49:23 +01:00
Peter Breitenlohner d5004be1f5 pg: compiler warning with NLS disabled
Signed-off-by: Peter Breitenlohner <peb@mppmu.mpg.de>
2009-07-20 15:23:40 +02:00
Karel Zak 126836e852 pg: add gettext call for the help string
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-12-12 15:13:44 +01:00
Pedro Ribeiro 7c7f4ff8e0 pg: several strings without gettext calls
Signed-off-by: Pedro Ribeiro <p.m42.ribeiro@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-10-03 09:31:44 +02:00
Rajeev V. Pillai 2b00dd6d54 pg: fix segfault on search
Run pg(1) and type '/<CR>' which is supposed to forward search for the
previously remembered search string. pg(1) will segfault after printing
"No remembered search string:".

Signed-off-by: Rajeev V. Pillai <rajeevvp@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-10-03 22:39:27 +02:00
Mike Frysinger 8b7f16fc37 build-sys: nls/locale handling in util-linux-ng general
On Monday 03 September 2007, Karel Zak wrote:
> http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/590/focus=592
>
>  I agree that we need a better support for compilation without
>  locales, but from my point of view NLS != all locales stuff. The NLS
>  support is subset only.

thinking about the input from everyone, i'd propose the attached ...

Only pull in locale.h as needed and move it to the common nls.h.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2007-09-19 23:15:21 +02:00
Karel Zak 06b04b23cd build-sys: fix ifdef ENABLE_WIDECHAR usage
There has been unexpected mix of HAVE_WIDECHAR and ENABLE_WIDECHAR macros. The
ENABLE_WIDECHAR is old version and has to be replaced everywhere otherwise we
will see bugs with multibyte stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-01-30 13:49:50 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +01:00