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 <stdio.h>
    char *_tempnam( char *dir, char *prefix );
    wchar_t *_wtempnam( wchar_t *dir, wchar_t *prefix );

Description:
     _tempnam creates a temporary filename for use in another directory.
     This filename is different from that of any existing file.  The prefix
    argument is the prefix to the filename.  _tempnam uses  malloc to
    allocate space for the filename; the program is responsible for freeing
    this space when it is no longer needed.  _tempnam looks for the file
    with the given name in the following directories, listed in order of
    precedence.

    Directory Used
        Conditions

    Directory specified by TMP
        The  TMP environment variable must be set and the directory
        specified by  TMP must exist.

    dir (function argument)
        The  TMP environment variable must not be set or the directory
        specified by  TMP does not exist.

    _P_tmpdir (_wP_tmpdir) in STDIO.H
        The dir argument is NULL or dir is the name of a nonexistent
        directory.  The  _wP_tmpdir string is used by _wtempnam.

    Current working directory
         _tempnam uses the current working directory when  _P_tmpdir does
        not exist.  _wtempnam uses the current working directory when
         _wP_tmpdir does not exist.

    _tempnam automatically handles multibyte-character string arguments as
    appropriate, recognizing multibyte-character sequences according to the
    OEM code page obtained from the operating system.  _wtempnam is a
    wide-character version of _tempnam the arguments and return value of
    _wtempnam are wide-character strings.  _wtempnam and _tempnam behave
    identically except that _wtempnam does not handle multibyte-character
    strings.

    The function generates unique filenames for up to  TMP_MAX calls.

Returns:
    The _tempnam function returns a pointer to the name generated, unless it
    is impossible to create this name or the name is not unique.  If the
    name cannot be created or if a file with that name already exists,
    _tempnam returns NULL.

Example:
    #include <stdio.h>
    #include <stdlib.h>

    /*
      Environment variable TMP=C:\WINDOWS\TEMP
    */
    void main()
      {
        char *filename;

        FILE *fp;

        filename = _tempnam( "D:\\TEMP", "_T" );
        if( filename == NULL )
            printf( "Can't obtain temp file name\n" );
        else {
            printf( "Temp file name is %s\n", filename );
            fp = fopen( filename, "w+b" );
            /* . */
            /* . */
            /* . */
            fclose( fp );
            remove( filename );
            free( filename );
        }
      }

    produces the following:

    Temp file name is C:\WINDOWS\TEMP\_T1

Classification:
    WATCOM

Systems:
     _tempnam - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

    _wtempnam - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

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

See Also: tmpfile

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