paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/physfs physfs_byteorder.c,NONE,1.1 Makefi


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/physfs physfs_byteorder.c,NONE,1.1 Makefile.am,1.1.1.1,1.2 physfs.c,1.1.1.1,1.2 physfs.h,1.1.1.1,1.2 physfs_internal.h,1.1.1.1,1.2
Date: Sat, 27 Apr 2002 12:06:29 -0400

Update of /cvsroot/paragui/paragui/src/physfs
In directory subversions:/tmp/cvs-serv12415/src/physfs

Modified Files:
        Makefile.am physfs.c physfs.h physfs_internal.h 
Added Files:
        physfs_byteorder.c 
Log Message:
updated physfs to version 0.1.5



--- NEW FILE ---
/**
 * PhysicsFS; a portable, flexible file i/o abstraction.
 *
 * Documentation is in physfs.h. It's verbose, honest.  :)
 *
 * Please see the file LICENSE in the source's root directory.
 *
 *  This file written by Ryan C. Gordon.
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "physfs.h"

/* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */
#define PHYSFS_LIL_ENDIAN  1234
#define PHYSFS_BIG_ENDIAN  4321

#if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
    (defined(__alpha__) || defined(__alpha)) || \
     defined(__arm__) || \
    (defined(__mips__) && defined(__MIPSEL__)) || \
     defined(__SYMBIAN32__) || \
     defined(__LITTLE_ENDIAN__)
#define PHYSFS_BYTEORDER    PHYSFS_LIL_ENDIAN
#else
#define PHYSFS_BYTEORDER    PHYSFS_BIG_ENDIAN
#endif


/* The macros used to swap values */
/* Try to use superfast macros on systems that support them */
#ifdef linux
#include <asm/byteorder.h>
#ifdef __arch__swab16
#define PHYSFS_Swap16  __arch__swab16
#endif
#ifdef __arch__swab32
#define PHYSFS_Swap32  __arch__swab32
#endif
#endif /* linux */

#if (defined _MSC_VER)
#define inline __inline
#endif

#ifndef PHYSFS_Swap16
static inline PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D)
{
        return((D<<8)|(D>>8));
}
#endif
#ifndef PHYSFS_Swap32
static inline PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D)
{
        return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
}
#endif
#ifndef PHYSFS_NO_64BIT_SUPPORT
#ifndef PHYSFS_Swap64
static inline PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) {
        PHYSFS_uint32 hi, lo;

        /* Separate into high and low 32-bit values and swap them */
        lo = (PHYSFS_uint32)(val&0xFFFFFFFF);
        val >>= 32;
        hi = (PHYSFS_uint32)(val&0xFFFFFFFF);
        val = PHYSFS_Swap32(lo);
        val <<= 32;
        val |= PHYSFS_Swap32(hi);
        return(val);
}
#endif
#else
#ifndef PHYSFS_Swap64
/* This is mainly to keep compilers from complaining in PHYSFS code.
   If there is no real 64-bit datatype, then compilers will complain about
   the fake 64-bit datatype that PHYSFS provides when it compiles user code.
*/
#define PHYSFS_Swap64(X)        (X)
#endif
#endif /* PHYSFS_NO_64BIT_SUPPORT */


/* Byteswap item from the specified endianness to the native endianness */
#if PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return(x); }
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return(x); }
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return(x); }
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return(x); }
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return(x); }
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return(x); }

PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return(PHYSFS_Swap16(x)); }
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return(PHYSFS_Swap16(x)); }
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return(PHYSFS_Swap32(x)); }
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return(PHYSFS_Swap32(x)); }
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(PHYSFS_Swap64(x)); }
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(PHYSFS_Swap64(x)); }
#else
PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 x) { return(PHYSFS_Swap16(x)); }
PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 x) { return(PHYSFS_Swap16(x)); }
PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 x) { return(PHYSFS_Swap32(x)); }
PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 x) { return(PHYSFS_Swap32(x)); }
PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 x) { return(PHYSFS_Swap64(x)); }
PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 x) { return(PHYSFS_Swap64(x)); }

PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 x) { return(x); }
PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 x) { return(x); }
PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 x) { return(x); }
PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 x) { return(x); }
PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(x); }
PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(x); }
#endif

/* end of physfs_byteorder.c ... */


Index: Makefile.am
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/Makefile.am,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Makefile.am 15 Apr 2002 13:22:14 -0000      1.1.1.1
--- Makefile.am 27 Apr 2002 16:06:25 -0000      1.2
***************
*** 8,11 ****
--- 8,12 ----
  libphysfs_la_SOURCES = \
        physfs.c \
+       physfs_byteorder.c \
        platform.c
  

Index: physfs.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/physfs.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** physfs.c    15 Apr 2002 13:22:13 -0000      1.1.1.1
--- physfs.c    27 Apr 2002 16:06:25 -0000      1.2
***************
*** 22,26 ****
  typedef struct __PHYSFS_ERRMSGTYPE__
  {
!     int tid;
      int errorAvailable;
      char errorString[80];
--- 22,26 ----
  typedef struct __PHYSFS_ERRMSGTYPE__
  {
!     PHYSFS_uint64 tid;
      int errorAvailable;
[...1151 lines suppressed...]
      FileHandle *h = (FileHandle *) handle->opaque;
--- 1387,1391 ----
  
  
! int PHYSFS_seek(PHYSFS_file *handle, PHYSFS_uint64 pos)
  {
      FileHandle *h = (FileHandle *) handle->opaque;
***************
*** 1283,1287 ****
  
  
! int PHYSFS_fileLength(PHYSFS_file *handle)
  {
      FileHandle *h = (FileHandle *) handle->opaque;
--- 1398,1402 ----
  
  
! PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_file *handle)
  {
      FileHandle *h = (FileHandle *) handle->opaque;

Index: physfs.h
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/physfs.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** physfs.h    15 Apr 2002 13:22:14 -0000      1.1.1.1
--- physfs.h    27 Apr 2002 16:06:25 -0000      1.2
***************
*** 103,124 ****
   *  are and how they can help you determine an optimal search path.
   *
!  * PhysicsFS is (sort of) NOT thread safe! The error messages returned by
!  *  PHYSFS_getLastError are unique by thread, but that's it. Generally
!  *  speaking, we'd have to request a mutex at the start of each function,
!  *  and release it before returning. Not only is this REALLY slow, it requires
!  *  a thread lock portability layer to be written. All that work is only
!  *  necessary as a safety if the calling application is poorly written.
!  *  Generally speaking, it is safe to call most functions that don't set state
!  *  simultaneously; you can read and write and open and close different files
!  *  at the same time in different threads, but trying to set the write path in
!  *  one thread while opening a file for writing in another will, at best,
!  *  cause a polite error, but depending on the race condition results, you may
!  *  get a segfault and crash, too. Use your head, and implement you own thread
!  *  locks where needed. Also, consider if you REALLY need a multithreaded
!  *  solution in the first place.
   *
   * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
   *  calls, doing so is not recommended, and you can not use system
!  *  filehandles with PhysicsFS filehandles and vice versa.
   *
   * Note that archives need not be named as such: if you have a ZIP file and
--- 103,116 ----
   *  are and how they can help you determine an optimal search path.
   *
!  * PhysicsFS is mostly thread safe. The error messages returned by
!  *  PHYSFS_getLastError are unique by thread, and library-state-setting
!  *  functions are mutex'd. For efficiency, individual file accesses are 
!  *  not locked, so you can not safely read/write/seek/close/etc the same 
!  *  file from two threads at the same time. Other race conditions are bugs 
!  *  that should be reported/patched.
   *
   * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
   *  calls, doing so is not recommended, and you can not use system
!  *  filehandles with PhysicsFS and vice versa.
   *
   * Note that archives need not be named as such: if you have a ZIP file and
***************
*** 148,151 ****
--- 140,180 ----
  #endif
  
+ typedef unsigned char         PHYSFS_uint8;
+ typedef signed char           PHYSFS_sint8;
+ typedef unsigned short        PHYSFS_uint16;
+ typedef signed short          PHYSFS_sint16;
+ typedef unsigned int          PHYSFS_uint32;
+ typedef signed int            PHYSFS_sint32;
+ 
+ #if (defined PHYSFS_NO_64BIT_SUPPORT)  /* oh well. */
+ typedef PHYSFS_uint32         PHYSFS_uint64;
+ typedef PHYSFS_sint32         PHYSFS_sint64;
+ #elif (defined _MSC_VER)
+ typedef signed __int64        PHYSFS_sint64;
+ typedef unsigned __int64      PHYSFS_uint64;
+ #else
+ typedef unsigned long long    PHYSFS_uint64;
+ typedef signed long long      PHYSFS_sint64;
+ #endif
+ 
+ /* Make sure the types really have the right sizes */
+ #define PHYSFS_COMPILE_TIME_ASSERT(name, x)               \
+        typedef int PHYSFS_dummy_ ## name[(x) * 2 - 1]
+ 
+ PHYSFS_COMPILE_TIME_ASSERT(uint8, sizeof(PHYSFS_uint8) == 1);
+ PHYSFS_COMPILE_TIME_ASSERT(sint8, sizeof(PHYSFS_sint8) == 1);
+ PHYSFS_COMPILE_TIME_ASSERT(uint16, sizeof(PHYSFS_uint16) == 2);
+ PHYSFS_COMPILE_TIME_ASSERT(sint16, sizeof(PHYSFS_sint16) == 2);
+ PHYSFS_COMPILE_TIME_ASSERT(uint32, sizeof(PHYSFS_uint32) == 4);
+ PHYSFS_COMPILE_TIME_ASSERT(sint32, sizeof(PHYSFS_sint32) == 4);
+ 
+ #ifndef PHYSFS_NO_64BIT_SUPPORT
+ PHYSFS_COMPILE_TIME_ASSERT(uint64, sizeof(PHYSFS_uint64) == 8);
+ PHYSFS_COMPILE_TIME_ASSERT(sint64, sizeof(PHYSFS_sint64) == 8);
+ #endif
+ 
+ #undef PHYSFS_COMPILE_TIME_ASSERT
+ 
+ 
  
  typedef struct __PHYSFS_FILE__
***************
*** 167,178 ****
  typedef struct __PHYSFS_VERSION__
  {
!     int major;
!     int minor;
!     int patch;
  } PHYSFS_Version;
  
  #define PHYSFS_VER_MAJOR 0
  #define PHYSFS_VER_MINOR 1
! #define PHYSFS_VER_PATCH 4
  
  #define PHYSFS_VERSION(x) { \
--- 196,207 ----
  typedef struct __PHYSFS_VERSION__
  {
!     PHYSFS_uint8 major;
!     PHYSFS_uint8 minor;
!     PHYSFS_uint8 patch;
  } PHYSFS_Version;
  
  #define PHYSFS_VER_MAJOR 0
  #define PHYSFS_VER_MINOR 1
! #define PHYSFS_VER_PATCH 5
  
  #define PHYSFS_VERSION(x) { \
***************
*** 273,277 ****
   *   @param list List of information specified as freeable by this function.
   */
! __EXPORT__ void PHYSFS_freeList(void *list);
  
  
--- 302,306 ----
   *   @param list List of information specified as freeable by this function.
   */
! __EXPORT__ void PHYSFS_freeList(void *listVar);
  
  
***************
*** 561,564 ****
--- 590,596 ----
   * A directory must be empty before this call can delete it.
   *
+  * Deleting a symlink will remove the link, not what it points to, regardless
+  *  of whether you "permitSymLinks" or not.
+  *
   * So if you've got the write dir set to "C:\mygame\writedir" and call
   *  PHYSFS_delete("downloads/maps/level1.map") then the file
***************
*** 571,574 ****
--- 603,610 ----
   *  filehandle to it (including your program) close their handles.
   *
+  * Chances are, the bits that make up the file still exist, they are just
+  *  made available to be written over at a later point. Don't consider this
+  *  a security method or anything.  :)
+  *
   *   @param filename Filename to delete.
   *  @return nonzero on success, zero on error. Specifics of the error can be
***************
*** 759,765 ****
   *            -1 if complete failure.
   */
! __EXPORT__ int PHYSFS_read(PHYSFS_file *handle, void *buffer,
!                            unsigned int objSize, unsigned int objCount);
! 
  
  /**
--- 795,802 ----
   *            -1 if complete failure.
   */
! __EXPORT__ PHYSFS_sint64 PHYSFS_read(PHYSFS_file *handle,
!                                      void *buffer,
!                                      PHYSFS_uint32 objSize,
!                                      PHYSFS_uint32 objCount);
  
  /**
***************
*** 773,779 ****
   *           the reason this might be < (objCount). -1 if complete failure.
   */
! __EXPORT__ int PHYSFS_write(PHYSFS_file *handle, void *buffer,
!                             unsigned int objSize, unsigned int objCount);
! 
  
  /**
--- 810,817 ----
   *           the reason this might be < (objCount). -1 if complete failure.
   */
! __EXPORT__ PHYSFS_sint64 PHYSFS_write(PHYSFS_file *handle,
!                                       const void *buffer,
!                                       PHYSFS_uint32 objSize,
!                                       PHYSFS_uint32 objCount);
  
  /**
***************
*** 793,797 ****
   *           Specifics of the error can be gleaned from PHYSFS_getLastError().
   */
! __EXPORT__ int PHYSFS_tell(PHYSFS_file *handle);
  
  
--- 831,835 ----
   *           Specifics of the error can be gleaned from PHYSFS_getLastError().
   */
! __EXPORT__ PHYSFS_sint64 PHYSFS_tell(PHYSFS_file *handle);
  
  
***************
*** 806,810 ****
   *          gleaned from PHYSFS_getLastError().
   */
! __EXPORT__ int PHYSFS_seek(PHYSFS_file *handle, int pos);
  
  
--- 844,848 ----
   *          gleaned from PHYSFS_getLastError().
   */
! __EXPORT__ int PHYSFS_seek(PHYSFS_file *handle, PHYSFS_uint64 pos);
  
  
***************
*** 812,816 ****
   * Get total length of a file in bytes. Note that if the file size can't
   *  be determined (since the archive is "streamed" or whatnot) than this
!  *  with report (-1). Also note that if another process/thread is writing
   *  to this file at the same time, then the information this function
   *  supplies could be incorrect before you get it. Use with caution, or
--- 850,854 ----
   * Get total length of a file in bytes. Note that if the file size can't
   *  be determined (since the archive is "streamed" or whatnot) than this
!  *  will report (-1). Also note that if another process/thread is writing
   *  to this file at the same time, then the information this function
   *  supplies could be incorrect before you get it. Use with caution, or
***************
*** 820,824 ****
   *  @return size in bytes of the file. -1 if can't be determined.
   */
! __EXPORT__ int PHYSFS_fileLength(PHYSFS_file *handle);
  
  #ifdef __cplusplus
--- 858,987 ----
   *  @return size in bytes of the file. -1 if can't be determined.
   */
! __EXPORT__ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_file *handle);
! 
! 
! /* Byteorder stuff... */
! 
! /**
!  * Take a 16-bit signed value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint16 PHYSFS_swapSLE16(PHYSFS_sint16 val);
! 
! 
! /**
!  * Take a 16-bit unsigned value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint16 PHYSFS_swapULE16(PHYSFS_uint16 val);
! 
! /**
!  * Take a 32-bit signed value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint32 PHYSFS_swapSLE32(PHYSFS_sint32 val);
! 
! 
! /**
!  * Take a 32-bit unsigned value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint32 PHYSFS_swapULE32(PHYSFS_uint32 val);
! 
! /**
!  * Take a 64-bit signed value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint64 PHYSFS_swapSLE64(PHYSFS_sint64 val);
! 
! 
! /**
!  * Take a 64-bit unsigned value in littleendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint64 PHYSFS_swapULE64(PHYSFS_uint64 val);
! 
! 
! /**
!  * Take a 16-bit signed value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint16 PHYSFS_swapSBE16(PHYSFS_sint16 val);
! 
! 
! /**
!  * Take a 16-bit unsigned value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint16 PHYSFS_swapUBE16(PHYSFS_uint16 val);
! 
! /**
!  * Take a 32-bit signed value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint32 PHYSFS_swapSBE32(PHYSFS_sint32 val);
! 
! 
! /**
!  * Take a 32-bit unsigned value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint32 PHYSFS_swapUBE32(PHYSFS_uint32 val);
! 
! 
! /**
!  * Take a 64-bit signed value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
! 
! 
! /**
!  * Take a 64-bit unsigned value in bigendian format and convert it to
!  *  the platform's native byte order.
!  *
!  *    @param val value to convert
!  *   @return converted value.
!  */
! __EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);
! 
! 
! 
! #if 0 /* !!! FIXME: add this? */
! #undef __EXPORT__
! #endif
  
  #ifdef __cplusplus

Index: physfs_internal.h
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/physfs_internal.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** physfs_internal.h   15 Apr 2002 13:22:14 -0000      1.1.1.1
--- physfs_internal.h   27 Apr 2002 16:06:26 -0000      1.2
***************
*** 15,18 ****
--- 15,24 ----
  #endif
  
+ #include "physfs.h"
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
  struct __PHYSFS_DIRHANDLE__;
  struct __PHYSFS_FILEFUNCTIONS__;
***************
*** 53,58 ****
           * On failure, call __PHYSFS_setError().
           */
!     int (*read)(FileHandle *handle, void *buffer,
!                 unsigned int objSize, unsigned int objCount);
  
          /*
--- 59,64 ----
           * On failure, call __PHYSFS_setError().
           */
!     PHYSFS_sint64 (*read)(FileHandle *handle, void *buffer,
!                           PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  
          /*
***************
*** 63,68 ****
           * On failure, call __PHYSFS_setError().
           */
!     int (*write)(FileHandle *handle, void *buffer,
!                  unsigned int objSize, unsigned int objCount);
  
          /*
--- 69,74 ----
           * On failure, call __PHYSFS_setError().
           */
!     PHYSFS_sint64 (*write)(FileHandle *handle, const void *buffer,
!                  PHYSFS_uint32 objSize, PHYSFS_uint32 objCount);
  
          /*
***************
*** 74,78 ****
           * Returns byte offset from start of file.
           */
!     int (*tell)(FileHandle *handle);
  
          /*
--- 80,84 ----
           * Returns byte offset from start of file.
           */
!     PHYSFS_sint64 (*tell)(FileHandle *handle);
  
          /*
***************
*** 81,85 ****
           * On failure, call __PHYSFS_setError().
           */
!     int (*seek)(FileHandle *handle, int offset);
  
          /*
--- 87,91 ----
           * On failure, call __PHYSFS_setError().
           */
!     int (*seek)(FileHandle *handle, PHYSFS_uint64 offset);
  
          /*
***************
*** 88,92 ****
           * On failure, call __PHYSFS_setError().
           */
!     int (*fileLength)(FileHandle *handle);
  
          /*
--- 94,98 ----
           * On failure, call __PHYSFS_setError().
           */
!     PHYSFS_sint64 (*fileLength)(FileHandle *handle);
  
          /*
***************
*** 256,259 ****
--- 262,270 ----
  #define ERR_TOO_MANY_SYMLINKS    "Too many symbolic links"
  #define ERR_COMPRESSION          "(De)compression error"
+ #define ERR_NOT_IMPLEMENTED      "Not implemented"
+ #define ERR_OS_ERROR             "Operating system reported error"
+ #define ERR_FILE_EXISTS          "File already exists"
+ #define ERR_NOT_A_DIR            "Not a directory"
+ #define ERR_FILE_NOT_FOUND       "File not found"
  
  /*
***************
*** 299,302 ****
--- 310,315 ----
  #define BAIL_MACRO(e, r) { __PHYSFS_setError(e); return r; }
  #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return r; }
+ #define BAIL_MACRO_MUTEX(e, m, r) { __PHYSFS_setError(e); 
__PHYSFS_platformReleaseMutex(m); return r; }
+ #define BAIL_IF_MACRO_MUTEX(c, e, m, r) if (c) { __PHYSFS_setError(e); 
__PHYSFS_platformReleaseMutex(m); return r; }
  
  
***************
*** 320,323 ****
--- 333,499 ----
  extern const char *__PHYSFS_platformDirSeparator;
  
+ 
+ /*
+  * Initialize the platform. This is called when PHYSFS_init() is called from
+  *  the application. You can use this to (for example) determine what version
+  *  of Windows you're running.
+  *
+  * Return zero if there was a catastrophic failure (which prevents you from
+  *  functioning at all), and non-zero otherwise.
+  */
+ int __PHYSFS_platformInit(void);
+ 
+ /*
+  * Deinitialize the platform. This is called when PHYSFS_deinit() is called
+  *  from the application. You can use this to clean up anything you've
+  *  allocated in your platform driver.
+  *
+  * Return zero if there was a catastrophic failure (which prevents you from
+  *  functioning at all), and non-zero otherwise.
+  */
+ int __PHYSFS_platformDeinit(void);
+ 
+ /*
+  * Open a file for reading. (filename) is in platform-dependent notation. The
+  *  file pointer should be positioned on the first byte of the file.
+  *
+  * The return value will be some platform-specific datatype that is opaque to
+  *  the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under 
win32.
+  *
+  * The same file can be opened for read multiple times, and each should have
+  *  a unique file handle; this is frequently employed to prevent race
+  *  conditions in the archivers.
+  *
+  * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
+  */
+ void *__PHYSFS_platformOpenRead(const char *filename);
+ 
+ /*
+  * Open a file for writing. (filename) is in platform-dependent notation. If
+  *  the file exists, it should be truncated to zero bytes, and if it doesn't
+  *  exist, it should be created as a zero-byte file. The file pointer should
+  *  be positioned on the first byte of the file.
+  *
+  * The return value will be some platform-specific datatype that is opaque to
+  *  the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under 
win32,
+  *  etc.
+  *
+  * Opening a file for write multiple times has undefined results.
+  *
+  * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
+  */
+ void *__PHYSFS_platformOpenWrite(const char *filename);
+ 
+ /*
+  * Open a file for appending. (filename) is in platform-dependent notation. If
+  *  the file exists, the file pointer should be place just past the end of the
+  *  file, so that the first write will be one byte after the current end of
+  *  the file. If the file doesn't exist, it should be created as a zero-byte
+  *  file. The file pointer should be positioned on the first byte of the file.
+  *
+  * The return value will be some platform-specific datatype that is opaque to
+  *  the caller; it could be a (FILE *) under Unix, or a (HANDLE *) under 
win32,
+  *  etc.
+  *
+  * Opening a file for append multiple times has undefined results.
+  *
+  * Call __PHYSFS_setError() and return (NULL) if the file can't be opened.
+  */
+ void *__PHYSFS_platformOpenAppend(const char *filename);
+ 
+ /*
+  * Read more data from a platform-specific file handle. (opaque) should be
+  *  cast to whatever data type your platform uses. Read a maximum of (count)
+  *  objects of (size) 8-bit bytes to the area pointed to by (buffer). If there
+  *  isn't enough data available, return the number of full objects read, and
+  *  position the file pointer at the start of the first incomplete object.
+  *  On success, return (count) and position the file pointer one byte past
+  *  the end of the last read object. Return (-1) if there is a catastrophic
+  *  error, and call __PHYSFS_setError() to describe the problem; the file
+  *  pointer should not move in such a case.
+  */
+ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
+                                     PHYSFS_uint32 size, PHYSFS_uint32 count);
+ 
+ /*
+  * Write more data to a platform-specific file handle. (opaque) should be
+  *  cast to whatever data type your platform uses. Write a maximum of (count)
+  *  objects of (size) 8-bit bytes from the area pointed to by (buffer). If
+  *  there isn't enough data available, return the number of full objects
+  *  written, and position the file pointer at the start of the first
+  *  incomplete object. Return (-1) if there is a catastrophic error, and call
+  *  __PHYSFS_setError() to describe the problem; the file pointer should not
+  *  move in such a case.
+  */
+ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
+                                      PHYSFS_uint32 size, PHYSFS_uint32 count);
+ 
+ /*
+  * Set the file pointer to a new position. (opaque) should be cast to
+  *  whatever data type your platform uses. (pos) specifies the number
+  *  of 8-bit bytes to seek to from the start of the file. Seeking past the
+  *  end of the file is an error condition, and you should check for it.
+  *
+  * Not all file types can seek; this is to be expected by the caller.
+  *
+  * On error, call __PHYSFS_setError() and return zero. On success, return
+  *  a non-zero value.
+  */
+ int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
+ 
+ /*
+  * Get the file pointer's position, in an 8-bit byte offset from the start of
+  *  the file. (opaque) should be cast to whatever data type your platform
+  *  uses.
+  *
+  * Not all file types can "tell"; this is to be expected by the caller.
+  *
+  * On error, call __PHYSFS_setError() and return zero. On success, return
+  *  a non-zero value.
+  */
+ PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);
+ 
+ /*
+  * Determine the current size of a file, in 8-bit bytes, from an open file.
+  *
+  * The caller expects that this information may not be available for all
+  *  file types on all platforms.
+  *
+  * Return -1 if you can't do it, and call __PHYSFS_setError(). Otherwise,
+  *  return the file length in 8-bit bytes.
+  */
+ PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
+ 
+ /*
+  * Determine if a file is at EOF. (opaque) should be cast to whatever data
+  *  type your platform uses.
+  *
+  * The caller expects that there was a short read before calling this.
+  *
+  * Return non-zero if EOF, zero if it is _not_ EOF.
+  */
+ int __PHYSFS_platformEOF(void *opaque);
+ 
+ /*
+  * Flush any pending writes to disk. (opaque) should be cast to whatever data
+  *  type your platform uses. Be sure to check for errors; the caller expects
+  *  that this function can fail if there was a flushing error, etc.
+  *
+  *  Return zero on failure, non-zero on success.
+  */
+ int __PHYSFS_platformFlush(void *opaque);
+ 
+ /*
+  * Flush and close a file. (opaque) should be cast to whatever data type
+  *  your platform uses. Be sure to check for errors when closing; the
+  *  caller expects that this function can fail if there was a flushing
+  *  error, etc.
+  *
+  * You should clean up all resources associated with (opaque).
+  *
+  *  Return zero on failure, non-zero on success.
+  */
+ int __PHYSFS_platformClose(void *opaque);
+ 
  /*
   * Platform implementation of PHYSFS_getCdRomDirs()...
***************
*** 354,358 ****
   *  number.
   */
