Skip to content

Commit e6f7cae

Browse files
committed
Use only SIZEOF_OFF_T to determine "large file support"
1 parent 99a41ec commit e6f7cae

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

libmspack/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2020-04-13 Stuart Caie <[email protected]>
2+
3+
* system.h: clear up libmspack's large file support.
4+
5+
To support large files, do this:
6+
7+
1. add any defines that your compiler needs to enable large file
8+
support. It may be supported by default.
9+
2. Define HAVE_FSEEKO if fseeko() and ftello() are available.
10+
3. Define SIZEOF_OFF_T to the value of sizeof(off_t); it must be a
11+
literal value because sizeof() can't be used in preprocessor tests.
12+
13+
libmspack uses the off_t datatype for all file offsets. If off_t is
14+
less than 64 bits, libmspack will return an error when processing
15+
CHM files with offsets beyond 2GB, and won't search for CAB headers
16+
beyond 2GB into a file. In both cases, it prints a warning message
17+
that the library doesn't support large files.
18+
119
2020-04-13 Stuart Caie <[email protected]>
220

321
* macros.h: new header for the D(), LD/LU and EndGet???() macros.

libmspack/mspack/cabd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,10 @@ static int cabd_find(struct mscab_decompressor_p *self, unsigned char *buf,
651651
unsigned int cablen_u32 = 0, foffset_u32 = 0;
652652
int false_cabs = 0;
653653

654-
#if !LARGEFILE_SUPPORT
654+
#if SIZEOF_OFF_T < 8
655655
/* detect 32-bit off_t overflow */
656656
if (flen < 0) {
657-
sys->message(fh, largefile_msg);
657+
sys->message(fh, "library not compiled to support large files.");
658658
return MSPACK_ERR_OK;
659659
}
660660
#endif
@@ -753,10 +753,10 @@ static int cabd_find(struct mscab_decompressor_p *self, unsigned char *buf,
753753
/* cause the search to restart after this cab's data. */
754754
offset = caboff + (off_t) cablen_u32;
755755

756-
#if !LARGEFILE_SUPPORT
756+
#if SIZEOF_OFF_T < 8
757757
/* detect 32-bit off_t overflow */
758758
if (offset < caboff) {
759-
sys->message(fh, largefile_msg);
759+
sys->message(fh, "library not compiled to support large files.");
760760
return MSPACK_ERR_OK;
761761
}
762762
#endif

libmspack/mspack/chmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,12 +1364,12 @@ static int chmd_error(struct mschm_decompressor *base) {
13641364
static int read_off64(off_t *var, unsigned char *mem,
13651365
struct mspack_system *sys, struct mspack_file *fh)
13661366
{
1367-
#if LARGEFILE_SUPPORT
1367+
#if SIZEOF_OFF_T >= 8
13681368
*var = EndGetI64(mem);
13691369
#else
13701370
*var = EndGetI32(mem);
13711371
if ((*var & 0x80000000) || EndGetI32(mem+4)) {
1372-
sys->message(fh, (char *)largefile_msg);
1372+
sys->message(fh, "library not compiled to support large files.");
13731373
return 1;
13741374
}
13751375
#endif

libmspack/mspack/system.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313

1414
#include <system.h>
1515

16-
#if !LARGEFILE_SUPPORT
17-
const char *largefile_msg = "library not compiled to support large files.";
18-
#endif
19-
20-
2116
int mspack_version(int entity) {
2217
switch (entity) {
2318
/* CHM decoder version 1 -> 2 changes:

libmspack/mspack/system.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,6 @@ static inline size_t strlen(const char *s) {
4949
# undef read
5050
#endif
5151

52-
/* CAB supports searching through files over 4GB in size, and the CHM file
53-
* format actively uses 64-bit offsets. These can only be fully supported
54-
* if the system the code runs on supports large files. If not, the library
55-
* will work as normal using only 32-bit arithmetic, but if an offset
56-
* greater than 2GB is detected, an error message indicating the library
57-
* can't support the file should be printed.
58-
*/
59-
#include <limits.h>
60-
#if ((defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS >= 64) || \
61-
(defined(FILESIZEBITS) && FILESIZEBITS >= 64) || \
62-
defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE) || \
63-
SIZEOF_OFF_T >= 8)
64-
# define LARGEFILE_SUPPORT 1
65-
#else
66-
extern const char *largefile_msg;
67-
#endif
68-
6952
extern struct mspack_system *mspack_default_system;
7053

7154
/* returns the length of a file opened for reading */

0 commit comments

Comments
 (0)