The first char is not missing since you have read it into variable r.
read(r, s);
lucamar@Diana$ a=$(head -c 64 /dev/urandom | xxd -p); echo "$a"; echo ""; echo "$a" | ./project1
4d771918afc5d672a44fba18c5c0728f8693c5831e3cf640b5976ae96c36
f6ac78f1c8bedeef6860ff25495269780a424c2c70abe702b194fe31c271
21a9b63e
r=4 s=d771918afc5d672a44fba18c5c0728f8693c5831e3cf640b5976ae96c36
r=#10 s=f6ac78f1c8bedeef6860ff25495269780a424c2c70abe702b194fe31c271
r=#10 s=21a9b63e
r=#10 s=
* DONE: end of file!
You should always remember that both Input and Output (and ErrorOut) are Text files, so they adhere to the conventions of that type.
read() on stdin is geared to read up to a LineBreak character. This is expected behavior for a console application reading user input. (duh) This is very, very bad for reading streams from piped standard input. The way read() interprets and drops control, tab, and line feed characters is totally incompatible with reading piped standard input, unless your only objective is human-readable text. But I'm looking at reading untyped binary input, where all the bytes are crucial.
Because read() only reads up to LineBreak, casting it to an array leaves arrays with lots of null bytes after the slot that LineBreak char would be located, if it were reading binary without interpreting breaks. This behavior makes it useless for my particular case. I need EVERY BYTE (all of them, no exceptions) to be castable to arrays, as loosing a single byte in a stream breaks a hash algorithm.
LineBreak is set in system files of the compiler somewhere, is it not? There's also a command to change the way a read or write operation interprets which characters are LineBreak, correct?
The simplest solution I see at this point is, to instruct the text stream input, to stop interpreting LineBreak characters so that every byte in the buffer will be cast to the char array. So when read() sees the LineBreak (#10, #13) chars, it just reads them like any other chars, filling up the entire array buffer.
sb@Merkur:~$ hexdump -C Exchange/test.bin
00000000 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 |................|
00000010
D:\fpc\git>.\testoutput\tfiletest.exe < x:\test.bin
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16