| 245 | */ |
| 246 | |
| 247 | int |
| 248 | lo_read(PGconn *conn, int fd, char *buf, size_t len) |
| 249 | { |
| 250 | PQArgBlock argv[2]; |
| 251 | PGresult *res; |
| 252 | int result_len; |
| 253 | |
| 254 | if (lo_initialize(conn) < 0) |
| 255 | return -1; |
| 256 | |
| 257 | /* |
| 258 | * Long ago, somebody thought it'd be a good idea to declare this function |
| 259 | * as taking size_t ... but the underlying backend function only accepts a |
| 260 | * signed int32 length. So throw error if the given value overflows |
| 261 | * int32. |
| 262 | */ |
| 263 | if (len > (size_t) INT_MAX) |
| 264 | { |
| 265 | appendPQExpBufferStr(&conn->errorMessage, |
| 266 | libpq_gettext("argument of lo_read exceeds integer range\n")); |
| 267 | return -1; |
| 268 | } |
| 269 | |
| 270 | argv[0].isint = 1; |
| 271 | argv[0].len = 4; |
| 272 | argv[0].u.integer = fd; |
| 273 | |
| 274 | argv[1].isint = 1; |
| 275 | argv[1].len = 4; |
| 276 | argv[1].u.integer = (int) len; |
| 277 | |
| 278 | res = PQfn(conn, conn->lobjfuncs->fn_lo_read, |
| 279 | (void *) buf, &result_len, 0, argv, 2); |
| 280 | if (PQresultStatus(res) == PGRES_COMMAND_OK) |
| 281 | { |
| 282 | PQclear(res); |
| 283 | return result_len; |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | PQclear(res); |
| 288 | return -1; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * lo_write |
no test coverage detected