This is only necessary if we use stdout fd.
function old new delta
less_exit 32 51 +19
less_main 2540 2543 +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0) Total: 22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Commit e6a2f4cc changed the way common_bufsiz1 works. Now it needs to
be initialized before using, but i2cdump wasn't updated by said patch.
Since the fact that we're using common_bufsiz1 here isn't obvious (no
G_INIT() macro, no other global variables), drop it and simply
allocate the integer array required for block reads on the stack.
Tested with i2c block read on a Lenovo Thinkpad laptop.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"
text data bss dec hex filename
829901 4086 1904 835891 cc133 busybox_before
829665 4086 1904 835655 cc047 busybox
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The non-fancy version of the from_cpuset uses CPU_SETSIZE as if it
represents the number of bytes in the cpuset, while it is actually
the number of bits. This leads to out-of-bounds accesses on the
cpu_set_t in the big-endian case. Basically all uses of CPU_SETSIZE
have to be divided by 8. This is done correctly in the fancy version
of from_cpuset.
In addition, the big-endian case is completely wrong to begin with.
All standard C libraries that I know of implement cpu_set_t as an
unsigned long array, so both for big and little endian, the least
significant bits are in the beginning of the array. Therefore, the
approach taken for the little endian case is equally valid. We only
need special handling for big endian when CPU_SETSIZE is large and
we use an unsigned long long to get more bits out.
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This makes busybox i2cdump compatible with the upstream version, which
also displays the numeric error value in case of a block read failure.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
We should bail-out if i2c_smbus_read_block_data() or
i2c_smbus_read_i2c_block_data() return 0 or less. Add the missing check
for the former and fix the existing for the latter.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Currently we're calling i2c_smbus_read_block_data() for both 'i' and 's'
mode parameters. If the bus doesn't support SMBus block mode, then the
i2c access ioctl() fails. Make i2cdump behave compatibly with upstream
version by calling i2c_smbus_read_i2c_block_data() for I2C block.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
We currently read data twice in byte mode. Add a check to avoid calling
i2c_smbus_read_i2c_block_data() if we're not in I2C or SMBus block mode.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
If the bus doesn't support SMBus Quick Write or Receive Byte commands
and we're running in auto mode all addresses will be skipped resulting
in an empty table being printed.
This is caused by not restoring the auto mode after it's been changed
for certain address ranges - we need an additional variable to hold the
temporary state.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The virtual y can be larger - and we can be even writing there since
we are taking into account the y offset. Avoids possible crash.
But use it only if set, seems it is not set if virtual area is not
allocated (though, often fbcon allocates some scrollback area).
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
MONOTONIC_SYSCALL=y by default
FEATURE_LAST_SMALL is gone: now FEATURE_LAST_FANCY is a "bool", not a "choice".
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Rename the defines not present in linux UAPI headers to better reflect
their purpose.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Most applets include linux' user API headers instead of duplicating
the definitions. Make it the case for i2c-tools as well.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Commit 1ecb996 attempted to make read_lines() use the last column of
the terminal (as re_wrap() did). There were two problems with this:
- The size of the buffer allocated for lines wasn't increased to allow
for the extra character.
- The test for width overflow was moved after the point where the
next character was added to the buffer. This caused a buffer overflow
in certain circumstances.
For example, if the line beyond the end of the display was wider than
the display read_lines() would initially read the partial line into a
buffer. When the user moved down read_lines() would be called again
to ensure the rest of the line was read. This would place the next
character in the partial line before checking for overflow.
This can be fixed by moving the test for overflow back to where it was
before commit 1ecb996 and changing the comparison to `>` rather than
`>=`.
There are two other places where buffers are created without allowing
for width+1 characters.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Test explicitly for REOPEN flags: update_num_lines is called
unconditionally so (num_lines != NOT_REGULAR_FILE) is also true when
num_lines contains a valid number of lines.
The call to fstat doesn't need to be in #if ENABLE_FEATURE_LESS_FLAGS:
the whole function is already in such a test.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
When read_lines tests whether a character will fit on the current
line it checks the *next* character but in case of overflow doesn't
display the *current* one. This results in the last column of the
terminal never being used.
The test in re_wrap (used when the terminal width changes or line
numbers are enabled/disabled) is different: it does allow the use
of the final column.
function old new delta
read_lines 764 770 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0) Total: 6 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Much of the code refers to lines using indices into the flines
array (which splits lines into portions that fit on the terminal).
In some cases this is wrong and actual line numbers should be
used:
- when lines are being truncated rather than wrapped (-S flag)
- when line numbers have been entered by the user
Also fix a bug in numeric input and improve the display at EOF.
function old new delta
goto_lineno - 111 +111
cap_cur_fline - 101 +101
buffer_to_line - 56 +56
buffer_up 35 66 +31
less_main 2606 2615 +9
goto_match 125 127 +2
buffer_down 81 56 -25
buffer_line 64 - -64
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 3/1 up/down: 310/-89) Total: 221 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Add a function to package the test that detects whether enough has
been read from the file to allow a screenful to be displayed.
Also use this to determine when to display '(END)' in the status
line. The previous code was incomplete and didn't handle truncated
lines (-S flag) properly.
function old new delta
at_end - 63 +63
status_print 111 109 -2
read_lines 819 764 -55
getch_nowait 319 264 -55
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 63/-112) Total: -49 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Move the code to detect non-regular files to the point where the
file is being opened. If num_lines == READING_FILE guarantees
that the file is regular.
Detect when a file becomes unreadable between it first being opened
and the call to update_num_lines. Mark the file as being non-regular
so we don't try that again.
function old new delta
reinitialize 197 245 +48
update_num_lines 159 127 -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-32) Total: 16 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Make verbose status messages (-m/-M flags) behave more like the
real `less` command:
- fix display of line numbers so they're correct whether lines are
being truncated (-S flag) or wrapped.
- don't display total lines or percentage when lines are read from
stdin: we don't have that information until we reach EOF. When
we do reach EOF the additional information is displayed.
- when lines are read from a file count the total number of lines
so that we can display percentages. Counting lines is avoided
until the information is actually needed. If the user pages to
EOF the separate read pass can be avoided entirely.
Fixes Bug 7586
function old new delta
m_status_print 195 382 +187
safe_lineno - 35 +35
reinitialize 172 182 +10
read_lines 675 685 +10
buffer_fill_and_print 178 169 -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 242/-9) Total: 233 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>