MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / CopyFile

Function CopyFile

Engine/source/platformPOSIX/POSIXFileio.cpp:194–230  ·  view source on GitHub ↗

------------------------------------------------------------------------------ copy a file from src to dest

Source from the content-addressed store, hash-verified

192//------------------------------------------------------------------------------
193// copy a file from src to dest
194static bool CopyFile(const char* src, const char* dest)
195{
196 S32 srcFd = x86UNIXOpen(src, O_RDONLY);
197 S32 destFd = x86UNIXOpen(dest, O_WRONLY | O_CREAT | O_TRUNC);
198 bool error = false;
199
200 if (srcFd != -1 && destFd != -1)
201 {
202 const int BufSize = 8192;
203 char buf[BufSize];
204 S32 bytesRead = 0;
205 while ((bytesRead = x86UNIXRead(srcFd, buf, BufSize)) > 0)
206 {
207 // write data
208 if (x86UNIXWrite(destFd, buf, bytesRead) == -1)
209 {
210 error = true;
211 break;
212 }
213 }
214
215 if (bytesRead == -1)
216 error = true;
217 }
218
219 if (srcFd != -1)
220 x86UNIXClose(srcFd);
221 if (destFd != -1)
222 x86UNIXClose(destFd);
223
224 if (error)
225 {
226 Con::errorf("Error copying file: %s, %s", src, dest);
227 remove(dest);
228 }
229 return error;
230}
231
232bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
233{

Callers 3

dPathCopyFunction · 0.70
openMethod · 0.70
dPathCopyFunction · 0.50

Calls 5

x86UNIXOpenFunction · 0.85
x86UNIXReadFunction · 0.85
x86UNIXWriteFunction · 0.85
x86UNIXCloseFunction · 0.85
errorfFunction · 0.50

Tested by

no test coverage detected