MCPcopy Create free account
hub / github.com/apache/cloudberry / lo_write

Function lo_write

src/interfaces/libpq/fe-lobj.c:298–342  ·  view source on GitHub ↗

* lo_write * write len bytes of buf into the large object fd * * returns the number of bytes written, or -1 on failure. */

Source from the content-addressed store, hash-verified

296 * returns the number of bytes written, or -1 on failure.
297 */
298int
299lo_write(PGconn *conn, int fd, const char *buf, size_t len)
300{
301 PQArgBlock argv[2];
302 PGresult *res;
303 int result_len;
304 int retval;
305
306 if (lo_initialize(conn) < 0)
307 return -1;
308
309 /*
310 * Long ago, somebody thought it'd be a good idea to declare this function
311 * as taking size_t ... but the underlying backend function only accepts a
312 * signed int32 length. So throw error if the given value overflows
313 * int32.
314 */
315 if (len > (size_t) INT_MAX)
316 {
317 appendPQExpBufferStr(&conn->errorMessage,
318 libpq_gettext("argument of lo_write exceeds integer range\n"));
319 return -1;
320 }
321
322 argv[0].isint = 1;
323 argv[0].len = 4;
324 argv[0].u.integer = fd;
325
326 argv[1].isint = 0;
327 argv[1].len = (int) len;
328 argv[1].u.ptr = (int *) unconstify(char *, buf);
329
330 res = PQfn(conn, conn->lobjfuncs->fn_lo_write,
331 &retval, &result_len, 1, argv, 2);
332 if (PQresultStatus(res) == PGRES_COMMAND_OK)
333 {
334 PQclear(res);
335 return retval;
336 }
337 else
338 {
339 PQclear(res);
340 return -1;
341 }
342}
343
344/*
345 * lo_lseek

Callers 1

lo_import_internalFunction · 0.70

Calls 6

lo_initializeFunction · 0.85
appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
PQfnFunction · 0.85
PQresultStatusFunction · 0.85
PQclearFunction · 0.85

Tested by

no test coverage detected