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

Function overwrite

src/test/examples/testlo64.c:112–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static void
113overwrite(PGconn *conn, Oid lobjId, pg_int64 start, int len)
114{
115 int lobj_fd;
116 char *buf;
117 int nbytes;
118 int nwritten;
119 int i;
120
121 lobj_fd = lo_open(conn, lobjId, INV_WRITE);
122 if (lobj_fd < 0)
123 fprintf(stderr, "cannot open large object %u", lobjId);
124
125 if (lo_lseek64(conn, lobj_fd, start, SEEK_SET) < 0)
126 fprintf(stderr, "error in lo_lseek64: %s", PQerrorMessage(conn));
127
128 buf = malloc(len + 1);
129
130 for (i = 0; i < len; i++)
131 buf[i] = 'X';
132 buf[i] = '\0';
133
134 nwritten = 0;
135 while (len - nwritten > 0)
136 {
137 nbytes = lo_write(conn, lobj_fd, buf + nwritten, len - nwritten);
138 nwritten += nbytes;
139 if (nbytes <= 0)
140 {
141 fprintf(stderr, "\nWRITE FAILED!\n");
142 break;
143 }
144 }
145 free(buf);
146 fprintf(stderr, "\n");
147 lo_close(conn, lobj_fd);
148}
149
150static void
151my_truncate(PGconn *conn, Oid lobjId, pg_int64 len)

Callers 1

mainFunction · 0.70

Calls 5

lo_openFunction · 0.85
lo_lseek64Function · 0.85
PQerrorMessageFunction · 0.85
lo_closeFunction · 0.85
lo_writeFunction · 0.50

Tested by

no test coverage detected