|go text: || - index - problems - systems - libraries - converting - programming - old library - [ new library ] - links -
||topics: || - dual export - [ largefiles win32 ] - compat32 calls - compat32 library - long32 dualmode -

Large files in Win32

As discussed in Win32 largefile API there is no "off_t" in Win32 and none of the AC_SYS_LARGEFILE magic can make your standard program to access the largefile API by default - i.e. the "lseek" call is never diverted to a "lseek64" or "lseeki64" call.

Still some libraries target large files by default and they want to pick up the Win32 large files API in their source code - hopefully without sacrificing portability to platforms that do not have large files at all - including some embedded systems and a lot of old platforms design that continue to exist. (Most people think that software runs for the 3 to 5 years support offer of the big companies but in reality there are lots of installations that need to run for more than 10 years and you will definitly find a number of installations being more than 20 years in the place).

There is a usual habit on Win32 systems that the missing "off_t" is being defined to "long". This is actually what the autoconf AC_TYPE_OFF_T will do and many others will opt for the same plan - simply because "long" was to type used in all function call declarations like "lseek" until it was replaced by "off_t". In order to expose a largefile API of your library it is best pick up the "off64_t" type.

largefile64_source.h
#ifndef _LARGEFILE64_H
#define _LARGEFILE64_H

#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE 1
#endif

/* read the off64_t declaration */
#include 

#ifdef WIN32
#include 
#ifndef off64_t
#define off64_t __int64
#define lseek64 _lseeki64
#define fstat64 _fstati64
#define ftell64 _ftelli64
#define stat64 _stati64
#endif

#endif

With the off64_t being in place you can now define your declarations in terms of "off64_t" for the largefile variants of your function calls. Your library implementation will be a portable largefile variant for both win32-compatabible systems (WIN32,WIN64,WINCE) as well as for UNIX98-compatible systems (Linux, Solaris) and BSD-systems (MacOsX/Darwin, FreeBSD, etc) which is of course a relevant subset of all the operating systems to exist.

#include "largefile64_source.h"

extern off64_t myseek64(int fd, off64_t seek, int whence);
extern long myseek32(int fd, long seek, int whence);

#if _FILE_OFFSET_BITS+0 == 64 || defined _LARGE_FILES
#define myseek myseek64
#else
#define myseek myseek32
#endif

Remember that the latter "ifdef-else" is just a shorthand for the redirect of the shapeshifting "off_t" declaration. You can make it more explicit in your headers if you check for C99 followed by their inline-function equivalents.

#include "largefile64_source.h"

extern off64_t myseek64(int fd, off64_t seek, int whence);
extern long myseek32(int fd, long seek, int whence);

#if __STDC_VERSION__+0 > 199900L || __GNUC__+0 >= 3 || defined __cplusplus
# if _FILE_OFFSET_BITS+0 == 64 || defined _LARGE_FILES
   inline off_t myseek(int fd, off_t seek, int whence) {
      return myseek64(fd, seek, whence);
   }
# else
   inline off_t myseek(int fd, off_t seek, int whence) {
      return myseek32(fd, seek, whence);
   }
# endif
#else
# if _FILE_OFFSET_BITS+0 == 64 || defined _LARGE_FILES
# define myseek myseek64
# else
# define myseek myseek32
#endif