Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    char *_mktemp( char *template );
    #include <wchar.h>
    wchar_t *_wmktemp( wchar_t *template );

Description:
    The _mktemp function creates a unique filename by modifying the template
    argument.  _mktemp automatically handles multibyte-character string
    arguments as appropriate, recognizing multibyte-character sequences
    according to the multibyte code page currently in use by the run-time
    system.

    The _wmktemp function is a wide-character version of _mktemp that
    operates with wide-character strings.

    The string template has the form baseXXXXXX where base is the fixed part
    of the generated filename and XXXXXX is the variable part of the
    generated filename.  Each of the 6 X's is a placeholder for a character
    supplied by _mktemp.  Each placeholder character in template must be an
    uppercase "X".  _mktemp preserves base and replaces the first of the 6
    trailing X's with a lowercase alphabetic character (a-z).  _mktemp
    replaces the following 5 trailing X's with a five-digit value this value
    is a unique number identifying the calling process or thread.

    _mktemp checks to see if a file with the generated name already exists
    and if so selects another letter, in succession, from "a" to "z" until
    it finds a file that doesn't exist.  If it is unsuccessful at finding a
    name for a file that does not already exist, _mktemp returns NULL.  At
    most, 26 unique file names can be returned to the calling process or
    thread.

Returns:
    The _mktemp function returns a pointer to the modified template.  The
    _mktemp function returns NULL if template is badly formed or no more
    unique names can be created from the given template.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

Example:
    #include <stdio.h>
    #include <string.h>
    #include <io.h>

    #define TMPLTE "_tXXXXXX"

    void main()
      {
        char name[sizeof(TMPLTE)];
        char *mknm;
        int i;
        FILE *fp;

        for( i = 0; i < 30; i++ ) {
          strcpy( name, TMPLTE );
          mknm = _mktemp( name );
          if( mknm == NULL )
            printf( "Name is badly formed\n" );
          else {
            printf( "Name is %s\n", mknm );
            fp = fopen( mknm, "w" );
            if( fp != NULL ) {
              fprintf( fp, "Name is %s\n", mknm );
              fclose( fp );
            }
          }
        }
      }

Classification:
    WATCOM

Systems:
     _mktemp - Win32

    _wmktemp - Win32

See Also:
    fopen, freopen, _tempnam, tmpfile, tmpnam

See Also: tmpfile

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson