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

Method open

engine/source/platformAndroid/AndroidFileio.cpp:172–281  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Open a file in the mode specified by openMode (Read, Write, or ReadWrite). Truncate the file if the mode is either Write or ReadWrite and truncate is true. Sets capability appropriate to the openMode. Returns the currentStatus of the file. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

170// Returns the currentStatus of the file.
171//-----------------------------------------------------------------------------
172File::Status File::open(const char *filename, const AccessMode openMode)
173{
174 //If its a cache path then we need to open it using C methods not AssetManager
175 if (isCachePath(filename) || isUserDataPath(filename))
176 {
177 if (dStrlen(filename) > MAX_MAC_PATH_LONG)
178 Con::warnf("File::open: Filename length is pretty long...");
179
180 // Close the file if it was already open...
181 if (currentStatus != Closed)
182 close();
183
184 // create the appropriate type of file...
185 switch (openMode)
186 {
187 case Read:
188 capability = FileRead;
189 filePointer = 0;
190 buffer = (U8*)_AndroidLoadInternalFile(filename, &size);
191 if (buffer == NULL)
192 currentStatus = UnknownError;
193 else
194 currentStatus = Ok;
195 return currentStatus;
196 break;
197 case Write:
198 handle = (void *)fopen(filename, "wb"); // write only
199 break;
200 case ReadWrite:
201 handle = (void *)fopen(filename, "ab+"); // write(append) and read
202 break;
203 case WriteAppend:
204 handle = (void *)fopen(filename, "ab"); // write(append) only
205 break;
206 default:
207 AssertFatal(false, "File::open: bad access mode");
208 }
209
210 // handle not created successfully
211 if (handle == NULL)
212 return setStatus();
213
214 // successfully created file, so set the file capabilities...
215 switch (openMode)
216 {
217 case Read:
218 capability = FileRead;
219 break;
220 case Write:
221 case WriteAppend:
222 capability = FileWrite;
223 break;
224 case ReadWrite:
225 capability = FileRead | FileWrite;
226 break;
227 default:
228 AssertFatal(false, "File::open: bad access mode");
229 }

Callers 1

_AndroidGetTxtFileArgsFunction · 0.45

Calls 6

isCachePathFunction · 0.85
isUserDataPathFunction · 0.85
warnfFunction · 0.85
_AndroidLoadInternalFileFunction · 0.85
_AndroidLoadFileFunction · 0.85
dStrlenFunction · 0.70

Tested by

no test coverage detected