| If the file header says that your file has fixed length record
format with 512 byte records, then every record--including the
last--had better have 512 bytes. If the file header also says
that the end of file position is in the middle of a [the last]
record, then that file is "broken" and you should not expect
any tool that you didn't write to be able to work with it.
If the file header must store the exact end of file position,
then I would use a different RMS record format, either the
stream_lf or the undefined record formats, via
fopen(pathname, "w", "rfm=stmlf", "rat=cr", "ctx=stm")
or
fopen(pathname, "w", "rfm=udf", "rat=none", ...)
[For the undefined record formats, what is the best way to
specify the rest of the options? Maybe "mrs=512", "ctx=stm"?
Would "ctx=bin" also be needed?]
If you must have both fixed length record format and the exact
end of file position, you can always change the end of file
position in the file header using the SET FILE/ATTRIBUTE=(...)
command after creating the file. You can also probably adjust
it via RMS calls or by using ACP QIO's.
Dan
|
|
You should instruct the CRTL to process the file in stream access mode
to avoid record access mode which is the default for "rfm=fix", "mrs=512".
In record access mode the full 512-byte records are written/read.
To force stream access mode specify:
#define WRITE_BINARY "wb", "rfm=fix", "mrs=512", "ctx=stm", "rat=none"
Note, that application reading this file should also specify "ctx=stm" if
it uses the CRTL I/O, otherwise, by default, the record mode will be applied.
In record mode application will get 512-byte records and EOF will be seen
after the last record rather than immediately after the written data.
If you're not sure how the application process the file, try undefined
record format:
#define WRITE_BINARY "wb", "rat=none", "rfm=udf", "ctx=stm"
The program below illustrates the difference between record and stream
access mode.
Boris
$ say f$getsy("hw_name")
VAXstation 4000-VLC
$ say f$getsy("version")
V6.1
$ run x
record mode: bytes read: 1024
stream mode: bytes read: 520
$ anal/rms/fdl/out=tt x.x
....
RECORD
BLOCK_SPAN yes
CARRIAGE_CONTROL none
FORMAT fixed
SIZE 512
X.C
===
#include <errno.h>
#include <stdio.h>
#include <string.h>
#define WRITE_BINARY "w", "rfm=fix", "mrs=512", "ctx=stm", "rat=none"
main()
{
FILE *file;
char buf[510];
int i;
if ( !(file = fopen ("x.x", WRITE_BINARY )) )
perror("fopen for write");
memset(buf,'x',sizeof(buf));
if ( fwrite(buf, sizeof(buf), 1, file) != 1 )
perror("fwrite");
memset(buf,'y',sizeof(buf));
if ( fwrite(buf, 10, 1, file) != 1 )
perror("fwrite");
if ( fclose(file) )
perror("fclose");
if ( !(file = fopen ("x.x", "r")) )
perror("fopen for read");
for ( i = 0; fgetc(file) != EOF; i++ )
;
printf("record mode: bytes read: %d\n", i);
if ( fclose(file) )
perror("fclose");
if ( !(file = fopen ("x.x", "r", "ctx=stm" )) )
perror("fopen for read");
for ( i = 0; fgetc(file) != EOF; i++ )
;
printf("stream mode: bytes read: %d\n", i);
if ( fclose(file) )
perror("fclose");
}
|