Beispiel #1
0
unsigned int Audio::File::read(unsigned char* dst, unsigned int bytes)
{
    if (!mFile) return 0u;
    auto status = PHYSFS_readBytes(mFile, dst, bytes);
    if (status < 0) return 0u;
    return static_cast<unsigned int>(status);
}
Beispiel #2
0
static size_t file_read(void * const p, size_t len, stream_t *stream)
{
  PHYSFS_sint64 count;
  int error;
  PHYSFS_File *file;

  if (file_check_context(stream))
    return 0;

  file = stream->context.pfs.file;

  count = PHYSFS_readBytes(file, p, len);

  if (count < len && (error = PHYSFS_getLastErrorCode())) {
    s_log_error("Error reading from file stream (pfs: %s). (File: %s)",
      PHYSFS_getErrorByCode(error), stream->context.pfs.file_path);

    stream->error = STREAM_ERROR_FAILURE;

    if (count == -1)
      return 0;
  }

  return (size_t)count;
}
Beispiel #3
0
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
#endif
{
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
    const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
    const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
    if (rc != ((PHYSFS_sint64) readlen))
    {
        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
        {
            SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());

            #if TARGET_SDL2
            return 0;
            #else
            return -1;
            #endif
        } /* if */
    } /* if */

    #if TARGET_SDL2
    return (size_t) rc / size;
    #else
    return (int) rc / size;
    #endif
} /* physfsrwops_read */
Beispiel #4
0
const char* kp::file::read(const char* filename)
{
    PHYSFS_File* handle = PHYSFS_openRead(filename);

    if(handle == NULL)
    {
        //kp::debug::error("PHYSFS_openRead(%s): %s", filename, PHYSFS_getLastError());
        
        return NULL;
    }

    // Create a buffer big enough for the file
    PHYSFS_sint64 size = PHYSFS_fileLength(handle);

    // Append an extra byte to the string so we can null terminate it
    char* buffer = new char[size+1];

    // Read the bytes
    if(PHYSFS_readBytes(handle, buffer, size) != size)
    {
        //kp::debug::error("PHYSFS_read: %s", PHYSFS_getLastError());
        
        return NULL;
    }

    // Null terminate the buffer
    buffer[size] = '\0';

    // Close the file handle
    PHYSFS_close(handle);

    return buffer;
}
Beispiel #5
0
size_t ex_fsys_fread ( ex_file_t *_file, void *_buf, uint64 _size ) {
#if 0
    return (size_t)PHYSFS_readBytes( _file, _buf, _size );
#else
    return (size_t)PHYSFS_read( _file, _buf, 1, (uint)_size );
#endif
}
Beispiel #6
0
sf::Int64 sf::PhysFSStream::read(void* data, sf::Int64 size)
{
#if (PHYSFS_VER_MAJOR >= 2 && PHYSFS_VER_MINOR >= 1)
	return PHYSFS_readBytes(file, data, (PHYSFS_uint32)size);
#else
	return PHYSFS_read(file, data, 1, (PHYSFS_uint32)size);
#endif
}
Beispiel #7
0
static size_t SDL_RWopsRead(SDL_RWops *ops, void *buffer, size_t size, size_t maxnum)
{
	PHYSFS_File *f = sdlPHYS(ops);

	if (!f)
		return 0;

	PHYSFS_sint64 result = PHYSFS_readBytes(f, buffer, size*maxnum);

	return (result != -1) ? (result / size) : 0;
}
Beispiel #8
0
size_t
OggSoundFile::cb_read(void* ptr, size_t size, size_t nmemb, void* source)
{
    auto file = reinterpret_cast<PHYSFS_file*> (source);

    PHYSFS_sint64 res
        = PHYSFS_readBytes(file, ptr, static_cast<PHYSFS_uint32> (size) * static_cast<PHYSFS_uint32> (nmemb));
    if(res <= 0)
        return 0;

    return static_cast<size_t> (res) / size;
}
Beispiel #9
0
static size_t physfsrwops_read(SDL_RWops *rw, void *ptr, size_t size, size_t maxnum)
{
    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
    PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, size * maxnum);
    if (rc != size * maxnum)
    {
        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
            SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
    } /* if */
	
    return rc;
} /* physfsrwops_read */
Beispiel #10
0
int
IFileStreambuf::underflow()
{
  if(PHYSFS_eof(file)) {
    return traits_type::eof();
  }

  PHYSFS_sint64 bytesread = PHYSFS_readBytes(file, buf, sizeof(buf));
  if(bytesread <= 0) {
    return traits_type::eof();
  }
  setg(buf, buf, buf + bytesread);

  return buf[0];
}
Beispiel #11
0
static const char* next_line( char* line, int* len, PHYSFS_File* file )
{
  int end = 0;

  if ( *len != 0 )
  {
    memmove( line, line + *len + 1, MAXLEN - *len - 1 );
    end = MAXLEN - *len - 2;
  }

  PHYSFS_sint64 num_read = PHYSFS_readBytes( file, line + end, MAXLEN - end - 1 );

  if ( num_read == -1 )
  {
    num_read = 0;
  }

  line[ num_read + end ] = 0;
  char* newline = strchr( line, '\n' );

  if ( newline != NULL )
  {
    *newline = 0;
    *len = newline - line;

    if ( newline > line && newline[ -1 ] == '\r' )
    {
      newline[ -1 ] = 0;
    }
  }
  else
  {
    *len = MAXLEN - 1;
  }

  return line;
}
Beispiel #12
0
static int PhysFSRead( void* user, char* data, int size )
{
    PHYSFS_File* file = (PHYSFS_File*)user;
    return (int)PHYSFS_readBytes(file, data, size);
}