mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
FS-4657 --resolve update libsndfile to its latest master
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2002-2013 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2003 Ross Bencina <rbencina@iprimus.com.au>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
@@ -73,26 +73,24 @@ static void psf_log_syserr (SF_PRIVATE *psf, int error) ;
|
||||
*/
|
||||
|
||||
static int psf_close_fd (int fd) ;
|
||||
static int psf_open_fd (const char * path, int mode) ;
|
||||
static int psf_open_fd (PSF_FILE * pfile) ;
|
||||
static sf_count_t psf_get_filelen_fd (int fd) ;
|
||||
|
||||
int
|
||||
psf_fopen (SF_PRIVATE *psf, const char *pathname, int open_mode)
|
||||
psf_fopen (SF_PRIVATE *psf)
|
||||
{
|
||||
psf->error = 0 ;
|
||||
psf->filedes = psf_open_fd (pathname, open_mode) ;
|
||||
psf->file.filedes = psf_open_fd (&psf->file) ;
|
||||
|
||||
if (psf->filedes == - SFE_BAD_OPEN_MODE)
|
||||
if (psf->file.filedes == - SFE_BAD_OPEN_MODE)
|
||||
{ psf->error = SFE_BAD_OPEN_MODE ;
|
||||
psf->filedes = -1 ;
|
||||
psf->file.filedes = -1 ;
|
||||
return psf->error ;
|
||||
} ;
|
||||
|
||||
if (psf->filedes == -1)
|
||||
if (psf->file.filedes == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
||||
psf->mode = open_mode ;
|
||||
|
||||
return psf->error ;
|
||||
} /* psf_fopen */
|
||||
|
||||
@@ -100,43 +98,40 @@ int
|
||||
psf_fclose (SF_PRIVATE *psf)
|
||||
{ int retval ;
|
||||
|
||||
if (psf->filedes == -1)
|
||||
return -1; /* already closed */
|
||||
|
||||
if (psf->virtual_io)
|
||||
return 0 ;
|
||||
|
||||
if (psf->do_not_close_descriptor)
|
||||
{ psf->filedes = -1 ;
|
||||
if (psf->file.do_not_close_descriptor)
|
||||
{ psf->file.filedes = -1 ;
|
||||
return 0 ;
|
||||
} ;
|
||||
|
||||
if ((retval = psf_close_fd (psf->filedes)) == -1)
|
||||
if ((retval = psf_close_fd (psf->file.filedes)) == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
||||
psf->filedes = -1 ;
|
||||
psf->file.filedes = -1 ;
|
||||
|
||||
return retval ;
|
||||
} /* psf_fclose */
|
||||
|
||||
int
|
||||
psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
psf_open_rsrc (SF_PRIVATE *psf)
|
||||
{
|
||||
if (psf->rsrcdes > 0)
|
||||
if (psf->rsrc.filedes > 0)
|
||||
return 0 ;
|
||||
|
||||
/* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s/rsrc", psf->filepath) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/..namedfork/rsrc", psf->file.path.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
|
||||
if (psf->rsrclength > 0 || (open_mode & SFM_WRITE))
|
||||
if ((psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
|
||||
if (psf->rsrclength > 0 || (psf->rsrc.mode & SFM_WRITE))
|
||||
return SFE_NO_ERROR ;
|
||||
psf_close_fd (psf->rsrcdes) ;
|
||||
psf->rsrcdes = -1 ;
|
||||
psf_close_fd (psf->rsrc.filedes) ;
|
||||
psf->rsrc.filedes = -1 ;
|
||||
} ;
|
||||
|
||||
if (psf->rsrcdes == - SFE_BAD_OPEN_MODE)
|
||||
if (psf->rsrc.filedes == - SFE_BAD_OPEN_MODE)
|
||||
{ psf->error = SFE_BAD_OPEN_MODE ;
|
||||
return psf->error ;
|
||||
} ;
|
||||
@@ -145,10 +140,10 @@ psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
** Now try for a resource fork stored as a separate file in the same
|
||||
** directory, but preceded with a dot underscore.
|
||||
*/
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s._%s", psf->directory, psf->filename) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
|
||||
if ((psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
|
||||
return SFE_NO_ERROR ;
|
||||
} ;
|
||||
|
||||
@@ -156,18 +151,18 @@ psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
** Now try for a resource fork stored in a separate file in the
|
||||
** .AppleDouble/ directory.
|
||||
*/
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s.AppleDouble/%s", psf->directory, psf->filename) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->rsrcdes = psf_open_fd (psf->rsrcpath, open_mode)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrcdes) ;
|
||||
if ((psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
|
||||
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
|
||||
return SFE_NO_ERROR ;
|
||||
} ;
|
||||
|
||||
/* No resource file found. */
|
||||
if (psf->rsrcdes == -1)
|
||||
if (psf->rsrc.filedes == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
||||
psf->rsrcdes = -1 ;
|
||||
psf->rsrc.filedes = -1 ;
|
||||
|
||||
return psf->error ;
|
||||
} /* psf_open_rsrc */
|
||||
@@ -179,7 +174,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.get_filelen (psf->vio_user_data) ;
|
||||
|
||||
filelen = psf_get_filelen_fd (psf->filedes) ;
|
||||
filelen = psf_get_filelen_fd (psf->file.filedes) ;
|
||||
|
||||
if (filelen == -1)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
@@ -191,7 +186,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
return (sf_count_t) -1 ;
|
||||
} ;
|
||||
|
||||
switch (psf->mode)
|
||||
switch (psf->file.mode)
|
||||
{ case SFM_WRITE :
|
||||
filelen = filelen - psf->fileoffset ;
|
||||
break ;
|
||||
@@ -219,28 +214,26 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
|
||||
int
|
||||
psf_close_rsrc (SF_PRIVATE *psf)
|
||||
{
|
||||
if (psf->rsrcdes >= 0)
|
||||
psf_close_fd (psf->rsrcdes) ;
|
||||
psf->rsrcdes = -1 ;
|
||||
{ psf_close_fd (psf->rsrc.filedes) ;
|
||||
psf->rsrc.filedes = -1 ;
|
||||
return 0 ;
|
||||
} /* psf_close_rsrc */
|
||||
|
||||
int
|
||||
psf_set_stdio (SF_PRIVATE *psf, int mode)
|
||||
psf_set_stdio (SF_PRIVATE *psf)
|
||||
{ int error = 0 ;
|
||||
|
||||
switch (mode)
|
||||
switch (psf->file.mode)
|
||||
{ case SFM_RDWR :
|
||||
error = SFE_OPEN_PIPE_RDWR ;
|
||||
break ;
|
||||
|
||||
case SFM_READ :
|
||||
psf->filedes = 0 ;
|
||||
psf->file.filedes = 0 ;
|
||||
break ;
|
||||
|
||||
case SFM_WRITE :
|
||||
psf->filedes = 1 ;
|
||||
psf->file.filedes = 1 ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
@@ -254,29 +247,31 @@ psf_set_stdio (SF_PRIVATE *psf, int mode)
|
||||
|
||||
void
|
||||
psf_set_file (SF_PRIVATE *psf, int fd)
|
||||
{ psf->filedes = fd ;
|
||||
{ psf->file.filedes = fd ;
|
||||
} /* psf_set_file */
|
||||
|
||||
int
|
||||
psf_file_valid (SF_PRIVATE *psf)
|
||||
{ return (psf->filedes >= 0) ? SF_TRUE : SF_FALSE ;
|
||||
{ return (psf->file.filedes >= 0) ? SF_TRUE : SF_FALSE ;
|
||||
} /* psf_set_file */
|
||||
|
||||
sf_count_t
|
||||
psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
{ sf_count_t new_position ;
|
||||
{ sf_count_t current_pos, new_position ;
|
||||
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.seek (offset, whence, psf->vio_user_data) ;
|
||||
|
||||
current_pos = psf_ftell (psf) ;
|
||||
|
||||
switch (whence)
|
||||
{ case SEEK_SET :
|
||||
offset += psf->fileoffset ;
|
||||
break ;
|
||||
|
||||
case SEEK_END :
|
||||
if (psf->mode == SFM_WRITE)
|
||||
{ new_position = lseek (psf->filedes, offset, whence) ;
|
||||
if (psf->file.mode == SFM_WRITE)
|
||||
{ new_position = lseek (psf->file.filedes, offset, whence) ;
|
||||
|
||||
if (new_position < 0)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
@@ -289,15 +284,25 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
** get the offset wrt the start of file.
|
||||
*/
|
||||
whence = SEEK_SET ;
|
||||
offset = lseek (psf->filedes, 0, SEEK_END) + offset ;
|
||||
offset = lseek (psf->file.filedes, 0, SEEK_END) + offset ;
|
||||
break ;
|
||||
|
||||
case SEEK_CUR :
|
||||
/* Translate a SEEK_CUR into a SEEK_SET. */
|
||||
offset += current_pos ;
|
||||
whence = SEEK_SET ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
/* No need to do anything about SEEK_CUR. */
|
||||
break ;
|
||||
/* We really should not be here. */
|
||||
psf_log_printf (psf, "psf_fseek : whence is %d *****.\n", whence) ;
|
||||
return 0 ;
|
||||
} ;
|
||||
|
||||
new_position = lseek (psf->filedes, offset, whence) ;
|
||||
if (current_pos != offset)
|
||||
new_position = lseek (psf->file.filedes, offset, whence) ;
|
||||
else
|
||||
new_position = offset ;
|
||||
|
||||
if (new_position < 0)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
@@ -325,7 +330,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ /* Break the read down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
|
||||
|
||||
count = read (psf->filedes, ((char*) ptr) + total, (size_t) count) ;
|
||||
count = read (psf->file.filedes, ((char*) ptr) + total, (size_t) count) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -366,7 +371,7 @@ psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf
|
||||
{ /* Break the writes down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : items ;
|
||||
|
||||
count = write (psf->filedes, ((const char*) ptr) + total, count) ;
|
||||
count = write (psf->file.filedes, ((const char*) ptr) + total, count) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -399,7 +404,7 @@ psf_ftell (SF_PRIVATE *psf)
|
||||
if (psf->is_pipe)
|
||||
return psf->pipeoffset ;
|
||||
|
||||
pos = lseek (psf->filedes, 0, SEEK_CUR) ;
|
||||
pos = lseek (psf->file.filedes, 0, SEEK_CUR) ;
|
||||
|
||||
if (pos == ((sf_count_t) -1))
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
@@ -413,6 +418,9 @@ static int
|
||||
psf_close_fd (int fd)
|
||||
{ int retval ;
|
||||
|
||||
if (fd < 0)
|
||||
return 0 ;
|
||||
|
||||
while ((retval = close (fd)) == -1 && errno == EINTR)
|
||||
/* Do nothing. */ ;
|
||||
|
||||
@@ -425,7 +433,7 @@ psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf)
|
||||
sf_count_t count ;
|
||||
|
||||
while (k < bufsize - 1)
|
||||
{ count = read (psf->filedes, &(buffer [k]), 1) ;
|
||||
{ count = read (psf->file.filedes, &(buffer [k]), 1) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -451,7 +459,7 @@ psf_is_pipe (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return SF_FALSE ;
|
||||
|
||||
if (fstat (psf->filedes, &statbuf) == -1)
|
||||
if (fstat (psf->file.filedes, &statbuf) == -1)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
/* Default to maximum safety. */
|
||||
return SF_TRUE ;
|
||||
@@ -465,19 +473,22 @@ psf_is_pipe (SF_PRIVATE *psf)
|
||||
|
||||
static sf_count_t
|
||||
psf_get_filelen_fd (int fd)
|
||||
{ struct stat statbuf ;
|
||||
{
|
||||
#if (SIZEOF_OFF_T == 4 && SIZEOF_SF_COUNT_T == 8 && HAVE_FSTAT64)
|
||||
struct stat64 statbuf ;
|
||||
|
||||
/*
|
||||
** Sanity check.
|
||||
** If everything is OK, this will be optimised out.
|
||||
*/
|
||||
if (sizeof (statbuf.st_size) == 4 && sizeof (sf_count_t) == 8)
|
||||
return (sf_count_t) -SFE_BAD_STAT_SIZE ;
|
||||
if (fstat64 (fd, &statbuf) == -1)
|
||||
return (sf_count_t) -1 ;
|
||||
|
||||
return statbuf.st_size ;
|
||||
#else
|
||||
struct stat statbuf ;
|
||||
|
||||
if (fstat (fd, &statbuf) == -1)
|
||||
return (sf_count_t) -1 ;
|
||||
|
||||
return statbuf.st_size ;
|
||||
#endif
|
||||
} /* psf_get_filelen_fd */
|
||||
|
||||
int
|
||||
@@ -491,7 +502,7 @@ psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
|
||||
if ((sizeof (off_t) < sizeof (sf_count_t)) && len > 0x7FFFFFFF)
|
||||
return -1 ;
|
||||
|
||||
retval = ftruncate (psf->filedes, len) ;
|
||||
retval = ftruncate (psf->file.filedes, len) ;
|
||||
|
||||
if (retval == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
@@ -501,28 +512,28 @@ psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
|
||||
|
||||
void
|
||||
psf_init_files (SF_PRIVATE *psf)
|
||||
{ psf->filedes = -1 ;
|
||||
psf->rsrcdes = -1 ;
|
||||
psf->savedes = -1 ;
|
||||
{ psf->file.filedes = -1 ;
|
||||
psf->rsrc.filedes = -1 ;
|
||||
psf->file.savedes = -1 ;
|
||||
} /* psf_init_files */
|
||||
|
||||
void
|
||||
psf_use_rsrc (SF_PRIVATE *psf, int on_off)
|
||||
{
|
||||
if (on_off)
|
||||
{ if (psf->filedes != psf->rsrcdes)
|
||||
{ psf->savedes = psf->filedes ;
|
||||
psf->filedes = psf->rsrcdes ;
|
||||
{ if (psf->file.filedes != psf->rsrc.filedes)
|
||||
{ psf->file.savedes = psf->file.filedes ;
|
||||
psf->file.filedes = psf->rsrc.filedes ;
|
||||
} ;
|
||||
}
|
||||
else if (psf->filedes == psf->rsrcdes)
|
||||
psf->filedes = psf->savedes ;
|
||||
else if (psf->file.filedes == psf->rsrc.filedes)
|
||||
psf->file.filedes = psf->file.savedes ;
|
||||
|
||||
return ;
|
||||
} /* psf_use_rsrc */
|
||||
|
||||
static int
|
||||
psf_open_fd (const char * pathname, int open_mode)
|
||||
psf_open_fd (PSF_FILE * pfile)
|
||||
{ int fd, oflag, mode ;
|
||||
|
||||
/*
|
||||
@@ -530,13 +541,13 @@ psf_open_fd (const char * pathname, int open_mode)
|
||||
** be optimised out. This is meant to catch the problems caused by
|
||||
** "sfconfig.h" being included after <stdio.h>.
|
||||
*/
|
||||
if (sizeof (off_t) != sizeof (sf_count_t))
|
||||
{ puts ("\n\n*** Fatal error : sizeof (off_t) != sizeof (sf_count_t)") ;
|
||||
if (sizeof (sf_count_t) != 8)
|
||||
{ puts ("\n\n*** Fatal error : sizeof (sf_count_t) != 8") ;
|
||||
puts ("*** This means that libsndfile was not configured correctly.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
switch (open_mode)
|
||||
switch (pfile->mode)
|
||||
{ case SFM_READ :
|
||||
oflag = O_RDONLY | O_BINARY ;
|
||||
mode = 0 ;
|
||||
@@ -558,9 +569,9 @@ psf_open_fd (const char * pathname, int open_mode)
|
||||
} ;
|
||||
|
||||
if (mode == 0)
|
||||
fd = open (pathname, oflag) ;
|
||||
fd = open (pfile->path.c, oflag) ;
|
||||
else
|
||||
fd = open (pathname, oflag, mode) ;
|
||||
fd = open (pfile->path.c, oflag, mode) ;
|
||||
|
||||
return fd ;
|
||||
} /* psf_open_fd */
|
||||
@@ -581,10 +592,10 @@ void
|
||||
psf_fsync (SF_PRIVATE *psf)
|
||||
{
|
||||
#if HAVE_FSYNC
|
||||
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
|
||||
fsync (psf->filedes) ;
|
||||
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
|
||||
fsync (psf->file.filedes) ;
|
||||
#else
|
||||
psf = NULL ;
|
||||
psf = NULL ;
|
||||
#endif
|
||||
} /* psf_fsync */
|
||||
|
||||
@@ -596,20 +607,18 @@ psf_fsync (SF_PRIVATE *psf)
|
||||
#include <io.h>
|
||||
|
||||
static int psf_close_handle (HANDLE handle) ;
|
||||
static HANDLE psf_open_handle (const char * path, int mode) ;
|
||||
static HANDLE psf_open_handle (PSF_FILE * pfile) ;
|
||||
static sf_count_t psf_get_filelen_handle (HANDLE handle) ;
|
||||
|
||||
/* USE_WINDOWS_API */ int
|
||||
psf_fopen (SF_PRIVATE *psf, const char *pathname, int open_mode)
|
||||
psf_fopen (SF_PRIVATE *psf)
|
||||
{
|
||||
psf->error = 0 ;
|
||||
psf->hfile = psf_open_handle (pathname, open_mode) ;
|
||||
psf->file.handle = psf_open_handle (&psf->file) ;
|
||||
|
||||
if (psf->hfile == NULL)
|
||||
if (psf->file.handle == NULL)
|
||||
psf_log_syserr (psf, GetLastError ()) ;
|
||||
|
||||
psf->mode = open_mode ;
|
||||
|
||||
return psf->error ;
|
||||
} /* psf_fopen */
|
||||
|
||||
@@ -620,30 +629,30 @@ psf_fclose (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return 0 ;
|
||||
|
||||
if (psf->do_not_close_descriptor)
|
||||
{ psf->hfile = NULL ;
|
||||
if (psf->file.do_not_close_descriptor)
|
||||
{ psf->file.handle = NULL ;
|
||||
return 0 ;
|
||||
} ;
|
||||
|
||||
if ((retval = psf_close_handle (psf->hfile)) == -1)
|
||||
if ((retval = psf_close_handle (psf->file.handle)) == -1)
|
||||
psf_log_syserr (psf, GetLastError ()) ;
|
||||
|
||||
psf->hfile = NULL ;
|
||||
psf->file.handle = NULL ;
|
||||
|
||||
return retval ;
|
||||
} /* psf_fclose */
|
||||
|
||||
/* USE_WINDOWS_API */ int
|
||||
psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
psf_open_rsrc (SF_PRIVATE *psf)
|
||||
{
|
||||
if (psf->hrsrc != NULL)
|
||||
if (psf->rsrc.handle != NULL)
|
||||
return 0 ;
|
||||
|
||||
/* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s/rsrc", psf->filepath) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/rsrc", psf->file.path.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->hrsrc = psf_open_handle (psf->rsrcpath, open_mode)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->hrsrc) ;
|
||||
if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
|
||||
return SFE_NO_ERROR ;
|
||||
} ;
|
||||
|
||||
@@ -651,10 +660,10 @@ psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
** Now try for a resource fork stored as a separate file in the same
|
||||
** directory, but preceded with a dot underscore.
|
||||
*/
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s._%s", psf->directory, psf->filename) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->hrsrc = psf_open_handle (psf->rsrcpath, open_mode)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->hrsrc) ;
|
||||
if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
|
||||
return SFE_NO_ERROR ;
|
||||
} ;
|
||||
|
||||
@@ -662,18 +671,18 @@ psf_open_rsrc (SF_PRIVATE *psf, int open_mode)
|
||||
** Now try for a resource fork stored in a separate file in the
|
||||
** .AppleDouble/ directory.
|
||||
*/
|
||||
snprintf (psf->rsrcpath, sizeof (psf->rsrcpath), "%s.AppleDouble/%s", psf->directory, psf->filename) ;
|
||||
snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ;
|
||||
psf->error = SFE_NO_ERROR ;
|
||||
if ((psf->hrsrc = psf_open_handle (psf->rsrcpath, open_mode)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->hrsrc) ;
|
||||
if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
|
||||
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
|
||||
return SFE_NO_ERROR ;
|
||||
} ;
|
||||
|
||||
/* No resource file found. */
|
||||
if (psf->hrsrc == NULL)
|
||||
if (psf->rsrc.handle == NULL)
|
||||
psf_log_syserr (psf, GetLastError ()) ;
|
||||
|
||||
psf->hrsrc = NULL ;
|
||||
psf->rsrc.handle = NULL ;
|
||||
|
||||
return psf->error ;
|
||||
} /* psf_open_rsrc */
|
||||
@@ -685,7 +694,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.get_filelen (psf->vio_user_data) ;
|
||||
|
||||
filelen = psf_get_filelen_handle (psf->hfile) ;
|
||||
filelen = psf_get_filelen_handle (psf->file.handle) ;
|
||||
|
||||
if (filelen == -1)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
@@ -697,7 +706,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
return (sf_count_t) -1 ;
|
||||
} ;
|
||||
|
||||
switch (psf->mode)
|
||||
switch (psf->file.mode)
|
||||
{ case SFM_WRITE :
|
||||
filelen = filelen - psf->fileoffset ;
|
||||
break ;
|
||||
@@ -725,34 +734,34 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
|
||||
/* USE_WINDOWS_API */ void
|
||||
psf_init_files (SF_PRIVATE *psf)
|
||||
{ psf->hfile = NULL ;
|
||||
psf->hrsrc = NULL ;
|
||||
psf->hsaved = NULL ;
|
||||
{ psf->file.handle = NULL ;
|
||||
psf->rsrc.handle = NULL ;
|
||||
psf->file.hsaved = NULL ;
|
||||
} /* psf_init_files */
|
||||
|
||||
/* USE_WINDOWS_API */ void
|
||||
psf_use_rsrc (SF_PRIVATE *psf, int on_off)
|
||||
{
|
||||
if (on_off)
|
||||
{ if (psf->hfile != psf->hrsrc)
|
||||
{ psf->hsaved = psf->hfile ;
|
||||
psf->hfile = psf->hrsrc ;
|
||||
{ if (psf->file.handle != psf->rsrc.handle)
|
||||
{ psf->file.hsaved = psf->file.handle ;
|
||||
psf->file.handle = psf->rsrc.handle ;
|
||||
} ;
|
||||
}
|
||||
else if (psf->hfile == psf->hrsrc)
|
||||
psf->hfile = psf->hsaved ;
|
||||
else if (psf->file.handle == psf->rsrc.handle)
|
||||
psf->file.handle = psf->file.hsaved ;
|
||||
|
||||
return ;
|
||||
} /* psf_use_rsrc */
|
||||
|
||||
/* USE_WINDOWS_API */ static HANDLE
|
||||
psf_open_handle (const char * pathname, int open_mode)
|
||||
psf_open_handle (PSF_FILE * pfile)
|
||||
{ DWORD dwDesiredAccess ;
|
||||
DWORD dwShareMode ;
|
||||
DWORD dwCreationDistribution ;
|
||||
HANDLE handle ;
|
||||
|
||||
switch (open_mode)
|
||||
switch (pfile->mode)
|
||||
{ case SFM_READ :
|
||||
dwDesiredAccess = GENERIC_READ ;
|
||||
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE ;
|
||||
@@ -775,15 +784,26 @@ psf_open_handle (const char * pathname, int open_mode)
|
||||
return NULL ;
|
||||
} ;
|
||||
|
||||
handle = CreateFile (
|
||||
pathname, /* pointer to name of the file */
|
||||
dwDesiredAccess, /* access (read-write) mode */
|
||||
dwShareMode, /* share mode */
|
||||
0, /* pointer to security attributes */
|
||||
dwCreationDistribution, /* how to create */
|
||||
FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
|
||||
NULL /* handle to file with attributes to copy */
|
||||
) ;
|
||||
if (pfile->use_wchar)
|
||||
handle = CreateFileW (
|
||||
pfile->path.wc, /* pointer to name of the file */
|
||||
dwDesiredAccess, /* access (read-write) mode */
|
||||
dwShareMode, /* share mode */
|
||||
0, /* pointer to security attributes */
|
||||
dwCreationDistribution, /* how to create */
|
||||
FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
|
||||
NULL /* handle to file with attributes to copy */
|
||||
) ;
|
||||
else
|
||||
handle = CreateFile (
|
||||
pfile->path.c, /* pointer to name of the file */
|
||||
dwDesiredAccess, /* access (read-write) mode */
|
||||
dwShareMode, /* share mode */
|
||||
0, /* pointer to security attributes */
|
||||
dwCreationDistribution, /* how to create */
|
||||
FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
|
||||
NULL /* handle to file with attributes to copy */
|
||||
) ;
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return NULL ;
|
||||
@@ -819,32 +839,30 @@ psf_log_syserr (SF_PRIVATE *psf, int error)
|
||||
|
||||
/* USE_WINDOWS_API */ int
|
||||
psf_close_rsrc (SF_PRIVATE *psf)
|
||||
{
|
||||
if (psf->hrsrc != NULL)
|
||||
psf_close_handle (psf->hrsrc) ;
|
||||
psf->hrsrc = NULL ;
|
||||
{ psf_close_handle (psf->rsrc.handle) ;
|
||||
psf->rsrc.handle = NULL ;
|
||||
return 0 ;
|
||||
} /* psf_close_rsrc */
|
||||
|
||||
|
||||
/* USE_WINDOWS_API */ int
|
||||
psf_set_stdio (SF_PRIVATE *psf, int mode)
|
||||
psf_set_stdio (SF_PRIVATE *psf)
|
||||
{ HANDLE handle = NULL ;
|
||||
int error = 0 ;
|
||||
|
||||
switch (mode)
|
||||
switch (psf->file.mode)
|
||||
{ case SFM_RDWR :
|
||||
error = SFE_OPEN_PIPE_RDWR ;
|
||||
break ;
|
||||
|
||||
case SFM_READ :
|
||||
handle = GetStdHandle (STD_INPUT_HANDLE) ;
|
||||
psf->do_not_close_descriptor = 1 ;
|
||||
psf->file.do_not_close_descriptor = 1 ;
|
||||
break ;
|
||||
|
||||
case SFM_WRITE :
|
||||
handle = GetStdHandle (STD_OUTPUT_HANDLE) ;
|
||||
psf->do_not_close_descriptor = 1 ;
|
||||
psf->file.do_not_close_descriptor = 1 ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
@@ -852,7 +870,7 @@ psf_set_stdio (SF_PRIVATE *psf, int mode)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
psf->hfile = handle ;
|
||||
psf->file.handle = handle ;
|
||||
psf->filelength = 0 ;
|
||||
|
||||
return error ;
|
||||
@@ -866,14 +884,14 @@ psf_set_file (SF_PRIVATE *psf, int fd)
|
||||
osfhandle = _get_osfhandle (fd) ;
|
||||
handle = (HANDLE) osfhandle ;
|
||||
|
||||
psf->hfile = handle ;
|
||||
psf->file.handle = handle ;
|
||||
} /* psf_set_file */
|
||||
|
||||
/* USE_WINDOWS_API */ int
|
||||
psf_file_valid (SF_PRIVATE *psf)
|
||||
{ if (psf->hfile == NULL)
|
||||
{ if (psf->file.handle == NULL)
|
||||
return SF_FALSE ;
|
||||
if (psf->hfile == INVALID_HANDLE_VALUE)
|
||||
if (psf->file.handle == INVALID_HANDLE_VALUE)
|
||||
return SF_FALSE ;
|
||||
return SF_TRUE ;
|
||||
} /* psf_set_file */
|
||||
@@ -906,7 +924,7 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
lDistanceToMove = (DWORD) (offset & 0xFFFFFFFF) ;
|
||||
lDistanceToMoveHigh = (DWORD) ((offset >> 32) & 0xFFFFFFFF) ;
|
||||
|
||||
dwResult = SetFilePointer (psf->hfile, lDistanceToMove, &lDistanceToMoveHigh, dwMoveMethod) ;
|
||||
dwResult = SetFilePointer (psf->file.handle, lDistanceToMove, &lDistanceToMoveHigh, dwMoveMethod) ;
|
||||
|
||||
if (dwResult == 0xFFFFFFFF)
|
||||
dwError = GetLastError () ;
|
||||
@@ -942,7 +960,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ /* Break the writes down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
|
||||
|
||||
if (ReadFile (psf->hfile, ((char*) ptr) + total, count, &dwNumberOfBytesRead, 0) == 0)
|
||||
if (ReadFile (psf->file.handle, ((char*) ptr) + total, count, &dwNumberOfBytesRead, 0) == 0)
|
||||
{ psf_log_syserr (psf, GetLastError ()) ;
|
||||
break ;
|
||||
}
|
||||
@@ -965,7 +983,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
/* USE_WINDOWS_API */ sf_count_t
|
||||
psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ sf_count_t total = 0 ;
|
||||
ssize_t count ;
|
||||
ssize_t count ;
|
||||
DWORD dwNumberOfBytesWritten ;
|
||||
|
||||
if (psf->virtual_io)
|
||||
@@ -981,7 +999,7 @@ psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf
|
||||
{ /* Break the writes down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
|
||||
|
||||
if (WriteFile (psf->hfile, ((const char*) ptr) + total, count, &dwNumberOfBytesWritten, 0) == 0)
|
||||
if (WriteFile (psf->file.handle, ((const char*) ptr) + total, count, &dwNumberOfBytesWritten, 0) == 0)
|
||||
{ psf_log_syserr (psf, GetLastError ()) ;
|
||||
break ;
|
||||
}
|
||||
@@ -1016,7 +1034,7 @@ psf_ftell (SF_PRIVATE *psf)
|
||||
lDistanceToMoveLow = 0 ;
|
||||
lDistanceToMoveHigh = 0 ;
|
||||
|
||||
dwResult = SetFilePointer (psf->hfile, lDistanceToMoveLow, &lDistanceToMoveHigh, FILE_CURRENT) ;
|
||||
dwResult = SetFilePointer (psf->file.handle, lDistanceToMoveLow, &lDistanceToMoveHigh, FILE_CURRENT) ;
|
||||
|
||||
if (dwResult == 0xFFFFFFFF)
|
||||
dwError = GetLastError () ;
|
||||
@@ -1035,7 +1053,10 @@ psf_ftell (SF_PRIVATE *psf)
|
||||
|
||||
/* USE_WINDOWS_API */ static int
|
||||
psf_close_handle (HANDLE handle)
|
||||
{ if (CloseHandle (handle) == 0)
|
||||
{ if (handle == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (CloseHandle (handle) == 0)
|
||||
return -1 ;
|
||||
|
||||
return 0 ;
|
||||
@@ -1048,7 +1069,7 @@ psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf)
|
||||
DWORD dwNumberOfBytesRead ;
|
||||
|
||||
while (k < bufsize - 1)
|
||||
{ if (ReadFile (psf->hfile, &(buffer [k]), 1, &dwNumberOfBytesRead, 0) == 0)
|
||||
{ if (ReadFile (psf->file.handle, &(buffer [k]), 1, &dwNumberOfBytesRead, 0) == 0)
|
||||
{ psf_log_syserr (psf, GetLastError ()) ;
|
||||
break ;
|
||||
}
|
||||
@@ -1071,7 +1092,7 @@ psf_is_pipe (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return SF_FALSE ;
|
||||
|
||||
if (GetFileType (psf->hfile) == FILE_TYPE_DISK)
|
||||
if (GetFileType (psf->file.handle) == FILE_TYPE_DISK)
|
||||
return SF_FALSE ;
|
||||
|
||||
/* Default to maximum safety. */
|
||||
@@ -1098,7 +1119,7 @@ psf_get_filelen_handle (HANDLE handle)
|
||||
|
||||
/* USE_WINDOWS_API */ void
|
||||
psf_fsync (SF_PRIVATE *psf)
|
||||
{ FlushFileBuffers (psf->hfile) ;
|
||||
{ FlushFileBuffers (psf->file.handle) ;
|
||||
} /* psf_fsync */
|
||||
|
||||
|
||||
@@ -1120,7 +1141,7 @@ psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
|
||||
lDistanceToMoveLow = (DWORD) (len & 0xFFFFFFFF) ;
|
||||
lDistanceToMoveHigh = (DWORD) ((len >> 32) & 0xFFFFFFFF) ;
|
||||
|
||||
dwResult = SetFilePointer (psf->hfile, lDistanceToMoveLow, &lDistanceToMoveHigh, FILE_BEGIN) ;
|
||||
dwResult = SetFilePointer (psf->file.handle, lDistanceToMoveLow, &lDistanceToMoveHigh, FILE_BEGIN) ;
|
||||
|
||||
if (dwResult == 0xFFFFFFFF)
|
||||
dwError = GetLastError () ;
|
||||
@@ -1135,7 +1156,7 @@ psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
|
||||
** which guarantees that the new portion of the file will be zeroed.
|
||||
** Not sure if this is important or not.
|
||||
*/
|
||||
if (SetEndOfFile (psf->hfile) == 0)
|
||||
if (SetEndOfFile (psf->file.handle) == 0)
|
||||
{ retval = -1 ;
|
||||
psf_log_syserr (psf, GetLastError ()) ;
|
||||
} ;
|
||||
@@ -1191,14 +1212,14 @@ psf_fopen (SF_PRIVATE *psf, const char *pathname, int open_mode)
|
||||
} ;
|
||||
|
||||
if (mode == 0)
|
||||
psf->filedes = open (pathname, oflag) ;
|
||||
psf->file.filedes = open (pathname, oflag) ;
|
||||
else
|
||||
psf->filedes = open (pathname, oflag, mode) ;
|
||||
psf->file.filedes = open (pathname, oflag, mode) ;
|
||||
|
||||
if (psf->filedes == -1)
|
||||
if (psf->file.filedes == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
||||
return psf->filedes ;
|
||||
return psf->file.filedes ;
|
||||
} /* psf_fopen */
|
||||
|
||||
/* Win32 */ sf_count_t
|
||||
@@ -1214,8 +1235,8 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
break ;
|
||||
|
||||
case SEEK_END :
|
||||
if (psf->mode == SFM_WRITE)
|
||||
{ new_position = _lseeki64 (psf->filedes, offset, whence) ;
|
||||
if (psf->file.mode == SFM_WRITE)
|
||||
{ new_position = _lseeki64 (psf->file.filedes, offset, whence) ;
|
||||
|
||||
if (new_position < 0)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
@@ -1228,7 +1249,7 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
** get the offset wrt the start of file.
|
||||
*/
|
||||
whence = SEEK_SET ;
|
||||
offset = _lseeki64 (psf->filedes, 0, SEEK_END) + offset ;
|
||||
offset = _lseeki64 (psf->file.filedes, 0, SEEK_END) + offset ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
@@ -1243,9 +1264,9 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
*** Use the _telli64() function instead.
|
||||
*/
|
||||
if (offset == 0 && whence == SEEK_CUR)
|
||||
new_position = _telli64 (psf->filedes) ;
|
||||
new_position = _telli64 (psf->file.filedes) ;
|
||||
else
|
||||
new_position = _lseeki64 (psf->filedes, offset, whence) ;
|
||||
new_position = _lseeki64 (psf->file.filedes, offset, whence) ;
|
||||
|
||||
if (new_position < 0)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
@@ -1258,7 +1279,7 @@ psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
|
||||
/* Win32 */ sf_count_t
|
||||
psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ sf_count_t total = 0 ;
|
||||
ssize_t count ;
|
||||
ssize_t count ;
|
||||
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.read (ptr, bytes*items, psf->vio_user_data) / bytes ;
|
||||
@@ -1273,7 +1294,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ /* Break the writes down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
|
||||
|
||||
count = read (psf->filedes, ((char*) ptr) + total, (size_t) count) ;
|
||||
count = read (psf->file.filedes, ((char*) ptr) + total, (size_t) count) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -1296,7 +1317,7 @@ psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
/* Win32 */ sf_count_t
|
||||
psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
|
||||
{ sf_count_t total = 0 ;
|
||||
ssize_t count ;
|
||||
ssize_t count ;
|
||||
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.write (ptr, bytes*items, psf->vio_user_data) / bytes ;
|
||||
@@ -1311,7 +1332,7 @@ psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf
|
||||
{ /* Break the writes down to a sensible size. */
|
||||
count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : items ;
|
||||
|
||||
count = write (psf->filedes, ((const char*) ptr) + total, count) ;
|
||||
count = write (psf->file.filedes, ((const char*) ptr) + total, count) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -1338,7 +1359,7 @@ psf_ftell (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.tell (psf->vio_user_data) ;
|
||||
|
||||
pos = _telli64 (psf->filedes) ;
|
||||
pos = _telli64 (psf->file.filedes) ;
|
||||
|
||||
if (pos == ((sf_count_t) -1))
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
@@ -1352,13 +1373,13 @@ psf_ftell (SF_PRIVATE *psf)
|
||||
psf_fclose (SF_PRIVATE *psf)
|
||||
{ int retval ;
|
||||
|
||||
while ((retval = close (psf->filedes)) == -1 && errno == EINTR)
|
||||
while ((retval = close (psf->file.filedes)) == -1 && errno == EINTR)
|
||||
/* Do nothing. */ ;
|
||||
|
||||
if (retval == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
||||
psf->filedes = -1 ;
|
||||
psf->file.filedes = -1 ;
|
||||
|
||||
return retval ;
|
||||
} /* psf_fclose */
|
||||
@@ -1369,7 +1390,7 @@ psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf)
|
||||
sf_count_t count ;
|
||||
|
||||
while (k < bufsize - 1)
|
||||
{ count = read (psf->filedes, &(buffer [k]), 1) ;
|
||||
{ count = read (psf->file.filedes, &(buffer [k]), 1) ;
|
||||
|
||||
if (count == -1)
|
||||
{ if (errno == EINTR)
|
||||
@@ -1396,7 +1417,7 @@ psf_is_pipe (SF_PRIVATE *psf)
|
||||
return SF_FALSE ;
|
||||
|
||||
/* Not sure if this works. */
|
||||
if (fstat (psf->filedes, &statbuf) == -1)
|
||||
if (fstat (psf->file.filedes, &statbuf) == -1)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
/* Default to maximum safety. */
|
||||
return SF_TRUE ;
|
||||
@@ -1420,7 +1441,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
*/
|
||||
struct _stati64 statbuf ;
|
||||
|
||||
if (_fstati64 (psf->filedes, &statbuf))
|
||||
if (_fstati64 (psf->file.filedes, &statbuf))
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
return (sf_count_t) -1 ;
|
||||
} ;
|
||||
@@ -1432,7 +1453,7 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
if (psf->virtual_io)
|
||||
return psf->vio.get_filelen (psf->vio_user_data) ;
|
||||
|
||||
if ((current = _telli64 (psf->filedes)) < 0)
|
||||
if ((current = _telli64 (psf->file.filedes)) < 0)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
return (sf_count_t) -1 ;
|
||||
} ;
|
||||
@@ -1450,17 +1471,17 @@ psf_get_filelen (SF_PRIVATE *psf)
|
||||
** by libsndfile and changing the license to GPL at the same time.
|
||||
*/
|
||||
|
||||
_lseeki64 (psf->filedes, 0, SEEK_END) ;
|
||||
_lseeki64 (psf->file.filedes, 0, SEEK_END) ;
|
||||
|
||||
if ((filelen = _lseeki64 (psf->filedes, 0, SEEK_END)) < 0)
|
||||
if ((filelen = _lseeki64 (psf->file.filedes, 0, SEEK_END)) < 0)
|
||||
{ psf_log_syserr (psf, errno) ;
|
||||
return (sf_count_t) -1 ;
|
||||
} ;
|
||||
|
||||
if (filelen > current)
|
||||
_lseeki64 (psf->filedes, current, SEEK_SET) ;
|
||||
_lseeki64 (psf->file.filedes, current, SEEK_SET) ;
|
||||
|
||||
switch (psf->mode)
|
||||
switch (psf->file.mode)
|
||||
{ case SFM_WRITE :
|
||||
filelen = filelen - psf->fileoffset ;
|
||||
break ;
|
||||
@@ -1504,7 +1525,7 @@ psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
|
||||
if (len > 0x7FFFFFFF)
|
||||
return -1 ;
|
||||
|
||||
retval = chsize (psf->filedes, len) ;
|
||||
retval = chsize (psf->file.filedes, len) ;
|
||||
|
||||
if (retval == -1)
|
||||
psf_log_syserr (psf, errno) ;
|
||||
|
Reference in New Issue
Block a user