MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / CopyFile

Function CopyFile

engine/source/platformEmscripten/EmscriptenFileio.cpp:100–136  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

98//------------------------------------------------------------------------------
99// copy a file from src to dest
100static bool CopyFile(const char* src, const char* dest)
101{
102 S32 srcFd = x86UNIXOpen(src, O_RDONLY);
103 S32 destFd = x86UNIXOpen(dest, O_WRONLY | O_CREAT | O_TRUNC);
104 bool error = false;
105
106 if (srcFd != -1 && destFd != -1)
107 {
108 const int BufSize = 8192;
109 char buf[BufSize];
110 S32 bytesRead = 0;
111 while ((bytesRead = x86UNIXRead(srcFd, buf, BufSize)) > 0)
112 {
113 // write data
114 if (x86UNIXWrite(destFd, buf, bytesRead) == -1)
115 {
116 error = true;
117 break;
118 }
119 }
120
121 if (bytesRead == -1)
122 error = true;
123 }
124
125 if (srcFd != -1)
126 x86UNIXClose(srcFd);
127 if (destFd != -1)
128 x86UNIXClose(destFd);
129
130 if (error)
131 {
132 Con::errorf("Error copying file: %s, %s", src, dest);
133 remove(dest);
134 }
135 return error;
136}
137
138//-----------------------------------------------------------------------------
139bool Platform::pathCopy(const char *fromName, const char *toName, bool nooverwrite)

Callers 2

pathCopyMethod · 0.70
openMethod · 0.70

Calls 6

errorfFunction · 0.85
removeFunction · 0.85
x86UNIXOpenFunction · 0.70
x86UNIXReadFunction · 0.70
x86UNIXWriteFunction · 0.70
x86UNIXCloseFunction · 0.70

Tested by

no test coverage detected