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

Function overwrite

src/test/examples/testlo.c:107–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 4

lo_openFunction · 0.85
lo_lseekFunction · 0.85
lo_closeFunction · 0.85
lo_writeFunction · 0.50

Tested by

no test coverage detected