If you want to show off that you are really clever then you get to the next level - with making your library dualmode just like the plain C library on a 64on32 system. Two advantages (A) you can export plain off_t seekvalues and file descriptors which makes it damn easy to integrate with third party code that does clever things to file descriptors as well. A rare case but (B) if you have shipped a library already in 32bit-off_t mode and you want your new library generation to be binary-compatible. The latter is the reason why the C library is dualmode, and quite often a reason to throw yourself into it.
However, be warned of the fact that a dualmode library can quickly get a PITA to maintain, you should think twice if you rally need to ship a binary compatible library or if it is somehow feasible to ship a new generation of your software in parallel with the old stuff left in the old shape thereby using mere longlong wrapping with the new generation. The problems are not about the size of extra code to add to your software - but at each point where you may be given a file descriptor or seek value from outside you need to constantly check for errors like EOVERFLOW and to also produce these kind of errors.
As an example, look at this snippet:
#ifndef MY_DUALMODE #define my_seek64 my_seek #endif off_t my_seek64(int fd, off_t value) { off_t at = lseek(fd, value, 0); // might return at == -1 and set errno to EOVERFLOW but we dont // need to care in this example - return that error condition return at; } #ifdef MY_DUALMODE long my_seek(int fd, long value) { // the library itself is compiled as largefile, links to lseek64 off_t at = lseek(fd, (off_t)value, 0); long ret = at; // the seek result can be represented in 32bit? if (ret != at) { errno = EOVERFLOW; return -1; } return ret; } #endif
Additionally, you need to make the header files of your library be dualmode aware. Whatever mode the third party software gets compiled in, they should work correctly. With autoconf, you may want to use the AX_SYS_LARGEFILE_SENSITIVE macro along with AX_PREFIX_CONFIG_H to allow the configure-check to be installed as a lib-config.h (see the ac-archive for these).
#ifdef MY_LARGEFILE_SENSITIVE #if _FILE_OFFSET_BITS+0 == 64 #define my_seek my_seek64 #ifndef _LARGEFILE64_SOURCE #error 64on32 has not magically defined _LARGEFILE64_SOURCE #endif #endif #endif #ifdef _LARGEFILE64_SOURCE off64_t my_seek64(int fd, off64_t value); #endif off_t my_seek(int fd, off_t value);
After all, be sure to read the whole site your are currently looking at to be aware of what problems lie ahead with a dualmode library in a 64on32 system. However, there were no problem reports with my zziplib so far after implementing dualmode support. If the text above makes you cautious (and it damn should!) then have a look at the next two sections telling about twinlibs and how to defend against improper third party setups.