* exportFile - * export large object "lobjOid" to file "out_filename" * */
| 147 | * |
| 148 | */ |
| 149 | static void |
| 150 | exportFile(PGconn *conn, Oid lobjId, char *filename) |
| 151 | { |
| 152 | int lobj_fd; |
| 153 | char buf[BUFSIZE]; |
| 154 | int nbytes, |
| 155 | tmp; |
| 156 | int fd; |
| 157 | |
| 158 | /* |
| 159 | * open the large object |
| 160 | */ |
| 161 | lobj_fd = lo_open(conn, lobjId, INV_READ); |
| 162 | if (lobj_fd < 0) |
| 163 | fprintf(stderr, "cannot open large object %u", lobjId); |
| 164 | |
| 165 | /* |
| 166 | * open the file to be written to |
| 167 | */ |
| 168 | fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
| 169 | if (fd < 0) |
| 170 | { /* error */ |
| 171 | fprintf(stderr, "cannot open unix file\"%s\"", |
| 172 | filename); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * read in from the inversion file and write to the Unix file |
| 177 | */ |
| 178 | while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0) |
| 179 | { |
| 180 | tmp = write(fd, buf, nbytes); |
| 181 | if (tmp < nbytes) |
| 182 | { |
| 183 | fprintf(stderr, "error while writing \"%s\"", |
| 184 | filename); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | lo_close(conn, lobj_fd); |
| 189 | close(fd); |
| 190 | } |
| 191 | |
| 192 | static void |
| 193 | exit_nicely(PGconn *conn) |