tools: data_to_source: fix types of generated variables
Both data array and its size should be constant so that GCC can do
as much as possible at compile time and it is safe to use them in
static assertions.
This patch also changes the type of size constant to size_t which
more appropriate and uses sizeof() to determine the size of the
array.
Fixes build breakage introduced in e547662664
.
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
This commit is contained in:
parent
219f6c904a
commit
669e389c33
|
@ -63,10 +63,11 @@ main(int argc, const char* const* argv)
|
|||
unsigned char buffer[kBufferSize];
|
||||
char lineBuffer[128];
|
||||
|
||||
sprintf(lineBuffer, "unsigned char %s[] = {\n", dataVarName);
|
||||
sprintf(lineBuffer, "#include <stddef.h>\n");
|
||||
write_string(outFD, lineBuffer);
|
||||
sprintf(lineBuffer, "const unsigned char %s[] = {\n", dataVarName);
|
||||
write_string(outFD, lineBuffer);
|
||||
|
||||
off_t dataSize = 0;
|
||||
off_t offset = 0;
|
||||
char* lineBufferEnd = lineBuffer;
|
||||
*lineBufferEnd = '\0';
|
||||
|
@ -81,8 +82,6 @@ main(int argc, const char* const* argv)
|
|||
if (bytesRead == 0)
|
||||
break;
|
||||
|
||||
dataSize += bytesRead;
|
||||
|
||||
// write lines
|
||||
for (int i = 0; i < bytesRead; i++, offset++) {
|
||||
if (offset % kCharsPerLine == 0) {
|
||||
|
@ -109,8 +108,8 @@ main(int argc, const char* const* argv)
|
|||
}
|
||||
|
||||
// close the braces and write the size variable
|
||||
sprintf(lineBuffer, "};\nlong long %s = %lldLL;\n", sizeVarName,
|
||||
(long long)dataSize);
|
||||
sprintf(lineBuffer, "};\nconst size_t %s = sizeof(%s);\n", sizeVarName,
|
||||
dataVarName);
|
||||
write_string(outFD, lineBuffer);
|
||||
|
||||
close(inFD);
|
||||
|
|
Loading…
Reference in New Issue