|go text: || - index - problems - systems - libraries - [ converting ] - programming - old library - new library - links -
||topics: || - old non-off_t code - going largefile - [ longlong default ] - face dualmode - make twinlibs - and defend - converting to longlong 2003-12-20 Step 3: converting to longlong seek values

If your library exports seek values or file descriptors then you need to care about the shapeshift semantics on 64on32 systems like linux/solaris. The easiest to get away with them is twofold:

compile as largefile: your library will use file descriptors internally that can get beyond 2 GiB. Be sure to check function calls (esp. seeks) for errors of type EOVERFLOW which notify you that a non-largefile file descriptors had been trying to get beyond the 2 GiB range allowed on a 32bit system with a 32bit off_t. It is not advisable to export those file descriptors and allow third party software to chew on them with direct seek calls not wrapped by your library. Just be ready that your library has inherited some non-largefile file descriptor from somewhere.

export longlong: do not use off_t in your header files since that typedef is subject to shapeshifting on 64on32 systems. Instead use `typedef long long mylib_off_t` which is 64bit on all contemporary systems and it can wrap all seek values on whatever platform (be 32bit or 64bit). The gtk2 library is an example for just that. With older C compilers the `long long` type might not exist or named differently but that is again pre-1998, the gtk2 library has some extensive checks to define a longlong type first and puts its seekvalue typedef on top of it.

wrap it: using these techniques above, ensure that all real work on a file descriptor is done right within your library. You may need to export a bunch of extra mylib_seek and my_tell functions that use a mylib_off_t as arguments/returntypes which are really 64bit wide even on 64on32 systems with a largefile kernel. Those wrappers are generally written quick and easy and they ensure that no problems come up with third party software to chew on your file descriptors directly.