<parameter>len</parameter>). The <parameter>fd</parameter>
argument must have been returned by a previous
<function>lo_open</function>. The number of bytes actually read is
returned; this will be less than <parameter>len</parameter> if the end of
the large object is reached first. In the event of an error, the return
value is -1.
</para>
<para>
Although the <parameter>len</parameter> parameter is declared as
<type>size_t</type>, this function will reject length values larger than
<literal>INT_MAX</literal>. In practice, it's best to transfer data in chunks
of at most a few megabytes anyway.
</para>
</sect2>
<sect2 id="lo-seek">
<title>Seeking in a Large Object</title>
<para>
<indexterm><primary>lo_lseek</primary></indexterm>
To change the current read or write location associated with a
large object descriptor, call
<synopsis>
int lo_lseek(PGconn *conn, int fd, int offset, int whence);
</synopsis>
This function moves the
current location pointer for the large object descriptor identified by
<parameter>fd</parameter> to the new location specified by
<parameter>offset</parameter>. The valid values for <parameter>whence</parameter>
are <symbol>SEEK_SET</symbol> (seek from object start),
<symbol>SEEK_CUR</symbol> (seek from current position), and
<symbol>SEEK_END</symbol> (seek from object end). The return value is
the new location pointer, or -1 on error.
</para>
<para>
<indexterm><primary>lo_lseek64</primary></indexterm>
When dealing with large objects that might exceed 2GB in size,
instead use
<synopsis>
int64_t lo_lseek64(PGconn *conn, int fd, int64_t offset, int whence);
</synopsis>
This function has the same behavior
as <function>lo_lseek</function>, but it can accept an
<parameter>offset</parameter> larger than 2GB and/or deliver a result larger
than 2GB.
Note that <function>lo_lseek</function> will fail if the new location
pointer would be greater than 2GB.
</para>
<para>
<function>lo_lseek64</function> is new as of <productname>PostgreSQL</productname>
9.3. If this function is run against an older server version, it will
fail and return -1.
</para>
</sect2>
<sect2 id="lo-tell">
<title>Obtaining the Seek Position of a Large Object</title>
<para>
<indexterm><primary>lo_tell</primary></indexterm>
To obtain the current read or write location of a large object descriptor,
call
<synopsis>
int lo_tell(PGconn *conn, int fd);
</synopsis>
If there is an error, the return value is -1.
</para>
<para>
<indexterm><primary>lo_tell64</primary></indexterm>
When dealing with large objects that might exceed 2GB in size,
instead use
<synopsis>
int64_t lo_tell64(PGconn *conn, int fd);
</synopsis>
This function has the same behavior
as <function>lo_tell</function>, but it can deliver a result larger
than 2GB.
Note that <function>lo_tell</function> will fail if the current
read/write location is greater than 2GB.
</para>
<para>
<function>lo_tell64</function> is new as of <productname>PostgreSQL</productname>
9.3. If this function is run against an older server version, it will
fail and return -1.
</para>
</sect2>
<sect2 id="lo-truncate">
<title>Truncating a Large Object</title>
<para>
<indexterm><primary>lo_truncate</primary></indexterm>
To truncate a large object to a given length, call
<synopsis>
int lo_truncate(PGconn *conn, int fd, size_t len);
</synopsis>
This function truncates the large object
descriptor <parameter>fd</parameter> to length <parameter>len</parameter>. The
<parameter>fd</parameter> argument must have been returned by a
previous <function>lo_open</function>. If <parameter>len</parameter> is
greater than the large object's current length, the large object
is extended to the specified length with null bytes ('\0').
On success, <function>lo_truncate</function>