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) 2003-12-20 Guido U. Draheim |
Step 4: converting to dualmode off_tIf 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. |