mktemp.c 420 B

1234567891011121314151617181920
  1. /* mktemp - make a name for a temporary file */
  2. char *mktemp(template)
  3. char *template;
  4. {
  5. int pid, k;
  6. char *p;
  7. pid = getpid(); /* get process id as semi-unique number */
  8. p = template;
  9. while (*p++) ; /* find end of string */
  10. p--; /* backup to last character */
  11. /* Replace XXXXXX at end of template with pid. */
  12. while (*--p == 'X') {
  13. *p = '0' + (pid % 10);
  14. pid = pid/10;
  15. }
  16. return(template);
  17. }