home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuawk.zip / atari / tmpnam.c < prev   
C/C++ Source or Header  |  1995-09-08  |  1KB  |  48 lines

  1. #ifdef PIPES_SIMULATED
  2. /* tmpnam.c : return a temporary file name */
  3. /* written by Eric R. Smith and placed in the public domain */
  4. /**
  5.  *  - modified for gawk needs - pattern /$$XXXXXX from the original
  6.  *    code creates names which are hard to remove when somethig
  7.  *    goes wrong
  8.  *  - returned name can be passed outside via system(); other programs
  9.  *    may not dig '/' as a path separator
  10.  *  - somehow more frugal in a memory use
  11.  *    (mj - October 1990)
  12.  **/
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. extern char *    getenv(const char *);
  18. extern char *    mktemp(char *);
  19. char *          tempnam(const char *path, const char *base);
  20. static char pattern[] = "\\gwkXXXXX";
  21.  
  22. char *tmpnam(buf)
  23.     char *buf;
  24. {
  25.     char *tmpdir;
  26.  
  27.     if (!(tmpdir = getenv("TEMP")) && !(tmpdir = getenv("TMPDIR")))
  28.         tmpdir = ".";
  29.  
  30.     if (!buf) {
  31.         size_t blen;
  32.         
  33.         blen = strlen (tmpdir) + sizeof(pattern);
  34.         if (NULL == (buf = malloc(blen)))
  35.             return NULL;
  36.     }
  37.     (void) strcat(strcpy(buf, tmpdir), pattern);
  38.     return(mktemp(buf));
  39. }
  40.  
  41. /* used by gawk_popen() */
  42. char *tempnam(path, base)
  43. const char *path, *base;    /* ignored */
  44. {
  45.     return tmpnam(NULL);
  46. }
  47. #endif /* PIPES_SIMULATED */
  48.