! int __PHYSFS_platformGetThreadID(void);
  
  /*
--- 530,534 ----
   *  number.
   */
! PHYSFS_uint64 __PHYSFS_platformGetThreadID(void);
  
  /*
***************
*** 393,397 ****
   *
   * Platforms that choose not to implement this may just call
!  *  __PHYSFS_convertToDependent() as a passthrough.
   *
   * Be sure to free() the return value when done with it.
--- 569,574 ----
   *
   * Platforms that choose not to implement this may just call
!  *  __PHYSFS_convertToDependent() as a passthrough, which may fit the bill
!  *  already.
   *
   * Be sure to free() the return value when done with it.
***************
*** 421,431 ****
  
  /*
-  * Determine the current size of a file, in bytes, from a stdio FILE *.
-  *  Return -1 if you can't do it, and call __PHYSFS_setError().
-  */
- int __PHYSFS_platformFileLength(FILE *handle);
- 
- 
- /*
   * Get the current working directory. The return value should be an
   *  absolute path in platform-dependent notation. The caller will deallocate
--- 598,601 ----
***************
*** 457,463 ****
  int __PHYSFS_platformMkDir(const char *path);
  
  
  #ifdef __cplusplus
! extern "C" {
  #endif
  
--- 627,692 ----
  int __PHYSFS_platformMkDir(const char *path);
  
+ /*
+  * Remove a file or directory entry in the actual filesystem. (path) is
+  *  specified in platform-dependent notation. Note that this deletes files
+  *  _and_ directories, so you might need to do some determination.
+  *  Non-empty directories should report an error and not delete themselves
+  *  or their contents.
+  *
+  * Deleting a symlink should remove the link, not what it points to.
+  *
+  * On error, return zero and set the error message. Return non-zero on 
success.
+  */
+ int __PHYSFS_platformDelete(const char *path);
+ 
+ 
+ /*
+  * Create a platform-specific mutex. This can be whatever datatype your
+  *  platform uses for mutexes, but it is cast to a (void *) for abstractness.
+  *
+  * Return (NULL) if you couldn't create one. Systems without threads can
+  *  return any arbitrary non-NULL value.
+  */
+ void *__PHYSFS_platformCreateMutex(void);
+ 
+ /*
+  * Destroy a platform-specific mutex, and clean up any resources associated
+  *  with it. (mutex) is a value previously returned by
+  *  __PHYSFS_platformCreateMutex(). This can be a no-op on single-threaded
+  *  platforms.
+  */
+ void __PHYSFS_platformDestroyMutex(void *mutex);
+ 
+ /*
+  * Grab possession of a platform-specific mutex. Mutexes should be recursive;
+  *  that is, the same thread should be able to call this function multiple
+  *  times in a row without causing a deadlock. This function should block 
+  *  until a thread can gain possession of the mutex.
+  *
+  * Return non-zero if the mutex was grabbed, zero if there was an 
+  *  unrecoverable problem grabbing it (this should not be a matter of 
+  *  timing out! We're talking major system errors; block until the mutex 
+  *  is available otherwise.)
+  *
+  * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
+  *  function, you'll cause an infinite recursion. This means you can't
+  *  use the BAIL_*MACRO* macros, either.
+  */
+ int __PHYSFS_platformGrabMutex(void *mutex);
+ 
+ /*
+  * Relinquish possession of the mutex when this method has been called 
+  *  once for each time that platformGrabMutex was called. Once possession has
+  *  been released, the next thread in line to grab the mutex (if any) may
+  *  proceed.
+  *
+  * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
+  *  function, you'll cause an infinite recursion. This means you can't
+  *  use the BAIL_*MACRO* macros, either.
+  */
+ void __PHYSFS_platformReleaseMutex(void *mutex);
  
  #ifdef __cplusplus
! }
  #endif
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]