| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

ftmp_open

#include "sflfile.h"
FILE *
ftmp_open (char **pathname)

Synopsis

Creates a temporary file, like the tmpfile() function, but without the problem under some systems where tmpfile() will try to create temporary files on read-only drives. If the pathname argument is not null, allocates a copy of the full filename used for the temporary file and passes this back in the pathname argument.

Source Code - (sflfile.c)

{
    static qbyte
        file_number = 0;                /*  We generate unique file names    */
    FILE
        *tempstream;
    char
        *tempdir,
        *tempfile;
    FTMPITEM
        *tempitem;

#if (defined (MSDOS_FILESYSTEM))
    tempdir = env get string  ("TEMP", NULL);
    if (!tempdir)
        tempdir = env get string  ("TMP", NULL);
    if (!tempdir)
        tempdir = ".";

#elif (defined (__UNIX__))
    tempdir = env get string  ("TMPDIR", NULL);
    if (!tempdir)
        tempdir = "/tmp";

#else
    tempdir = env get string  ("TMPDIR", NULL);
    if (!tempdir)
        tempdir = ".";
#endif
    if (file_number == 0)
      {
        randomize ();
        file_number = random (32767);
      }
    tempfile = get tmp file name (tempdir, &file_number, "tmp");
    if (pathname)
        *pathname = mem_strdup (tempfile);

    tempstream = fopen (tempfile, "wb");
    if (tempstream)
      {
        list_create (tempitem, sizeof (FTMPITEM));
        list_relink_before (&ftmplist, tempitem);
        tempitem-> stream   = tempstream;
        tempitem-> filename = tempfile;
      }
    else
        mem_free (tempfile);

    return (tempstream);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation