Mantis - Quercus
Viewing Issue Advanced Details
4296 major always 11-16-10 16:15 11-16-10 16:15
fredo  
 
normal  
new 4.0.13  
open  
none    
none  
0004296: file_get_contents ignores offset parameter
php docs say:


string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )

This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.

BUT the implementation in Quercus will always return the file-contents from the start of the file
should be fixed like:

  @ReturnNullAsFalse
  public static StringValue
    file_get_contents(Env env,
                      StringValue filename,
                      @Optional boolean useIncludePath,
                      @Optional Value context,
                      @Optional("-1") long offset,
                      @Optional("4294967296") long maxLen)
  {
    if (filename.length() == 0) {
      env.warning(L.l("file name must not be null"));
      return null;
    }

    BinaryStream s = fopen(env, filename, "r", useIncludePath, context);

    if (! (s instanceof BinaryInput))
      return null;

    BinaryInput is = (BinaryInput) s;
    
    if(offset>0)
    {
        is.seek(offset, BinaryInput.SEEK_SET);
    }
    
    StringValue bb = env.createLargeBinaryBuilder();
    bb.appendReadAll(is, maxLen);

    s.close();
    return bb;
  }

There are no notes attached to this issue.