nn::fs::TryCreateFile Function

Syntax

Result TryCreateFile(
     const wchar_t * pathName,
     s64 size
);

Result TryCreateFile(
     const char * pathName,
     s64 size
);

List of Overloaded Member Functions

TryCreateFile(const wchar_t *, s64) Creates a file.
TryCreateFile(const char *, s64) Creates a file.

Description of TryCreateFile(const wchar_t *, s64)

This function returns any error that occurs while it is creating the file.

If file creation fails, a garbage file may have been created. Call the TryDeleteFile function to delete it. If a garbage file has not been created, ResultNotFound is returned.

Which Result values need handling will differ, depending on the archive. For details, see Handling Errors During File and Directory Operations.

Note

After a file has been created with this function, if nothing has been written then in principle the process of reading will return nn::fs::ResultVerificationFailed.
However, if this function is called for save data or expanded save data, then the first 512 bytes (or the entire file if the size is 512 bytes or smaller) are guaranteed to be zero-initialized. By using this and writing to the file in the order (Create file > Write data and flush > Write file signature to front and flush), you can check that the file signature has been loaded correctly and guarantee that the file is written correctly.

Description of TryCreateFile(const char *, s64)

This function returns any error that occurs while it is creating the file.


Note: This function uses a large amount of buffer space on the stack because it converts the path name from a multibyte string into a wide string. Pay careful attention to the stack size.

If file creation fails, a garbage file may have been created. Call the TryDeleteFile function to delete it. If a garbage file has not been created, ResultNotFound is returned.

Which Result values need handling will differ, depending on the archive. For details, see Handling Errors During File and Directory Operations.

Note

After a file has been created with this function, if nothing has been written then in principle the process of reading will return nn::fs::ResultVerificationFailed.
However, if this function is called for save data or expanded save data, then the first 512 bytes (or the entire file if the size is 512 bytes or smaller) are guaranteed to be zero-initialized. By using this and writing to the file in the order (Create file > Write data and flush > Write file signature to front and flush), you can check that the file signature has been loaded correctly and guarantee that the file is written correctly.

CONFIDENTIAL