summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorKarel Zak2007-10-03 23:15:03 +0200
committerKarel Zak2007-10-11 13:19:55 +0200
commit642035150ec8fcb76244cf8475c5efdc7541760d (patch)
tree0a40ff376bc9cf04f6556c42454a2f39c9422951 /text-utils
parentlosetup: clean up gcc warnings (diff)
downloadkernel-qcow2-util-linux-642035150ec8fcb76244cf8475c5efdc7541760d.tar.gz
kernel-qcow2-util-linux-642035150ec8fcb76244cf8475c5efdc7541760d.tar.xz
kernel-qcow2-util-linux-642035150ec8fcb76244cf8475c5efdc7541760d.zip
tailf: clean up gcc warnings & fix use of errno
Fix strict gcc warnings in tailf that come from using: ("-Wall -Wp,-D_FORTIFY_SOURCE=2") tailf.c:111: warning: ignoring return value of 'fwrite', declared with attribute warn_unused_result Also, tailf uses perror() for error reporting, but it inserts an fprintf call first, so perror() is actually reporting the result of the fprintf() call, not the failing call; change the code to print the message by using strerror() instead. Builds cleanly on x86_32 and x86_64. Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/tailf.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index e10243f98..5b1d1a4ec 100644
--- a/text-utils/tailf.c
+++ b/text-utils/tailf.c
@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <malloc.h>
+#include <errno.h>
+#include <string.h>
#include <sys/stat.h>
#include "nls.h"
@@ -50,8 +52,8 @@ static void tailf(const char *filename, int lines)
int i;
if (!(str = fopen(filename, "r"))) {
- fprintf(stderr, _("Cannot open \"%s\" for read\n"), filename);
- perror("");
+ fprintf(stderr, _("Cannot open \"%s\" for read: %s\n"),
+ filename, strerror(errno));
exit(1);
}
@@ -83,7 +85,7 @@ int main(int argc, char **argv)
size_t osize, nsize;
FILE *str;
const char *filename;
- int count;
+ int count, wcount;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -102,13 +104,17 @@ int main(int argc, char **argv)
nsize = filesize(filename);
if (nsize != osize) {
if (!(str = fopen(filename, "r"))) {
- fprintf(stderr, _("Cannot open \"%s\" for read\n"), filename);
- perror(argv[0]);
+ fprintf(stderr, _("Cannot open \"%s\" for read: %s\n"),
+ filename, strerror(errno));
exit(1);
}
if (!fseek(str, osize, SEEK_SET))
- while ((count = fread(buffer, 1, sizeof(buffer), str)) > 0)
- fwrite(buffer, 1, count, stdout);
+ while ((count = fread(buffer, 1, sizeof(buffer), str)) > 0) {
+ wcount = fwrite(buffer, 1, count, stdout);
+ if (wcount != count)
+ fprintf (stderr, _("Incomplete write to \"%s\" (written %d, expected %d)\n"),
+ filename, wcount, count);
+ }
fflush(stdout);
fclose(str);
osize = nsize;