#include <wchar.h>
|
|
wchar_t *
wtmpnam (wchar_t *str); |
The buffer referenced by str is expected to be at least L_tmpnam bytes in length. L_tmpnam is defined in the include file stdio.h.
The environment variable TMPDIR (if set), the argument tmpdir (if non-NULL), the directory P_tmpdir, and the directory /tmp are tried, in the listed order, as directories in which to store the temporary file.
#include<stdio.h> //wtmpnam
#include<sys/stat.h> //S_IWUSR
#include<errno.h> //errno
int main()
{
//create a directory c:ystem emp
wmkdir(L"c:\\system\\temp", S_IWUSR);
wchar_t wbuf[L_tmpnam];
wchar_t rbuf[10];
//call wtmpnam() to create a file
wchar_t *rval = wtmpnam(wbuf);
errno = 0;
//open the file with the name returned by wtmpnam()
FILE *fp = wfopen(buf, L"w");
if (fp == NULL)
{
printf("fopen of file returned by wtmpnam() failed - errno %d ", errno);
return -1;
}
if(fp)
{
fwprintf(fp, L"%ls", L"check");
fclose(fp);
}
fp = wfopen(buf, L"r");
if(fp)
{
fwscanf(fp, L"%ls", rbuf);
fclose(fp);
}
printf("read from file: %ls\n", rbuf);
printf("argument buf: %ls\n", buf);
printf("return value: %ls\n", rval);
return 0;
}
Output
read from file: check
argument buf: /System/temp/tmp.0.U9UPTx
return value: /System/temp/tmp.0.U9UPTx
|
© 2005-2007 Nokia |