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

Function exportFile

src/test/examples/testlo.c:149–190  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

147 *
148 */
149static void
150exportFile(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
192static void
193exit_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