tmpnam.c 405 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * pANS stdio -- tmpnam
  3. */
  4. #include "iolib.h"
  5. #include <string.h>
  6. char *
  7. tmpnam(char *s)
  8. {
  9. static char name[] = "/tmp/tn000000000000";
  10. char *p;
  11. do {
  12. p = name + 7;
  13. while (*p == '9')
  14. *p++ = '0';
  15. if (*p == '\0')
  16. return NULL;
  17. ++*p;
  18. } while (access(name, 0) == 0);
  19. if (s) {
  20. strcpy(s, name);
  21. return s;
  22. }
  23. return name;
  24. }
  25. char *
  26. tmpnam_r(char *s)
  27. {
  28. return s ? tmpnam(s) : NULL;
  29. }