summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Kerola2013-06-02 19:51:17 +0200
committerKarel Zak2013-06-07 12:24:47 +0200
commitb2e081ce0f81f6c4d6601665bfa447da28973bf3 (patch)
tree33b2e9f915cd509f001c57dc587ac7fdf2d40f39
parentrev: stop adding new line at the end when input does not have it (diff)
downloadkernel-qcow2-util-linux-b2e081ce0f81f6c4d6601665bfa447da28973bf3.tar.gz
kernel-qcow2-util-linux-b2e081ce0f81f6c4d6601665bfa447da28973bf3.tar.xz
kernel-qcow2-util-linux-b2e081ce0f81f6c4d6601665bfa447da28973bf3.zip
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>
-rw-r--r--text-utils/rev.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 0456c2b14..1665772b2 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -154,11 +154,10 @@ int main(int argc, char *argv[])
len = wcslen(buf);
}
- t = buf + len - 1 - (*(buf+len-1)=='\r' || *(buf+len-1)=='\n');
- for ( ; t >= buf; --t) {
- if (*t != 0)
- putwchar(*t);
- }
+ if (*(t = buf + len - 1) == '\n')
+ --t;
+ for ( ; buf <= t; --t)
+ putwchar(*t);
if (!feof(fp))
putwchar('\n');
}