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

Function exportFile

src/test/examples/testlo64.c:171–212  ·  view source on GitHub ↗

* exportFile - * export large object "lobjOid" to file "out_filename" * */

Source from the content-addressed store, hash-verified

169 *
170 */
171static void
172exportFile(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
214static void
215exit_nicely(PGconn *conn)

Callers

nothing calls this directly

Calls 3

lo_openFunction · 0.85
lo_closeFunction · 0.85
lo_readFunction · 0.50

Tested by

no test coverage detected