Name

wtmpnam - generate temporary file name.

Library

libc.lib

Synopsis

  #include <wchar.h>
  wchar_t * wtmpnam (wchar_t *str);

Return values

The wtmpnam function return a pointer to a file name on success, and a NULL pointer on error.

Detailed description

The wtmpnam function returns a pointer to a file name, in the P_tmpdir directory, which did not reference an existing file at some indeterminate point in the past. P_tmpdir is defined in the include file stdio.h. If the argument str is non-NULL, the file name is copied to the buffer it references. Otherwise, the file name is copied to a static buffer. In either case, wtmpnam returns a pointer to the file name.

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.


Examples

#include<stdio.h> //wtmpnam
#include<sys/stat.h> //S_IWUSR
#include<errno.h> //errno
  
int main()
{
 //create a directory c:\system 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

         

Errors

The wtmpnam function may fail and set errno for any of the errors specified for the library function mktemp.


See also

mktemp, tmpnam

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top