Internationalization and localization tools


File and Path Function

int fopen(const char *filename, const char *pmode);

int _wfopen(const wchar_t *filename, const wchar_t *pmode);

int _tfopen(const TCHAR *filename, const TCHAR *pmode);

Internationalization (I18n) Function Overview

The fopen function opens a stream for I/O to the file filename with the access permission setting of pmode, and returns a pointer to the stream if successful; else NULL.

The pmode character string specifies the file access, and can be one of the following:

"r" to open the file for reading. If the file does not exist or cannot be found, the function call fails.
"w" to open an empty file for writing. If the given file exists, its contents are destroyed.
"a" to open the file for writing at the end of the file (appending); creates the file first if it doesn't exist.
"r+" to open the file for both reading and writing. (The file must exist.)
"w+" to open an empty file for both reading and writing. If the given file exists, its contents are destroyed.
"a+" to open the file for reading and appending; creates the file first if it doesn't exist.

Other characters may appear after these permissions characters to specify additional options for the call. However, always put the mode ("r", "w+", etc.) first; that is the only part you are guaranteed will be understood by all systems. See the MSDN Library for details on the various modes and their interactions on Windows systems; or the GNU C Library for flags supported by the GCC compiler.

On Windows platforms, _wfopen is the wide-character version of fopen; its arguments are wide-character strings. There is no ANSI wide-character equivalent.

_tfopen is the Windows-only Generic version of the function; with the _MBCS or _UNICODE compiler flags determining its mapping to either fopen or _wfopen.

I18n Issues

Use the appropriate version of the function as required for internationalization support.

On ANSI UTF-16 platforms, use a conversion function to convert the wide-character strings to multibyte-character strings and then call fopen.

See Pathnames for a discussion of path and filename considerations in an internationalized application, and File I/O, which addresses reading and writing non-ASCII text data files.

Recommended Replacements*

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

File and Path Functions

 

Lingoport internationalization and localization services and software