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
This commit is contained in:
parent
d4578d0fe1
commit
7696124772
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user