| 264 | } |
| 265 | |
| 266 | int CScriptFile::Open(const std::string &filename, const std::string &mode) |
| 267 | { |
| 268 | // Close the previously opened file handle |
| 269 | if( file ) |
| 270 | Close(); |
| 271 | |
| 272 | std::string myFilename = filename; |
| 273 | |
| 274 | // Validate the mode |
| 275 | string m; |
| 276 | #if AS_WRITE_OPS == 1 |
| 277 | if( mode != "r" && mode != "w" && mode != "a" ) |
| 278 | #else |
| 279 | if( mode != "r" ) |
| 280 | #endif |
| 281 | return -1; |
| 282 | else |
| 283 | m = mode; |
| 284 | |
| 285 | #ifdef _WIN32_WCE |
| 286 | // no relative pathing on CE |
| 287 | char buf[MAX_PATH]; |
| 288 | static TCHAR apppath[MAX_PATH] = TEXT(""); |
| 289 | if (!apppath[0]) |
| 290 | { |
| 291 | GetModuleFileName(NULL, apppath, MAX_PATH); |
| 292 | |
| 293 | int appLen = _tcslen(apppath); |
| 294 | while (appLen > 1) |
| 295 | { |
| 296 | if (apppath[appLen-1] == TEXT('\\')) |
| 297 | break; |
| 298 | appLen--; |
| 299 | } |
| 300 | |
| 301 | // Terminate the string after the trailing backslash |
| 302 | apppath[appLen] = TEXT('\0'); |
| 303 | } |
| 304 | #ifdef _UNICODE |
| 305 | wcstombs(buf, apppath, wcslen(apppath)+1); |
| 306 | #else |
| 307 | memcpy(buf, apppath, strlen(apppath)); |
| 308 | #endif |
| 309 | myFilename = buf + myFilename; |
| 310 | #endif |
| 311 | |
| 312 | |
| 313 | // By default windows translates "\r\n" to "\n", but we want to read the file as-is. |
| 314 | m += "b"; |
| 315 | |
| 316 | // Open the file |
| 317 | #if _MSC_VER >= 1400 && !defined(__S3E__) |
| 318 | // MSVC 8.0 / 2005 introduced new functions |
| 319 | // Marmalade doesn't use these, even though it uses the MSVC compiler |
| 320 | fopen_s(&file, myFilename.c_str(), m.c_str()); |
| 321 | #else |
| 322 | file = fopen(myFilename.c_str(), m.c_str()); |
| 323 | #endif |
no outgoing calls
no test coverage detected