* lo_write * write len bytes of buf into the large object fd * * returns the number of bytes written, or -1 on failure. */
| 296 | * returns the number of bytes written, or -1 on failure. |
| 297 | */ |
| 298 | int |
| 299 | lo_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 |
no test coverage detected