src/platform_posix.c
changeset 1228 7c0e9de2ba33
parent 1226 3ea51c799aba
child 1238 97d4522cdf02
equal deleted inserted replaced
1227:b5c017759a1f 1228:7c0e9de2ba33
    20 #include <errno.h>
    20 #include <errno.h>
    21 #include <fcntl.h>
    21 #include <fcntl.h>
    22 
    22 
    23 #if ((!defined PHYSFS_NO_THREAD_SUPPORT) && (!defined PHYSFS_PLATFORM_BEOS))
    23 #if ((!defined PHYSFS_NO_THREAD_SUPPORT) && (!defined PHYSFS_PLATFORM_BEOS))
    24 #include <pthread.h>
    24 #include <pthread.h>
    25 #endif
       
    26 
       
    27 #ifdef PHYSFS_HAVE_LLSEEK
       
    28 #include <linux/unistd.h>
       
    29 #endif
    25 #endif
    30 
    26 
    31 #include "physfs_internal.h"
    27 #include "physfs_internal.h"
    32 
    28 
    33 char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
    29 char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
   284 
   280 
   285 
   281 
   286 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   282 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   287 {
   283 {
   288     const int fd = *((int *) opaque);
   284     const int fd = *((int *) opaque);
   289 
   285     BAIL_IF_MACRO(lseek(fd, (off_t) pos, SEEK_SET) == -1, strerror(errno), 0);
   290     #ifdef PHYSFS_HAVE_LLSEEK
       
   291       unsigned long offset_high = ((pos >> 32) & 0xFFFFFFFF);
       
   292       unsigned long offset_low = (pos & 0xFFFFFFFF);
       
   293       loff_t retoffset;
       
   294       int rc = llseek(fd, offset_high, offset_low, &retoffset, SEEK_SET);
       
   295       BAIL_IF_MACRO(rc == -1, strerror(errno), 0);
       
   296     #else
       
   297       BAIL_IF_MACRO(lseek(fd, (int) pos, SEEK_SET) == -1, strerror(errno), 0);
       
   298     #endif
       
   299 
       
   300     return 1;
   286     return 1;
   301 } /* __PHYSFS_platformSeek */
   287 } /* __PHYSFS_platformSeek */
   302 
   288 
   303 
   289 
   304 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   290 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   305 {
   291 {
   306     const int fd = *((int *) opaque);
   292     const int fd = *((int *) opaque);
   307     PHYSFS_sint64 retval;
   293     PHYSFS_sint64 retval;
   308 
   294     retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR);
   309     #ifdef PHYSFS_HAVE_LLSEEK
   295     BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
   310       loff_t retoffset;
       
   311       int rc = llseek(fd, 0, &retoffset, SEEK_CUR);
       
   312       BAIL_IF_MACRO(rc == -1, strerror(errno), -1);
       
   313       retval = (PHYSFS_sint64) retoffset;
       
   314     #else
       
   315       retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR);
       
   316       BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
       
   317     #endif
       
   318 
       
   319     return retval;
   296     return retval;
   320 } /* __PHYSFS_platformTell */
   297 } /* __PHYSFS_platformTell */
   321 
   298 
   322 
   299 
   323 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
   300 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)