Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

When does fopen not open a stream?

As we have all been taught, a sucessfull call to 'fopen' returns a stream.

If the stream is 'seekable', then we expect the calls ftell and fseek to
work, and if it is not seekable,  we expect these calls to to return
errors.

Well, we are just plain ignorant. If we open a vms "record format" file,
everything you know is wrong. I quote the "VAX C Runtime Library Reference 
Manual":

ftell - ....With record files, ftell returns the starting position of the
current record, not the current byte offset, (sic) which repositions the
file to where it was when ftell was called.

fseek - ....With record files, fseek .... causes unpredictable behavior.

But, of course, you can get a stream to act like a stream simply by
opening it with an "optional file attribute option" which is an RMS keyword
attribute pair:

 ...
 "ctx=stm"      Force stream mode access.
 ...

Oh, silly me, I thought fopen opened a stream, and that it was portable...

------

The best thing about all this is that it has changed somewhere along the
way, at some release of the VMS C RTL, this was different.

The fix to the VMS recent netcdf bug is to add "ctx=stm" to the fopen
"optional file attribute options" in netcdf/src/file.c.

Regards.
glenn

5c5
< /*    $Id: file.c,v 1.48 1991/08/01 21:00:43 davis Exp $ */
---
> /*    $Id: file.c,v 1.49 1991/08/27 02:37:02 davis Exp $ */
169c169
<               "mbf=2","mbc=16") ;
---
>               "ctx=stm","mbf=2","mbc=16") ;
474c474
<               "mbf=2","mbc=16") ;
---
>               "ctx=stm","mbf=2","mbc=16") ;


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690