Hi Luigi,
I encountered an issue when trying to use PutDString.
I would like to write a blob of data to a memoryfile.
Apparently, the GetDString and PutDString show a different behavior.
Code:
PutDString VAR LENGTH [FILENUM]
example :
GetDString NAME 0x100
SetDString NAME 0x100 MEMORY_FILE
When writing a VAR that has NUL bytes embedded (because the input had them in the first place), data is padded with NUL bytes after the first \x00.
if input is :
01 02 03 04 05 00 01 02 03 04 etc.
output is (unfortunately) :
01 02 03 04 05 00 00 00 00 00 etc.
Here is the reason:
Code:
if(size > datasz) { // fill with zeroes, I avoided to use myfputc(0x00, fd);
size -= datasz;
myalloc(&buff, size, &buffsz);
memset(buff, 0, size);
if(myfw(fd, buff, size) < 0) return(-1);
}
on the other hand, GetDString does not seem to bother:
Code:
myalloc(&buff, size + 1, &buffsz);
myfr(fd, buff, size);
buff[size] = 0;
My question is, would it be possible to bypass the datasz check?
If backward compatibility is a concern, how about having an additional arg to toggle the behavior?