Listing 10
/*
* tmpname.c - Generate a temporary filename (in the TMP directory).
* usage:
* tmpname [<prefix>]
* where <prefix> specifies the first few chars of the new name.
* Sends the output to stdout.
*
* Compile
* cc tmpname.c -o tmpname
*/
#include <stdio.h>
#define TMP "/tmp"
main(argc, argv)
int argc;
char **argv;
{
int i, j;
char prefix[20];
prefix[0] = '\0';
if (argc == 2) /* user user-supplied prefix, */
strcpy(prefix,argv[1]); /* if any */
puts(tempnam(TMP, prefix)); /* write output to stdout */
}
|