home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_02 / 1002014c < prev    next >
Text File  |  1991-12-17  |  563b  |  31 lines

  1.  
  2. Listing 3 -- the file tmpnam.c
  3.  
  4. /* tmpnam function -- UNIX version */
  5. #include <string.h>
  6. #include "xstdio.h"
  7.  
  8.         /* UNIX system call */
  9. int _Getpid(void);
  10.  
  11. char *(tmpnam)(char *s)
  12.     {   /* create a temporary file name */
  13.     int i;
  14.     char *p;
  15.     unsigned short t;
  16.     static char buf[L_tmpnam];
  17.     static unsigned short seed = 0;
  18.  
  19.     if (s == NULL)
  20.         s = buf;
  21.     seed = seed == 0 ? _Getpid() : seed + 1;
  22.     strcpy(s, "/tmp/t");
  23.     i = 5;
  24.     p = s + strlen(s) + i;
  25.     *p = '\0';
  26.     for (t = seed; 0 <= --i; t >>= 3)
  27.         *--p = '0' + (t & 07);
  28.     return (s);
  29.     }
  30.  
  31.