------------------------------------------------------------------------------ copy a file from src to dest
| 192 | //------------------------------------------------------------------------------ |
| 193 | // copy a file from src to dest |
| 194 | static 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 | |
| 232 | bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite) |
| 233 | { |
no test coverage detected