O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Temporary Files

This chapter will examine a number of ways that a temporary file can be created under UNIX. Each of these has its advantages and disadvantages. The tmpnam(3) function is discouraged and is covered only because you will encounter it in existing code. The remaining functions can be used in new software.

Using the tmpnam(3) Function

The tmpnam(3) function generates a pathname for a new temporary file but does not create the temporary file itself. Its function synopsis is as follows:

#include <stdio.h>

char *tmpnam(char *buf);  /* Discouraged */

This function generates a temporary pathname in the directory given by the macro name P_tmpdir (defined in <stdio.h>). The argument buf must be null or point to a character buffer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required