Home

lineptr

Lineptr is a conventional parameter name used in the POSIX getline and related functions to refer to a buffer that will hold a line read from a stream. The name does not denote a separate type or object; it is simply the pointer to the memory that stores the line text.

In C, the getline function has the signature ssize_t getline(char **lineptr, size_t *n, FILE *stream). The lineptr

The function reads from the specified stream up to and including the newline character, or until end-of-file,

Lineptr is often discussed alongside getdelim, which reads up to a specified delimiter rather than a newline.

argument
points
to
a
buffer
that
will
contain
the
input
line,
and
n
points
to
the
size
of
that
buffer.
If
*lineptr
is
NULL
or
*n
is
0,
getline
allocates
a
buffer
with
malloc
and
stores
the
address
in
*lineptr,
updating
*n
to
reflect
the
buffer
size.
If
the
existing
buffer
is
large
enough,
getline
uses
it;
otherwise
it
reallocates
as
needed.
and
stores
the
result
as
a
null-terminated
string
in
*lineptr.
It
returns
the
number
of
characters
read,
including
the
newline
if
present,
but
not
including
the
terminating
null
byte.
On
end-of-file
with
no
characters
read,
or
on
error,
it
returns
-1.
When
successful,
the
caller
owns
the
allocated
buffer
and
is
responsible
for
freeing
it
with
free(*lineptr)
when
it
is
no
longer
needed.
Subsequent
calls
can
reuse
the
same
buffer
by
passing
the
same
lineptr
and
n.
The
term
emphasizes
the
buffer’s
role
rather
than
a
distinct
data
type,
and
while
getline
is
common
on
many
systems,
portability
varies
across
platforms.