home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / arch / 11990 < prev    next >
Encoding:
Text File  |  1992-12-29  |  1.9 KB  |  79 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!lyra.scs.uiuc.edu!mcdonald
  2. From: mcdonald@aries.scs.uiuc.edu (J. D. McDonald)
  3. Newsgroups: comp.arch
  4. Subject: Re: UNIX fseek time (was Re: Comparison of Alpha, MIPS and PA-RISC-II wanted)
  5. Message-ID: <mcdonald.8@aries.scs.uiuc.edu>
  6. Date: 30 Dec 92 01:05:33 GMT
  7. References: <1477@pacsoft.com> <1992Dec29.212344.20899@qb.rhein-main.de>
  8. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  9. Organization: UIUC SCS
  10. Lines: 67
  11.  
  12. In article <1992Dec29.212344.20899@qb.rhein-main.de> vhs@rhein-main.de (Volker Herminghaus-Shirai) writes:
  13.  
  14.  
  15. >Or did he mix it up with M$-DOS fseek on files opened in "text mode".
  16. >This is indeed incredibly slow because the file is searched for CR/LFs
  17. >since CR/LFs count as only one byte (a logical linefeed) in that case.
  18.  
  19. This is just plain wrong. 
  20.  
  21. A seek to a location in a text file is no slower than in a binary file.
  22.  
  23. This is because the location ... the number that the fseek is to ...
  24. can be to a number of bytes in the file ... one does **not** need to
  25. take into account the CRLF pairs. An fseek can **only** be to one of three
  26. places:
  27.  
  28. 1) the beginning
  29.  
  30. 2) the end
  31.  
  32. 3) the value returned by a previous ftell. 
  33.  
  34. The first two are trivial.
  35.  
  36. The third is also trivial ... as the ftell will never be in the middle of
  37. the crlf pair. Ftell will normally return not **the number characters 
  38. read by single getc's up to the given location** but rather the
  39. **number of bytes physically returned from the file on disk**.
  40.  
  41. EXAMPLE:
  42.  
  43. the following program:
  44.  
  45. #include <stdio.h>
  46. main()
  47. {
  48. int i,k;
  49. long j;
  50. for(i = 0; i < 7; i++) {
  51.   k = getchar();
  52.   j = ftell(stdin);
  53.   printf("%d %d %ld\n",i,k,j);
  54. }
  55. }
  56.  
  57. When fed the following input file as stdin:
  58.  
  59. 1
  60. 2
  61. 3
  62. 456
  63.  
  64. produces the following output:
  65.  
  66. 0 49 1
  67. 1 10 3
  68. 2 50 4
  69. 3 10 6
  70. 4 51 7
  71. 5 10 9
  72. 6 52 10
  73.  
  74. Note that the crlf pairs increment the ftell results by two for one
  75. read by getchar.
  76.  
  77.  
  78. Doug McDonald
  79.