Back to index

cell-binutils  2.17cvs20070401
Defines | Functions
choose-temp.c File Reference
#include <stdio.h>
#include "libiberty.h"

Go to the source code of this file.

Defines

#define TEMP_FILE   "ccXXXXXX"
#define TEMP_FILE_LEN   (sizeof(TEMP_FILE) - 1)

Functions

char * choose_tmpdir (void)
char * choose_temp_base (void)

Define Documentation

#define TEMP_FILE   "ccXXXXXX"

Definition at line 37 of file choose-temp.c.

#define TEMP_FILE_LEN   (sizeof(TEMP_FILE) - 1)

Definition at line 38 of file choose-temp.c.


Function Documentation

char* choose_temp_base ( void  )

Definition at line 57 of file choose-temp.c.

{
  const char *base = choose_tmpdir ();
  char *temp_filename;
  int len;

  len = strlen (base);
  temp_filename = XNEWVEC (char, len + TEMP_FILE_LEN + 1);
  strcpy (temp_filename, base);
  strcpy (temp_filename + len, TEMP_FILE);

  if (mktemp (temp_filename) == 0)
    abort ();
  return temp_filename;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* choose_tmpdir ( void  )

Definition at line 97 of file make-temp-file.c.

{
  const char *base = 0;
  char *tmpdir;
  unsigned int len;

  if (memoized_tmpdir)
    return memoized_tmpdir;

  base = try_dir (getenv ("TMPDIR"), base);
  base = try_dir (getenv ("TMP"), base);
  base = try_dir (getenv ("TEMP"), base);

#ifdef P_tmpdir
  base = try_dir (P_tmpdir, base);
#endif

  /* Try /var/tmp, /usr/tmp, then /tmp.  */
  base = try_dir (vartmp, base);
  base = try_dir (usrtmp, base);
  base = try_dir (tmp, base);
 
  /* If all else fails, use the current directory!  */
  if (base == 0)
    base = ".";

  /* Append DIR_SEPARATOR to the directory we've chosen
     and return it.  */
  len = strlen (base);
  tmpdir = XNEWVEC (char, len + 2);
  strcpy (tmpdir, base);
  tmpdir[len] = DIR_SEPARATOR;
  tmpdir[len+1] = '\0';

  memoized_tmpdir = tmpdir;
  return tmpdir;
}

Here is the call graph for this function:

Here is the caller graph for this function: