bugGNU Octave - Bugs: bug #54102, Origin specifier in fseek

 
 

bug #54102: Origin specifier in fseek

Submitter:  Michael Leitner <mleitner>
Submitted:  Tue 12 Jun 2018 07:27:27 AM UTC
   
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 12 Jun 2018 03:06:04 PM UTC, comment #1: 

The functionality hasn't been removed.  The numerical constant to pass to fseek is returned by the function SEEK_SET.  Instead of


fseek(fid,0,'SEEK_SET')


you should call


fseek(fid,0, SEEK_SET)


Using 'help SEEK_SET' I get


'SEEK_SET' is a built-in function from the file libinterp/corefcn/file-io.cc

 -- SEEK_SET ()
     Return the numerical value to pass to 'fseek' to position the file
     pointer relative to the beginning of the file.

     See also: SEEK_CUR, SEEK_END, fseek.


I can see how it is a little bit confusing because the @code macro for Texinfo is putting single quotes around its argument.  The help text for fseek is


octave:1> help fseek
'fseek' is a built-in function from the file libinterp/corefcn/file-io.cc

 -- fseek (FID, OFFSET)
 -- fseek (FID, OFFSET, ORIGIN)
 -- STATUS = fseek (...)
     Set the file pointer to the location OFFSET within the file FID.

     The pointer is positioned OFFSET characters from the ORIGIN, which
     may be one of the predefined variables 'SEEK_SET' (beginning),
     'SEEK_CUR' (current position), or 'SEEK_END' (end of file) or
     strings "bof", "cof", or "eof".  If ORIGIN is omitted, 'SEEK_SET'
     is assumed.  OFFSET may be positive, negative, or zero but not all
     combinations of ORIGIN and OFFSET can be realized.

     'fseek' returns 0 on success and -1 on error.


Even though the text refers to them as variables, it places them in single quotes.  I changed the Texinfo source so that the displayed help is now



octave:1> help fseek
'fseek' is a built-in function from the file libinterp/corefcn/file-io.cc

 -- fseek (FID, OFFSET)
 -- fseek (FID, OFFSET, ORIGIN)
 -- STATUS = fseek (...)
     Set the file pointer to the location OFFSET within the file FID.

     The pointer is positioned OFFSET characters from the ORIGIN, which
     may be one of the predefined variables SEEK_SET (beginning),
     SEEK_CUR (current position), or SEEK_END (end of file) or strings
     "bof", "cof", or "eof".  If ORIGIN is omitted, SEEK_SET is assumed.
     OFFSET may be positive, negative, or zero but not all combinations
     of ORIGIN and OFFSET can be realized.

     'fseek' returns 0 on success and -1 on error.


The change was made on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/41ea5f665659) and will be part of the next bug fix release.


Rik <rik5>
Group administrator
Tue 12 Jun 2018 07:27:27 AM UTC, original submission:  

Try


fid=fopen("bla","w");
fseek(fid,0,"bof")
fseek(fid,0,'SEEK_SET')
fseek(fid,0,0)
fclose(fid);


Apparently at some point the C-inspired way of specifying fseek origin has been dropped to follow Matlab and allow "cof"/0, "bof"/-1 and "eof"/1. However, this is not reflected in the documentation, which still speaks of 'SEEK_SET'/"cof" and analogues. I think that it would not hurt to relax with respect to Matlab and allow all three possibilities.

Further, is it really the best option to refuse any fseeks beyond the end-of-file? This is more or less the standard way in C to cheaply allocate large files. Yes, it seems that Matlab refuses, but this is not even documented as I see it. You could also do it and just throw a warning in this case. Or is there another good way to generate large files? Obviously an fwrite of zeros is suboptimal.

Michael Leitner <mleitner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mleitner (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-12 rik5 CategoryOctave Function Documentation
        StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code