Processing binary or plaintext files
I'm working on a little C program which transfers files across a [Unix] network. At the moment, it can handle things like text files just fine, but trying to read and transmit a binary executable (eg. "app1.exe") results in failure/loss of data.
I was originally using fread and fwrite, but then switched to read() and write() because read() will not go beyond the actual number of bytes remaining in the file, AND because it returns exactly how many bytes were read. IE., if I tell fread to try reading 100 bytes into my char buffer, but there are only 50 remaining in the file, it ended up polluting the buffer with "false" data past index 50. Anyway..
Is it possible to handle text AND binary files using the same IO process (that is, without coding something like an FTP binary/ascii mode) ?