From: t68@nikhefh.nikhef.nl (Jos Vermaseren)
Subject: question about files and C in VMS
Date: 20 Aug 92 15:55:57 GMT [thread overview]
Message-ID: <1833@nikhefh.nikhef.nl> (raw)
HELP!!!!!
I have a problem with C under VMS that has bothered me and many
others for a while. It has to do with filepositioning from C programs.
I have to port a C program to VMS and the program will read part of a
text file into a buffer. Then it may go to another part of the file
(or it may not) and at a later stage I want to reposition the file and
read the next so many bytes. Originally I got into problems because
the read command refused to read more than one line at a time.
According to the manual fread, fwrite, fseek and ftell emulate the
regular C file operations, so I started using those.
Problem: fseek refuses to position in the middle of a line.
Solution: read (for instance) 1024 bytes, skip back to the last
linefeed, recompute the position and do an fseek to this position.
Suddenly this does not work anymore. It appears that the file that is
to be used as input came by ftp and is not in the form of lines, but
in blocks of 80 characters, no matter what characters they are.
Example:
fseek(handle,0,SEEK_CUR); /* first time might be superfluous of course */
ftell(handle); --> 0
fread(...,1024,...);
fseek(handle,1023,SEEK_SET); /* we have to skip one back */
ftell(handle); --> 1120 ?????
fseek(handle,1120,SEEK_SET);
fread(...,1024,...); This time it looses the line with 1024 in it.
and after the next seek and tell it positions the file at a value which is
something like 29000
Other attempt:
fseek(handle,0,SEEK_CUR); /* first time might be superfluous of course */
ftell(handle); --> 0
fread(...,1024,...);
fseek(handle,0,SEEK_SET);
fseek(handle,1023,SEEK_CUR); /* rebuild it from the start */
ftell(handle); --> 14 ?????
Now what?
Whenever I go to someone who is a local VMS guru I get this look and
finally the remark: YESSSSS. This is a famous problem. If you ever
find this out, please let me know.
So I get the feeling that
a: most of these library functions do not do what the manual says they
should do.
b: nobody ever uses them anyway.
Is there a global guru who can help me position my files in a filetype
independent way? This would make me very happy.
Thanks in advance
Jos Vermaseren
next reply other threads:[~1992-08-20 15:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-08-20 15:55 Jos Vermaseren [this message]
1992-08-20 22:00 ` question about files and C in VMS Stephen Tihor
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox