Whenever a file is opened using the VMS C fopen function, it defaults to
stream linefeed type. This can be changed by adding more parameters to the
fopen call. However, suppose file.dat;1 exists with attributes X1 which may
not be stream linefeed (eg, created by FORTRAN). Now suppose I write a
program in C which modifies the data in file.dat;1 and creates file.dat;2.
The fopen call will create the new version with stream linefeed unless I
explicitly give it the new attributes [fopen(file.dat, "w", "rat=...", ...)].
However, suppose I do not know what the attributes of file.dat;1 are. How can
I get this information in VMS C or how do I tell the fopen to use the
previous version's file attributes?
Thanks,
--
_____________
#___/John E. Davis\_________________________________________________________
#
# internet: da...@amy.tch.harvard.edu
# bitnet: davis@ohstpy
# office: 617-735-6746
#
Short answer: You can't. No interface exists in the VAX C library that lets
you determine the file attributes of an existing file; no method exists for
telling fopen() to give a file "the same attributes" as some existing file, or
as the previous version of a file.
Longer answer: It's straightforward using RMS calls - well, as straight-
forward as *anything* using RMS calls :-) - to determine the file attributes
of an existing file. Then you can create any kind of file you want.
An alternative to hacking with RMS is to use the callable FDL routines. The
only problem then is that you'll have to parse the resulting information,
which was not really intended for "program consumption". All in all, this
is approach is probably not a win over just biting the bullet and using RMS.
The REALLY easy way to do it, I suppose, is to use system() to get COPY to
create a copy of the file (or use callable CONVERT to do the same thing),
the modify the new copy in place. This approach is neither elegant nor
efficient, and you do have to be careful to truncate the file as required.
(Then again, you could use ANALYZE/FDL and CREATE/FDL to create an empty
file with the right attributes - or, again, use the callable forms to avoid
creating a subprocess.)
Me, I'd use RMS. It's not nearly as hard as it's made out to be, and you'll
learn how to use an important VMS facility.
-- Jerry
You get the information by using the stat() or fstat() runtime library
function, as appropriate. If you've used fopen(), you use fstat().
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CA...@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
Disclaimer: Hey, I understand VAXen and VMS. That's what I get paid for. My
understanding of astronomy is purely at the amateur level (or below). So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it. If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.
What about stat(), which lets you determine:
1) File protection;
2) File owner;
3) File size;
4) Last modification time;
5) Creation time;
6) Reford format;
7) Record attributes;
8) Fixed header size; and
9) Maximum record size.
>no method exists for telling fopen() to give a file "the same attributes" as
>some existing file, or as the previous version of a file.
If you're willing to parse the definitions in FAB.H, you can quite easily come
up with something like:
#include stat
main()
{ stat_t buffer;
static char *rfms[] = { "UDF", "FIX", "VAR", "VFC", "STM", "STMLF",
"STMCR"};
char tmp[20];
stat("LOGIN.COM", &buffer);
printf("%d\n" buffer.st_fab_rfm);
sprintf(tmp, "rfm=%s", rfms[buffer.st_fab_rfm]);
creat("TEST.DAT", 0644, tmp);
}
Of course, if the definitions of the bits in FAB$B_RFM ever change, you'll
have to change your program.
>Me, I'd use RMS. It's not nearly as hard as it's made out to be, and you'll
>learn how to use an important VMS facility.
Agreed. However, as I pointed out above, it IS possible to do it without using
RMS.