* exportFile - * export large object "lobjOid" to file "out_filename" * */
| 169 | * |
| 170 | */ |
| 171 | static void |
| 172 | exportFile(PGconn *conn, Oid lobjId, char *filename) |
| 173 | { |
| 174 | int lobj_fd; |
| 175 | char buf[BUFSIZE]; |
| 176 | int nbytes, |
| 177 | tmp; |
| 178 | int fd; |
| 179 | |
| 180 | /* |
| 181 | * open the large object |
| 182 | */ |
| 183 | lobj_fd = lo_open(conn, lobjId, INV_READ); |
| 184 | if (lobj_fd < 0) |
| 185 | fprintf(stderr, "cannot open large object %u", lobjId); |
| 186 | |
| 187 | /* |
| 188 | * open the file to be written to |
| 189 | */ |
| 190 | fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
| 191 | if (fd < 0) |
| 192 | { /* error */ |
| 193 | fprintf(stderr, "cannot open unix file\"%s\"", |
| 194 | filename); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * read in from the inversion file and write to the Unix file |
| 199 | */ |
| 200 | while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0) |
| 201 | { |
| 202 | tmp = write(fd, buf, nbytes); |
| 203 | if (tmp < nbytes) |
| 204 | { |
| 205 | fprintf(stderr, "error while writing \"%s\"", |
| 206 | filename); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | lo_close(conn, lobj_fd); |
| 211 | close(fd); |
| 212 | } |
| 213 | |
| 214 | static void |
| 215 | exit_nicely(PGconn *conn) |