Commit Graph

43 Commits

Author SHA1 Message Date
Karel Zak e0e2975998 rev: report line on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-04 13:20:56 +01:00
Karel Zak 303ff21ea7 rev: be careful with close()
Addresses: https://github.com/karelzak/util-linux/issues/807
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-13 12:59:39 +02: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
Sami Kerola 25ed963d02 rev: move a global variable to local scope
Mark also file names read-only.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02: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 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +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
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Tobias Stoeckmann b56b13684e rev: Avoid out of boundary read
Check if the length of the parsed string is at least 1,
otherwise an out of boundary read would occur.
2016-10-06 14:56:39 +02:00
Tobias Stoeckmann 2571cf0f9b rev: Avoid calling free in a signal handler
free() is not a safe function for a signal handler. The next
line calls _exit() anyway, so there is no need for resource
management.
2016-10-06 14:56:39 +02: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 db433bf737 textual: use usage() text element macros
Translating these text elements should happen only once, which is
more likely when the text macros are used properly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:26 +02:00
Sami Kerola a587cc5520 textual: use manual tail usage() macro
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:24 +02:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Sami Kerola d267fdb854 rev: fix new line regression
Commit 4b4eb34004 made output incorrect for
input lines that does not have new line.  For example

$ printf "a b c\n1 2 3" | rev
c b a
 2 13

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-12 11:05:34 +02:00
Sami Kerola 4b4eb34004 rev: use string printing rather than character output
Fliping a string in memory, and printing it with multibyte output
function makes the command about 1/3 quicker.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-01 13:35:39 +02:00
Sami Kerola 67c47dff7a rev: reduce stream checking when closing read-only file descriptor
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-06-07 12:24:49 +02:00
Sami Kerola b2e081ce0f rev: simplify new line detection and impossible test
The new line detection is earlier using only '\n' so there should not be
need to search for '\r' later.

The detection whether allocated address is pointing to null seems to be
unnecessary.  Assuming xmalloc() returned valid address space the address
should never be 0.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-06-07 12:24:47 +02:00
Sami Kerola 7c7061f771 rev: stop adding new line at the end when input does not have it
When the rev(1) is executed twice outcome is expected to be exactly what
it was originally.  That includes not adding new line at the end of the
output.  The oneliner below demonstrates earlier issue.

$ printf "abc\n123" | rev | rev

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-06-07 12:24:46 +02:00
Sami Kerola 3acc206d39 various: fix variable and function declarations [smatch scan]
disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code
fdisks/sfdisk.c:982:5: warning: mixing declarations and code
fdisks/sfdisk.c:1254:5: warning: mixing declarations and code
fdisks/sfdisk.c:1564:5: warning: mixing declarations and code
lib/mbsalign.c:279:7: warning: mixing declarations and code
libblkid/src/devname.c:378:17: warning: mixing declarations and code
libfdisk/src/alignment.c:219:9: warning: mixing declarations and code
term-utils/wall.c:111:9: warning: mixing declarations and code
text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks'
text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line'
text-utils/rev.c:105:9: warning: mixing declarations and code
text-utils/tailf.c:245:9: warning: mixing declarations and code

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:17:20 +02:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01: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
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 66b0b03e05 rev: mark signo unused in sig_handler
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-01 09:07:52 +02:00
Sami Kerola ca96c6ac52 rev: option parsing bug fixed & long options added
The former getopts segment gave impression unknown options will
cause the program to exit with error and help is available with
-h. Neither work quite as designed, all unknown options made the
program to exit with success; and none of the options where
known.

The fix also has support for long options, and new --version
switch.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-06 10:48:35 +02:00
Sami Kerola 2226064c52 rev: memory leak fix
Moving the malloc out of loop will make leak to disappear, and
the command might run few jiffie quicker when there are 1+N
arguments.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-06 10:45:02 +02:00
Sami Kerola 099bce7f5d rev: use xrealloc from xalloc.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-06 10:44:59 +02:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Davidlohr Bueso 3924d0f169 rev: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 15:17:11 +01:00
Marek Polacek 50644ff4de use _exit() instead of exit() in sighandlers
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
2010-10-29 13:26:25 +02:00
Davidlohr Bueso 06eee0d84f rev: coding style, various fixes
* Change indentation to 8 characters and coding style, for better reading the code.

 * Add some memory allocation error handling.

 * Fix memory leaks. In cases when Ctrl-C is used to exit the program,
  'p' cannot be freed, so made it a global var, to share between main()
   and sig_handler(). Signal handing is necessary to fix some leaks, so
   added a very basic, non invasive, mechanism.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-20 12:05:42 +02:00
Li Zefan fffe39059d rev: use warn() in errs.h
The function warn() in rev.c is actually duplicate code,
so here we remove it.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-10-25 21:50:59 +02:00
Karel Zak ffc4374869 Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
Karel Zak c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak 22853e4a82 Imported from util-linux-2.10m tarball. 2006-12-07 00:25:43 +01:00
Karel Zak eb63b9b8f4 Imported from util-linux-2.10f tarball. 2006-12-07 00:25:41 +01:00
Karel Zak 7eda085c41 Imported from util-linux-2.9v tarball. 2006-12-07 00:25:39 +01:00
Karel Zak 2b6fc908bc Imported from util-linux-2.8 tarball. 2006-12-07 00:25:35 +01:00
Karel Zak fd6b7a7ffc Imported from util-linux-2.7.1 tarball. 2006-12-07 00:25:34 +01:00
Karel Zak 726f69e29c Imported from util-linux-2.5 tarball. 2006-12-07 00:25:33 +01:00
Karel Zak 6dbe3af945 Imported from util-linux-2.2 tarball. 2006-12-07 00:25:32 +01:00