platform/pocketpc.c
changeset 651 cbe4ea4c7e8e
parent 596 381b6ca0dd85
child 657 dad3b5c307a9
equal deleted inserted replaced
650:298b8bb26775 651:cbe4ea4c7e8e
   469 
   469 
   470 
   470 
   471 PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
   471 PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
   472                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
   472                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
   473 {
   473 {
   474     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   474     HANDLE Handle = ((winCEfile *) opaque)->handle;
   475     DWORD CountOfBytesRead;
   475     DWORD CountOfBytesRead;
   476     PHYSFS_sint64 retval;
   476     PHYSFS_sint64 retval;
   477 
   477 
   478     /* Read data from the file */
   478     /* Read data from the file */
   479     /*!!! - uint32 might be a greater # than DWORD */
   479     /*!!! - uint32 might be a greater # than DWORD */
   480     if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
   480     if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL))
   481     {
   481     {
   482     retval=-1;
   482         retval = -1;
   483     } /* if */
   483     } /* if */
   484     else
   484     else
   485     {
   485     {
   486         /* Return the number of "objects" read. */
   486         /* Return the number of "objects" read. */
   487         /* !!! - What if not the right amount of bytes was read to make an object? */
   487         /* !!! - What if not the right amount of bytes was read to make an object? */
   494 
   494 
   495 
   495 
   496 PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
   496 PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
   497                                      PHYSFS_uint32 size, PHYSFS_uint32 count)
   497                                      PHYSFS_uint32 size, PHYSFS_uint32 count)
   498 {
   498 {
   499     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   499     HANDLE Handle = ((winCEfile *) opaque)->handle;
   500     DWORD CountOfBytesWritten;
   500     DWORD CountOfBytesWritten;
   501     PHYSFS_sint64 retval;
   501     PHYSFS_sint64 retval;
   502 
   502 
   503     /* Read data from the file */
   503     /* Read data from the file */
   504     /*!!! - uint32 might be a greater # than DWORD */
   504     /*!!! - uint32 might be a greater # than DWORD */
   505     if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
   505     if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL))
   506     {
   506     {
   507     retval=-1;
   507         retval = -1;
   508     } /* if */
   508     } /* if */
   509     else
   509     else
   510     {
   510     {
   511         /* Return the number of "objects" read. */
   511         /* Return the number of "objects" read. */
   512         /*!!! - What if not the right number of bytes was written? */
   512         /*!!! - What if not the right number of bytes was written? */
   518 } /* __PHYSFS_platformWrite */
   518 } /* __PHYSFS_platformWrite */
   519 
   519 
   520 
   520 
   521 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   521 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   522 {
   522 {
   523     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   523     HANDLE Handle = ((winCEfile *) opaque)->handle;
   524     DWORD HighOrderPos;
   524     DWORD HighOrderPos;
   525     DWORD rc;
   525     DWORD rc;
   526 
   526 
   527     /* Get the high order 32-bits of the position */
   527     /* Get the high order 32-bits of the position */
   528     //HighOrderPos = HIGHORDER_UINT64(pos);
   528     //HighOrderPos = HIGHORDER_UINT64(pos);
   529     HighOrderPos = (unsigned long)(pos>>32);
   529     HighOrderPos = (unsigned long)(pos>>32);
   530 
   530 
   531     /*!!! SetFilePointer needs a signed 64-bit value. */
   531     /*!!! SetFilePointer needs a signed 64-bit value. */
   532     /* Move pointer "pos" count from start of file */
   532     /* Move pointer "pos" count from start of file */
   533     rc = SetFilePointer(FileHandle, (unsigned long)(pos&0x00000000ffffffff),
   533     rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
   534                         &HighOrderPos, FILE_BEGIN);
   534                         &HighOrderPos, FILE_BEGIN);
   535 
   535 
   536     if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   536     if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   537     {
   537     {
   538         BAIL_MACRO(win32strerror(), 0);
   538         BAIL_MACRO(win32strerror(), 0);
   542 } /* __PHYSFS_platformSeek */
   542 } /* __PHYSFS_platformSeek */
   543 
   543 
   544 
   544 
   545 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   545 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   546 {
   546 {
   547     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   547     HANDLE Handle = ((winCEfile *) opaque)->handle;
   548     DWORD HighPos = 0;
   548     DWORD HighPos = 0;
   549     DWORD LowPos;
   549     DWORD LowPos;
   550     PHYSFS_sint64 retval;
   550     PHYSFS_sint64 retval;
   551 
   551 
   552     /* Get current position */
   552     /* Get current position */
   553     LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT);
   553     LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
   554     if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   554     if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   555     {
   555     {
   556         BAIL_MACRO(win32strerror(), 0);
   556         BAIL_MACRO(win32strerror(), 0);
   557     } /* if */
   557     } /* if */
   558     else
   558     else
   566 } /* __PHYSFS_platformTell */
   566 } /* __PHYSFS_platformTell */
   567 
   567 
   568 
   568 
   569 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
   569 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
   570 {
   570 {
   571     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   571     HANDLE Handle = ((winCEfile *) opaque)->handle;
   572     DWORD SizeHigh;
   572     DWORD SizeHigh;
   573     DWORD SizeLow;
   573     DWORD SizeLow;
   574     PHYSFS_sint64 retval;
   574     PHYSFS_sint64 retval;
   575 
   575 
   576     SizeLow = GetFileSize(FileHandle, &SizeHigh);
   576     SizeLow = GetFileSize(Handle, &SizeHigh);
   577     if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   577     if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
   578     {
   578     {
   579         BAIL_MACRO(win32strerror(), -1);
   579         BAIL_MACRO(win32strerror(), -1);
   580     } /* if */
   580     } /* if */
   581     else
   581     else
   615 } /* __PHYSFS_platformFlush */
   615 } /* __PHYSFS_platformFlush */
   616 
   616 
   617 
   617 
   618 int __PHYSFS_platformClose(void *opaque)
   618 int __PHYSFS_platformClose(void *opaque)
   619 {
   619 {
   620     HANDLE FileHandle = ((winCEfile *) opaque)->handle;
   620     HANDLE Handle = ((winCEfile *) opaque)->handle;
   621     BAIL_IF_MACRO(!CloseHandle(FileHandle), win32strerror(), 0);
   621     BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
   622     free(opaque);
   622     free(opaque);
   623     return(1);
   623     return(1);
   624 } /* __PHYSFS_platformClose */
   624 } /* __PHYSFS_platformClose */
   625 
   625 
   626 
   626