Temporary File Management
Temporary File Management
Centralized management of temporary files for all applications.
A key behavior is to delete of all intermediate files on program exit.
Notes
The inserted calls to cleanup are really part of the
overall exit behavior.
Since that code is not localized, these extensions have to
be made all over.
- Declare temporary file structure (tempnode{})
- Structure declaration
- Segment Source
-
258: /* The list of temporary files. */
259: static struct tempnode
260: {
261: char *name;
262: struct tempnode *next;
263: } temphead;
264:
- Define cleanup()
-
Function definition
- Segment Source
-
265: /* Clean up any remaining temporary files. */
266:
267: static void
268: cleanup (void)
269: {
270: struct tempnode *node;
271:
272: for (node = temphead.next; node; node = node->next)
273: unlink (node->name);
274: }
275:
- Remember allocated temporaries
-
Function definition
- Segment Source
- 318: static FILE *
319: xtmpfopen (const char *file)
320: {
321: FILE *fp;
322: int fd;
323:
324: fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
325: if (fd < 0 || (fp = fdopen (fd, "w")) == NULL)
326: {
327: error (0, errno, "%s", file);
328: cleanup ();
329: exit (SORT_FAILURE);
330: }
331:
332: return fp;
333: }
334:
- Extend tempname()
-
Keep track of temporary files allocated by the sort
process so these can be cleaned-up on program termination
(either normal or aborted termination).
Segment Element
Code insertion
- 407: struct tempnode *node;
408:
409: node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
Segment Element
Code insertion
-
ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝύύύύ
- Define zaptemp()
-
Function definition
- Segment Source
-
427: /* Search through the list of temporary files for NAME;
428: remove it if it is found on the list. */
429:
430: static void
431: zaptemp (char *name)
432: {
433: struct tempnode *node, *temp;
434:
435: for (node = &temphead; node->next; node = node->next)
436: if (!strcmp (name, node->next->name))
437: break;
438: if (node->next)
439: {
440: temp = node->next;
441: unlink (temp->name);
442: free (temp->name);
443: node->next = temp->next;
444: free ((char *) temp);
445: }
446: }
447:
- Cleanup on program exit
-
Code insertion
- Segment Source
- 2129: cleanup ();