J
Jan Engelhardt
why can't it just skip these null characters until it reaches EOF,
Chris Torek wrote:
CT>On systems that really do this to you -- such as VMS or CP/M --
CT>"system-supplied" null characters are indistinguishable from
CT>user-supplied null characters. For instance:
CT>
CT> FILE *fp = fopen("somefile", "wb");
CT> if (fp != NULL) {
CT> putc(100, fp);
CT> putc(0, fp);
CT> fclose(fp);
CT> }
CT>
CT>will, on VMS, give you a 512-byte file consisting of the byte 100
CT>decimal (0x64), followed by 511 null (0x00) bytes. Remove the
CT>second putc(), and you get an *identical* 512-byte-long file. The
CT>problem then becomes deciding how many null bytes to skip.
Silly VMS.
Lew Pitcher wrote:
LP>Let's pretend that you have a CP/M text file (10 bytes of text) that you
LP>wish to find the length of in a conforming C program. You
LP>fseek(file,0,SEEK_END) on the file, opened as binary, and
LP> a) are positioned 11 bytes into the file, at the 0x1a character that
LP> demarks logical end of file, or
LP> b) are positioned 1024 bytes into the file, at the end of the last (and
LP> first) physical block that the file occupies.
LP>Which is correct to you?
b).
Chris Torek wrote:
CT>On systems that really do this to you -- such as VMS or CP/M --
CT>"system-supplied" null characters are indistinguishable from
CT>user-supplied null characters. For instance:
CT>
CT> FILE *fp = fopen("somefile", "wb");
CT> if (fp != NULL) {
CT> putc(100, fp);
CT> putc(0, fp);
CT> fclose(fp);
CT> }
CT>
CT>will, on VMS, give you a 512-byte file consisting of the byte 100
CT>decimal (0x64), followed by 511 null (0x00) bytes. Remove the
CT>second putc(), and you get an *identical* 512-byte-long file. The
CT>problem then becomes deciding how many null bytes to skip.
Silly VMS.
Lew Pitcher wrote:
LP>Let's pretend that you have a CP/M text file (10 bytes of text) that you
LP>wish to find the length of in a conforming C program. You
LP>fseek(file,0,SEEK_END) on the file, opened as binary, and
LP> a) are positioned 11 bytes into the file, at the 0x1a character that
LP> demarks logical end of file, or
LP> b) are positioned 1024 bytes into the file, at the end of the last (and
LP> first) physical block that the file occupies.
LP>Which is correct to you?
b).