Home

FILEOFFSETBITS

FILEOFFSETBITS is a macro concept used in some C libraries and kernel headers to control the width of file offsets, effectively choosing between 32-bit and 64-bit offsets. In practice, the commonly used form is _FILE_OFFSET_BITS, which, when defined before including standard headers, switches the offset type used by the C library from 32-bit to 64-bit. This enables large-file support (LFS) on systems where 32-bit offsets would limit file sizes to 2 GiB.

How it works: on 32-bit systems, defining _FILE_OFFSET_BITS as 64 causes types such as off_t to become

Usage notes: to enable large-file support in user-space code, place a preprocessor directive such as #define

Variants and naming: the exact macro name can vary by library or platform, with FILE_OFFSET_BITS and FILEOFFSETBITS

64-bit,
and
it
can
enable
64-bit
variants
of
file-seeking
and
positioning
functions
(for
example,
fseeko/ftello
and
lseek)
to
operate
on
larger
files.
If
the
macro
is
not
defined
or
is
defined
as
32,
the
default
32-bit
offsets
remain
in
effect.
On
native
64-bit
systems,
these
offsets
are
typically
already
64-bit,
so
the
macro
may
have
no
practical
effect.
_FILE_OFFSET_BITS
64
before
including
any
headers.
Some
environments
also
support
a
corresponding
_FILE_OFFSET_BITS
value
of
32
to
contract
offsets
back
to
32
bits.
Developers
should
be
aware
of
ABI
implications,
as
enabling
64-bit
offsets
changes
the
sizes
of
types
like
off_t
and
can
affect
binary
compatibility
with
pre-LFS
code.
appearing
in
some
contexts.
The
underlying
idea
remains
the
same:
selecting
32-bit
vs
64-bit
file
offsets
to
support
large
files.
See
also
Large
File
Support,
off_t,
lseek,
fseeko,
and
ftello.