Defines Space for Temporary Files
Defines Space for Temporary Files
Provide a pool of filenames for intermediate results.
- Define temp file default (DEFAULT_TMPDIR)
- Constant definition
- Segment Source
- 59: #ifndef DEFAULT_TMPDIR
60: #define DEFAULT_TMPDIR "/tmp"
61: #endif
62:
- Define tempname()
-
Function definition
-
Generate a bunch of distinct file names.
- Notes
-
The parts of this routine that manage the tempnode list
are actually part of the TempMngr concern.
- Segment Source
-
399: /* Return a name for a temporary file. */
400:
401: static char *
402: tempname (void)
403: {
404: static unsigned int seq;
405: int len = strlen (temp_file_prefix);
406: char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1);
407: struct tempnode *node;
408:
409: node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
410: sprintf (name,
411: "%s%ssort%5.5d%5.5d",
412: temp_file_prefix,
413: (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
414: (unsigned int) getpid () & 0xffff, seq);
415:
416: /* Make sure that SEQ's value fits in 5 digits. */
417: ++seq;
418: if (seq >= 100000)
419: seq = 0;
420:
421: node->name = name;
422: node->next = temphead.next;
423: temphead.next = node;
424: return name;
425: }
426: