MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / copyFile

Function copyFile

TheForceEngine/TFE_FileSystem/fileutil-posix.cpp:192–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190 }
191
192 void copyFile(const char *src, const char *dst)
193 {
194 ssize_t rd, wr;
195 char buf[1024], *fnd;
196 int s, d;
197
198 // assume the source is case-insensitive
199 fnd = findFileObjectNoCase(src, false);
200 if (!fnd)
201 return;
202
203 s = open(fnd, O_RDONLY);
204 free(fnd);
205 if (!s)
206 return;
207 d = open(dst, O_WRONLY | O_CREAT, 00644);
208 if (!d) {
209 close(s);
210 return;
211 }
212
213 do {
214 rd = read(s, buf, 1024);
215 if (rd <= 0)
216 break;
217 wr = write(d, buf, rd);
218 if (wr < 0 || wr != rd)
219 break;
220 } while (rd > 0);
221 close(d);
222 close(s);
223 }
224
225 void deleteFile(const char *fn)
226 {

Callers

nothing calls this directly

Calls 4

findFileObjectNoCaseFunction · 0.85
readFunction · 0.85
freeFunction · 0.50
writeFunction · 0.50

Tested by

no test coverage detected