home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / dec / 4631 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.4 KB

  1. Path: sparky!uunet!mcsun!sun4nl!nikhefh!t68
  2. From: t68@nikhefh.nikhef.nl (Jos Vermaseren)
  3. Newsgroups: comp.sys.dec
  4. Subject: question about files and C in VMS
  5. Message-ID: <1833@nikhefh.nikhef.nl>
  6. Date: 20 Aug 92 15:55:57 GMT
  7. Organization: Nikhef-H, Amsterdam (the Netherlands).
  8. Lines: 49
  9.  
  10.  
  11. HELP!!!!!
  12.  
  13. I have a problem with C under VMS that has bothered me and many
  14. others for a while. It has to do with filepositioning from C programs.
  15. I have to port a C program to VMS and the program will read part of a
  16. text file into a buffer. Then it may go to another part of the file
  17. (or it may not) and at a later stage I want to reposition the file and
  18. read the next so many bytes. Originally I got into problems because
  19. the read command refused to read more than one line at a time.
  20. According to the manual fread, fwrite, fseek and ftell emulate the
  21. regular C file operations, so I started using those.
  22. Problem: fseek refuses to position in the middle of a line.
  23. Solution: read (for instance) 1024 bytes, skip back to the last
  24. linefeed, recompute the position and do an fseek to this position.
  25. Suddenly this does not work anymore. It appears that the file that is
  26. to be used as input came by ftp and is not in the form of lines, but
  27. in blocks of 80 characters, no matter what characters they are.
  28. Example:
  29.     fseek(handle,0,SEEK_CUR);   /* first time might be superfluous of course */
  30.     ftell(handle);  --> 0
  31.     fread(...,1024,...);
  32.     fseek(handle,1023,SEEK_SET); /* we have to skip one back */
  33.     ftell(handle);  --> 1120   ?????
  34.  
  35.     fseek(handle,1120,SEEK_SET);
  36.     fread(...,1024,...);  This time it looses the line with 1024 in it.
  37. and after the next seek and tell it positions the file at a value which is
  38. something like 29000
  39. Other attempt:
  40.     fseek(handle,0,SEEK_CUR);   /* first time might be superfluous of course */
  41.     ftell(handle);  --> 0
  42.     fread(...,1024,...);
  43.     fseek(handle,0,SEEK_SET);
  44.     fseek(handle,1023,SEEK_CUR); /* rebuild it from the start */
  45.     ftell(handle);  --> 14   ?????
  46. Now what?
  47. Whenever I go to someone who is a local VMS guru I get this look and
  48. finally the remark: YESSSSS. This is a famous problem. If you ever
  49. find this out, please let me know.
  50. So I get the feeling that
  51. a: most of these library functions do not do what the manual says they
  52.    should do.
  53. b: nobody ever uses them anyway.
  54. Is there a global guru who can help me position my files in a filetype
  55. independent way? This would make me very happy.
  56.  
  57. Thanks in advance
  58. Jos Vermaseren
  59.