Hi

Some fast code: compiled, but not tested...

#define memNewChunkFlagNonMovable    0x0200
#define memNewChunkFlagAllowLarge    0x1000  // this is not in the sdk

SysAppInfoPtr
  SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP)
SYS_TRAP(sysTrapSysGetAppInfo);

// You can use another alloc method instead
void *MemPtrNew_large( Int32 size)
{
  if( size > 65500 ) // the max MemPtrNew will give
  {
    SysAppInfoPtr appInfoP;
    UInt16        ownerID = ((SysAppInfoPtr) SysGetAppInfo(&appInfoP,
&appInfoP))->memOwnerID;
    return MemChunkNew(0, size, ownerID | memNewChunkFlagNonMovable |
memNewChunkFlagAllowLarge);
  }
  else
    return MemPtrNew(size);
}

char *ReadSomeFile( UInt16 volNum, const Char *fullPath, int *error, UInt32
*fSize )
{
 FileRef hFile ;
 char    *buffer = NULL ;

 // Open source file
 *error = VFSFileOpen( volNum, fullPath, vfsModeRead, &hFile ) ;
 if( *error != 0 )
  return NULL ;

 // Get file length
 *error = VFSFileSize( hFile, fSize ) ;
 if( *error == 0  &&  *fSize == 0 )
  *error = -1 ;  // empty file, define some error code here

 if( *error == 0 )
 {
  UInt32 nRead=0 ;
  UInt32 toRead=*fSize ;
  buffer = MemPtrNew_large( *fSize ) ;
  if( buffer == NULL )
   *error = memErrNotEnoughSpace ;

  while( *error==0 && toRead>0 )
  {
   UInt32 nBytesRead ;
   *error = VFSFileRead( hFile, toRead, buffer+nRead, &nBytesRead) ;
   nRead += nBytesRead ;
   toRead -= nBytesRead ;
  }
 }

 VFSFileClose( hFile ) ;
 if( *error != 0  &&  buffer != NULL )
  MemPtrFree( buffer ) ;
 return buffer ;
}

Regards,

    Jan Slodicka

----- Original Message -----
From: "Anders Rahm-Nilzon" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, January 05, 2004 11:09 PM
Subject: Re: VFSFileRead


> Hi Jan,
>
> I think that I have tested that but I get NULL as the return value from
> VFSFileRead ?
> Can you show me how you should do that loop ???
> Please help me!
> So many thanks !!!
>  \Anders R-N
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to