printer / text mode version compat32 calls

index
-summary
-history
-testscript
  perl / python
problems
-with callframes
-with structures
-largefile seeks
-broken builds
systems
-freeBSD/darwin
-linux/solaris
-64on32 mix
-distro makers
-win32/other (2)
libraries
-libc ..(3264)
-zlib ..(-32-)
-gtk2 ..(-64-)
converting
-old non-off_t code
-going largefile
-longlong default
-face dualmode
-make twinlibs
-and defend (it)
programming
-largefile default
-off_t in headers
-make export64
-find mismatch
-the autowrappers
-environ changes
-best practice?
old library
-dualmode renames
-the extra function
-largefile64_source
-glibc headers
-libgz example ***
new library
-dual export
-largefiles win32
-compat32 calls
-compat32 library
-long32 dualmode
links
-some quotes
-sitemap / mpl
-large.file Group*
-ac-archive Site*

 

 

 

(C) 2010-03-27 <guidod>
 Guido U. Draheim

compat32 calls

Embedding compat32 calls is basically the inverse of a dualmode library. Instead of renaming largefile64 functions into a new call with a "64" suffix one would continue the normal compilation process where the normal functions are compiled in largefile64 mode - additionally one does add a second series of functions using the traditional "long" instead of "off_t". These should be given a suffix of "32" to differentiate them from the other calls.

The actual advantage over a dualmode library is in the fact that the library header files do not really need #ifdefs. It is just required that any function with a "off_t" arguments gets a sister call with "long" arguments in the same place. This looks like so..

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

The standard implementation of the myseek32 would be a wrapper around the largefile64 variant. On a 64bit system it happens that both "long" and "off64_t" are the same size, so we try to ask the compiler to detect the situation and "remove unreachable code" (which modern C compilers can actually do). Essentially the code template looks like so...

#ifndef EOVERFLOW
#define EOVERFLOW EFBIG
#endif

long
myseek32(MYFILE * fp, long offset, int whence)
{
    if (sizeof(off64_t) == sizeof(long))
    {
        return myseek(fp, offset, whence); /* << largefile64 */
    } else
    {
        off64_t off = myseek(fp, offset, whence);
        if (off >= 0) {
            register long off32 = off;
            if (off32 == off) return off32;
            errno = EOVERFLOW;
        }
        return -1;
    }
}