sndfile-salvage: Handle files > 4 GB on Windows OS

This commit is contained in:
evpobr 2021-03-06 12:22:14 +05:00
parent 36c5198d91
commit 6dee7120ab
2 changed files with 25 additions and 5 deletions

View File

@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`replace_read_f2i`(), thanks @bobsayshilol, (issue #702).
* Missing samples when doing a partial read of Ogg file from index till the end
of file, thanks @arthurt (issue #643).
* sndfile-salvage: Handle files > 4 GB on Windows OS
### Security

View File

@ -56,6 +56,12 @@
#define NOT(x) (! (x))
#ifndef _WIN32
typedef off_t sf_off_t ;
#else
typedef long long sf_off_t ;
#endif
static void usage_exit (const char *progname) ;
static void salvage_file (const char * broken_wav, const char * fixed_w64) ;
@ -74,8 +80,8 @@ main (int argc, char *argv [])
/*==============================================================================
*/
static void lseek_or_die (int fd, off_t offset, int whence) ;
static sf_count_t get_file_length (int fd, const char * name) ;
static void lseek_or_die (int fd, sf_off_t offset, int whence) ;
static sf_off_t get_file_length (int fd, const char * name) ;
static sf_count_t find_data_offset (int fd, int format) ;
static void copy_data (int fd, SNDFILE * sndfile, int readsize) ;
@ -180,9 +186,13 @@ salvage_file (const char * broken_wav, const char * fixed_w64)
*/
static void
lseek_or_die (int fd, off_t offset, int whence)
lseek_or_die (int fd, sf_off_t offset, int whence)
{
#ifndef _WIN32
if (lseek (fd, offset, whence) < 0)
#else
if (_lseeki64 (fd, offset, whence) < 0)
#endif
{ printf ("lseek failed : %s\n", strerror (errno)) ;
exit (1) ;
} ;
@ -191,9 +201,14 @@ lseek_or_die (int fd, off_t offset, int whence)
} /* lseek_or_die */
static sf_count_t
static sf_off_t
get_file_length (int fd, const char * name)
{ struct stat sbuf ;
{
#ifndef _WIN32
struct stat sbuf ;
#else
struct _stat64 sbuf ;
#endif
if (sizeof (sbuf.st_size) != 8)
{ puts ("Error : sizeof (sbuf.st_size) != 8. Was program compiled with\n"
@ -201,7 +216,11 @@ get_file_length (int fd, const char * name)
exit (1) ;
} ;
#ifndef _WIN32
if (fstat (fd, &sbuf) != 0)
#else
if (_fstat64 (fd, &sbuf) != 0)
#endif
{ printf ("Error : fstat ('%s') failed : %s\n", name, strerror (errno)) ;
exit (1) ;
} ;