src/platform_posix.c
changeset 1117 968e1567f4f4
parent 1115 bc7257f4f8da
child 1118 2e09fc635fdd
equal deleted inserted replaced
1116:20dfca1e8a27 1117:968e1567f4f4
   300 
   300 
   301 
   301 
   302 PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
   302 PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
   303                                     PHYSFS_uint64 len)
   303                                     PHYSFS_uint64 len)
   304 {
   304 {
   305     int fd = *((int *) opaque);
   305     const int fd = *((int *) opaque);
   306     ssize_t rc = 0;
   306     ssize_t rc = 0;
   307 
   307 
   308     BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
   308     BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
   309 
   309 
   310     rc = read(fd, buffer, (size_t) len);
   310     rc = read(fd, buffer, (size_t) len);
   316 
   316 
   317 
   317 
   318 PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
   318 PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
   319                                      PHYSFS_uint64 len)
   319                                      PHYSFS_uint64 len)
   320 {
   320 {
   321     int fd = *((int *) opaque);
   321     const int fd = *((int *) opaque);
   322     ssize_t rc = 0;
   322     ssize_t rc = 0;
   323 
   323 
   324     BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
   324     BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
   325 
   325 
   326     rc = write(fd, (void *) buffer, (size_t) len);
   326     rc = write(fd, (void *) buffer, (size_t) len);
   331 } /* __PHYSFS_platformWrite */
   331 } /* __PHYSFS_platformWrite */
   332 
   332 
   333 
   333 
   334 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   334 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
   335 {
   335 {
   336     int fd = *((int *) opaque);
   336     const int fd = *((int *) opaque);
   337 
   337 
   338     #ifdef PHYSFS_HAVE_LLSEEK
   338     #ifdef PHYSFS_HAVE_LLSEEK
   339       unsigned long offset_high = ((pos >> 32) & 0xFFFFFFFF);
   339       unsigned long offset_high = ((pos >> 32) & 0xFFFFFFFF);
   340       unsigned long offset_low = (pos & 0xFFFFFFFF);
   340       unsigned long offset_low = (pos & 0xFFFFFFFF);
   341       loff_t retoffset;
   341       loff_t retoffset;
   349 } /* __PHYSFS_platformSeek */
   349 } /* __PHYSFS_platformSeek */
   350 
   350 
   351 
   351 
   352 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   352 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
   353 {
   353 {
   354     int fd = *((int *) opaque);
   354     const int fd = *((int *) opaque);
   355     PHYSFS_sint64 retval;
   355     PHYSFS_sint64 retval;
   356 
   356 
   357     #ifdef PHYSFS_HAVE_LLSEEK
   357     #ifdef PHYSFS_HAVE_LLSEEK
   358       loff_t retoffset;
   358       loff_t retoffset;
   359       int rc = llseek(fd, 0, &retoffset, SEEK_CUR);
   359       int rc = llseek(fd, 0, &retoffset, SEEK_CUR);
   368 } /* __PHYSFS_platformTell */
   368 } /* __PHYSFS_platformTell */
   369 
   369 
   370 
   370 
   371 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
   371 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
   372 {
   372 {
   373     int fd = *((int *) opaque);
   373     const int fd = *((int *) opaque);
   374     struct stat statbuf;
   374     struct stat statbuf;
   375     BAIL_IF_MACRO(fstat(fd, &statbuf) == -1, strerror(errno), -1);
   375     BAIL_IF_MACRO(fstat(fd, &statbuf) == -1, strerror(errno), -1);
   376     return ((PHYSFS_sint64) statbuf.st_size);
   376     return ((PHYSFS_sint64) statbuf.st_size);
   377 } /* __PHYSFS_platformFileLength */
   377 } /* __PHYSFS_platformFileLength */
   378 
   378 
   379 
   379 
   380 int __PHYSFS_platformEOF(void *opaque)
   380 int __PHYSFS_platformEOF(void *opaque)
   381 {
   381 {
   382     PHYSFS_sint64 pos = __PHYSFS_platformTell(opaque);
   382     const PHYSFS_sint64 pos = __PHYSFS_platformTell(opaque);
   383     PHYSFS_sint64 len = __PHYSFS_platformFileLength(opaque);
   383     const PHYSFS_sint64 len = __PHYSFS_platformFileLength(opaque);
   384     return (pos >= len);
   384     return (pos >= len);
   385 } /* __PHYSFS_platformEOF */
   385 } /* __PHYSFS_platformEOF */
   386 
   386 
   387 
   387 
   388 int __PHYSFS_platformFlush(void *opaque)
   388 int __PHYSFS_platformFlush(void *opaque)
   389 {
   389 {
   390     int fd = *((int *) opaque);
   390     const int fd = *((int *) opaque);
   391     BAIL_IF_MACRO(fsync(fd) == -1, strerror(errno), 0);
   391     BAIL_IF_MACRO(fsync(fd) == -1, strerror(errno), 0);
   392     return 1;
   392     return 1;
   393 } /* __PHYSFS_platformFlush */
   393 } /* __PHYSFS_platformFlush */
   394 
   394 
   395 
   395