Skip to content
Snippets Groups Projects
Commit 9d444cf2 authored by rswindell's avatar rswindell
Browse files

Define int64_t and use it for return type of flength() to support files >2G

in size (or >4G-1byte depending on how the return value was used).
This is going to trigger a bunch of warnings like this:
conversion from '__int64 ' to 'unsigned long ', possible loss of data
which will be fixed over type (either with typecasts or by supporting 64-bit
file sizes, as the case may be).
parent 8733f932
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -388,8 +388,9 @@ int DLLCALL setfdate(const char* filename, time_t t)
/****************************************************************************/
/* Returns the length of the file in 'filename' */
/* or -1 if the file doesn't exist */
/****************************************************************************/
long DLLCALL flength(const char *filename)
int64_t DLLCALL flength(const char *filename)
{
#if defined(__BORLANDC__) && !defined(__unix__) /* stat() doesn't work right */
......@@ -397,7 +398,7 @@ long DLLCALL flength(const char *filename)
struct _finddata_t f;
if(access((char*)filename,0)==-1)
return(-1L);
return(-1);
if((handle=_findfirst((char*)filename,&f))==-1)
return(-1);
......@@ -408,13 +409,21 @@ long DLLCALL flength(const char *filename)
#else
#ifdef _WIN32
struct _stati64 st;
#else
struct stat st;
#endif
if(access(filename,0)==-1)
return(-1L);
return(-1);
#ifdef _WIN32
if(_stati64(filename, &st)!=0)
#else
if(stat(filename, &st)!=0)
return(-1L);
#endif
return(-1);
return(st.st_size);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -218,7 +218,7 @@ extern "C" {
/* General file system wrappers for all platforms and compilers */
DLLEXPORT BOOL DLLCALL fexist(const char *filespec);
DLLEXPORT BOOL DLLCALL fexistcase(char *filespec); /* fixes upr/lwr case fname */
DLLEXPORT long DLLCALL flength(const char *filename);
DLLEXPORT int64_t DLLCALL flength(const char *filename);
DLLEXPORT time_t DLLCALL fdate(const char *filename);
DLLEXPORT int DLLCALL setfdate(const char* filename, time_t t);
DLLEXPORT BOOL DLLCALL isdir(const char *filename);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -153,6 +153,14 @@ typedef uchar uint8_t;
typedef ushort uint16_t;
typedef ulong uint32_t;
#if defined(_MSC_VER) || defined(__WATCOMC__)
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;
#endif
#endif
/* Legacy 32-bit time_t */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment