From c49a6908b6030d7a1d473d9abe4fc0522f87b251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 18 Jan 2005 22:37:07 +0000 Subject: [PATCH] fixed error reporting in --raw mode git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10854 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/catattr.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/apps/bin/catattr.cpp b/src/apps/bin/catattr.cpp index bfa7ff660d..10bf4c4552 100644 --- a/src/apps/bin/catattr.cpp +++ b/src/apps/bin/catattr.cpp @@ -81,8 +81,10 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) // limit size of the attribute, only the first 64k will make it on screen off_t size = info.size; - if (size > 64 * 1024) - size = 64 * 1024; +// if (size > 64 * 1024) +// size = 64 * 1024; + if (size > 64) + size = 64; char* buffer = new char[size]; ssize_t bytesRead = fs_read_attr(fd, attribute, info.type, 0, buffer, size); @@ -105,9 +107,11 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) written = write(STDOUT_FILENO, buffer, bytesRead); // check for write error if (written < bytesRead) { - fprintf(stderr, "Could only write %ld bytes to stream!\n", written); - if (written > 0) + if (written >= 0) { + fprintf(stderr, "Could only write %ld bytes to stream!\n", written); written = B_ERROR; + } else + fprintf(stderr, "Failed to write to stream: %s\n", strerror(written)); break; } // read next chunk of data at pos @@ -115,7 +119,10 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) bytesRead = fs_read_attr(fd, attribute, info.type, pos, buffer, size); // check for read error if (bytesRead < size && pos + bytesRead < info.size) { - fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); + if (bytesRead >= 0) + fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); + else + fprintf(stderr, "Failed to read from attribute: %s\n", strerror(bytesRead)); written = B_ERROR; break; }