HFILE _lcreat(lpszFilename, fnAttribute) | |||||
LPCSTR lpszFilename; | /* address of file to open | */ | |||
int fnAttribute; | /* file attributes, */ |
The _lcreat function creates or opens a specified file. If the file does not exist, the function creates a new file and opens it for writing. If the file does exist, the function truncates the file size to zero and opens it for reading and writing. When the function opens the file, the pointer is set to the beginning of the file.
lpszFilename
Points to a null-terminated string that names the file to be opened. The string must consist of characters from the Windows character set.
fnAttribute
Specifies the file attributes. This parameter must be one of the following values:
Value | Meaning |
0 | Normal; can be read or written without restriction. |
1 | Read-only; cannot be opened for writing. |
2 | Hidden; not found by directory search. |
3 | System; not found by directory search. |
The return value is a file handle if the function is successful. Otherwise, it is HFILE_ERROR.
Use this function carefully. It is possible to open any file, even one that has already been opened by another function.
The following example uses the _lcreat function to open a temporary file:
HFILE hfTempFile;
char szBuf[144];
/* Create a temporary file. */
GetTempFileName(0, "tst", 0, szBuf);
hfTempFile = _lcreat(szBuf, 0);
if (hfTempFile == HFILE_ERROR) {
ErrorHandler();
}