------------------------------------------------------------------------------ copy a file from src to dest
| 98 | //------------------------------------------------------------------------------ |
| 99 | // copy a file from src to dest |
| 100 | static 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 | //----------------------------------------------------------------------------- |
| 139 | bool Platform::pathCopy(const char *fromName, const char *toName, bool nooverwrite) |
no test coverage detected