From 76961247726d62e605fbe2c08bb3666dc5f8cac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 18 Jan 2005 03:29:13 +0000 Subject: [PATCH] allocating buffers of size known at runtime is a GCC feature, now allocates on the heap, but it should be rewritten to write smaller chunks of the attribute at a time to support potentially huge ammounts of attribute data, but not tonight git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10823 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/catattr.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apps/bin/catattr.cpp b/src/apps/bin/catattr.cpp index 87a04ef690..801c29cf51 100644 --- a/src/apps/bin/catattr.cpp +++ b/src/apps/bin/catattr.cpp @@ -83,13 +83,16 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) if (!keepRaw && size > 64 * 1024) size = 64 * 1024; - char buffer[size]; + char* buffer = new char[size]; ssize_t bytesRead = fs_read_attr(fd, attribute, info.type, 0, buffer, size); - if (bytesRead < 0) + if (bytesRead < 0) { + delete[] buffer; return errno; + } if (bytesRead != size) { fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); + delete[] buffer; return B_ERROR; } @@ -99,6 +102,7 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) for (int32 i = 0; i < info.size; i++) { putchar(buffer[i]); } + delete[] buffer; return B_OK; } @@ -148,6 +152,7 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw = false) break; } + delete[] buffer; return B_OK; }