Commit Graph

125 Commits

Author SHA1 Message Date
Sami Kerola 2afa872ffc ul.c: fix compier warnings
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola cc319747b5 ul.c: magic constant removal
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola a3b761801c ul.c: use long options
This commit introduces help & version options.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola cdbe31fc6a ul.c: convert definition to function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-17 15:56:22 +02:00
Karel Zak 0a0803460c hexdump: don't include err.h directly 2011-04-12 12:58:17 +02:00
Sami Kerola a29e40cad5 column: use xalloc lib
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-06 10:59:17 +02:00
Sami Kerola 07dcb82d06 rev: mention long options in man page
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-06 10:59:06 +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
Karel Zak 127b12dcf6 tailf: support --lines 0
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-18 09:52:07 +01:00
Karel Zak 9e57f24771 tailf: fix open() return value check [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-11 14:25:45 +01:00
Karel Zak 405265b432 tailf: fix memmove() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-08 14:13:41 +01:00
Sami Kerola 73f5a687e6 tailf: tailf mention new help & version options in man page
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-03-08 13:05:06 +01:00
Sami Kerola dc181a2115 tailf: use long options
This was TODO item from commit 947a7c9c. The patch also
introduces version and help switches.

[kzak@redhat.com: rewrite old_style_option()]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-08 13:04:09 +01:00
Ville Skyttä 821ac2c710 man page syntax fixes
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2011-03-07 10:13:46 +01:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Sami Kerola 85bf44b714 hexdump: new usage(), xalloc and err.h stuff
New usage help screen and print version switch. Also fixes to
exit codes, util linux xmalloc replaced emalloc and every error
print is using libc error function.

[kzak@redhat.com: - minor changes in formatting and coding style]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-21 14:38:23 +01:00
Sami Kerola bf6db55ad5 more: new usage output, and some trivial fixes
Usage output screen got to be completely rewrote. Aim is to
assist user to determe which switches to use without reading
manual page. The change also introduced new option to see command
version.

Determination if the executable name is `page' is now easy to see
in source, and effect of using the name is mentioned in manual
page.

Rest of the change is trivial; exit values to compiler warning
removals, magic constants to preprocessor definitions, symbolic
exit values, comment pretty printing and #endif markups.

[kzak@redhat.com: - coding style
                  - add __unused__ attribute to signal handlers]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-15 10:13:19 +01: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
Sami Kerola 395801be43 column: data type mismatch compiler warning fixes
Following warnings will longer appear when one will compile with
gcc flags -Wall -Wextra -pedantic

column.c:364:2: warning: comparison of unsigned expression < 0 is always false
column.c:369:2: warning: comparison of unsigned expression < 0 is always false

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-01-25 10:40:36 +01:00
Karel Zak bcf006d71f don't declare usage() without parametr
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-21 01:00:18 +01:00
Davidlohr Bueso 001a4424d3 column: fix column.1 typo
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-01-17 15:27:21 +01:00
Sami Kerola 604eb2602c hexdump: remove od functionality in favor to GNU coreutils od
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2010-12-30 23:11:43 +01:00
Karel Zak 601d12fb10 rename util-linux-ng back to util-linux
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-30 11:41:59 +01:00
Davidlohr Bueso 8abcf29002 lib: [strutils] general purpose string handling functions
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>
2010-11-23 21:06:49 +01:00
Karel Zak 3f7fc4d43b column: segfault on empty input
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=579955
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-04 22:22:49 +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
Davidlohr Bueso f0961db21f ul: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 15:17:10 +01:00
Karel Zak 2ebef8704d col: use err.h and EXIT_* macros
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-01 14:51:08 +01:00
Davidlohr Bueso 04faca4a13 col: use xalloc for memory allocation
Differentiate between malloc and realloc (not done so far) and get rid of local warn()

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 14:32:48 +01:00
Davidlohr Bueso b7159bd5c9 tailf: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 14:31:34 +01:00
Davidlohr Bueso 0d4e5f8e0d more: use xalloc for memory allocation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 14:31:32 +01: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
Karel Zak 5d757a9fde remove free() from atexit() callbacks
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-29 13:29:28 +02: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
Sami Kerola 1ae90932bd column: code readability improvements
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2010-10-21 09:41:38 +02:00
Sami Kerola bf90b8a6af column: error messaging & exit codes
Human understandable error messages along with symbolic exit
codes to comply with coding standard.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2010-10-21 09:41:38 +02:00
Sami Kerola 80fa094c90 column: EOF handling bug
For the last line of the file lenght of line should be determined
where the EOF is instead of new line. Old output was

$ printf "1 2\n3" | column -t
column: line too long
1 2

which this commit will change to

$ printf "1 2\n3" | column -t
1  2
3

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-21 09:38:17 +02:00
Sami Kerola 6cebde5c96 column: update manual page to match column switches
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-07 10:20:31 +02:00
Sami Kerola a4cc8dfe7d column: getopt_long and new help output
[kzak@redhat.com: - remove __progname, cleanup usage()]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-07 10:12:34 +02:00
Karel Zak 59f8c787e7 ul: use atexit() to deallocate buffer, print errors by err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-09-17 10:35:35 +02:00
Davidlohr Bueso 4727b16944 ul: fix memory leak.
The 'obuf' variable is not being freed after usage and this includes
when SIGINTs occur, hence add some basic signal handling.

[kzak@redhat.com - remove if-before-free ]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-09-17 10:02:36 +02:00
Dima Kogan 3a788d773b tailf: fixed timing issue that could cause duplicate data output
The issue is that in roll_file() we fstat() to find the file size, then read()
as much data as we can and then use the previously saved file size to mark our
position. The bug occurs if we read past the file size reported by fstat()
because more data has arrived while we were reading it. The attached patch uses
the current file position as the location marker instead, with some extra logic
to handle tailing truncated files.

[kzak@redhat.com: - fix coding style]

Signed-off-by: Dima Kogan <dkogan@cds.caltech.edu>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-20 13:15:14 +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
François Revol 1bf4407a1d portability: use standard constants
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-07-26 11:41:04 +02: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
Karel Zak 04c944419d po: fix msgid bugs
Reported-by: Petr Pisar <petr.pisar@atlas.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-12-10 13:04:41 +01:00
Américo Wang 2c9f0e8e7f hexdump: bug in hexdump when offset == file length
On Thu, Nov 26, 2009 at 03:42:21AM -0500, Mike Smith wrote:
>[mike@laptop ~]$ dd if=/dev/urandom of=testfile bs=1 count=42
>42+0 records in
>42+0 records out
>42 bytes (42 B) copied, 0.000216179 s, 194 kB/s
>[mike@laptop ~]$ hexdump -Cv testfile -s 42
>0000002a  bb b0 ba 50 fe 70 f8 d9  f7 96 36 49 e9 74 c7 bd  |...P.p....6I.t..|
>0000003a  82 cb 19 64 a6 30 53 29  d2 fa 08 e3 f4 26 7f de  |...d.0S).....&..|
>0000004a  bb 2c f2 df 7c a7 8c 6e  66 01                    |.,..|..nf.|
>00000054
>[mike@laptop ~]$ hexdump -Cv testfile -s 43
>0000002a

I think I got where the bug is, it's an off-by-one problem...

Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
2009-12-01 13:23:05 +01:00
Mike Frysinger c457971213 tailf: fix printf format
ssize_t types are shown with %zd, not %ld.

Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-11-23 10:14:56 +01:00