Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

70 File I/O Chapter 3


Name of option Description nameargument
_POSIX_V7_ILP32_OFF32 int,long,pointer,andoff_ttypes _SC_V7_ILP32_OFF32
are 32 bits.
_POSIX_V7_ILP32_OFFBIG int,long,and pointer types are _SC_V7_ILP32_OFFBIG
32 bits;off_ttypes are at least
64 bits.
_POSIX_V7_LP64_OFF64 inttypes are 32 bits;long,pointer, _SC_V7_LP64_OFF64
andoff_ttypes are 64 bits.
_POSIX_V7_LP64_OFFBIG inttypes are at least 32 bits;long, _SC_V7_LP64_OFFBIG
pointer,andoff_ttypes areat
least 64 bits.

Figure 3.3Data size options andnamearguments tosysconf

Thec99 compiler requires that we use thegetconf( 1 )command to map the
desired data size model to the flags necessary to compile and link our programs.
Different flags and libraries might be needed, depending on the environments
supported by each platform.

Unfortunately,this is one area in which implementations haven’t caught up to the standards.
If your system does not match the latest version of the standard, the system might support the
option names from the previous version of the Single UNIX Specification:
_POSIX_V6_ILP32_OFF32,_POSIX_V6_ILP32_OFFBIG,_POSIX_V6_LP64_OFF64,and
_POSIX_V6_LP64_OFFBIG.
To get around this, applications can set the_FILE_OFFSET_BITSconstant to 64 to enable
64 - bit offsets. Doing so changes the definition ofoff_tto be a 64-bit signed integer.Setting
_FILE_OFFSET_BITSto 32 enables 32-bit file offsets. Be aware, however,that although all
four platforms discussed in this text support both 32-bit and 64-bit file offsets, setting
_FILE_OFFSET_BITSis not guaranteed to be portable and might not have the desired effect.
Figure3.4 summarizes the size in bytes of theoff_tdata type for the platforms covered in
this book when an application doesn’t define_FILE_OFFSET_BITS, as well as the size when
an application defines_FILE_OFFSET_BITSto have a value of either 32 or 64.

Operating CPU _FILE_OFFSET_BITSvalue
system architectureUndefined 32 64
FreeBSD 8.0 x86 32-bit 8 88
Linux 3.2.0 x86 64-bit 8 88
Mac OS X 10.6.8 x86 64-bit 8 88
Solaris 10 SPARC 64-bit 8 48

Figure 3.4Size in bytes ofoff_tfor different platforms

Note that even though you might enable 64-bit file offsets, your ability to create a
file larger than 2 GB( 231 −1bytes)depends on the underlying file system type.
Free download pdf