tempnam.c 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #if defined( nextstep )
  13. #include <string.h>
  14. char *tempnam( char *dir, char *pfx );
  15. char *tempnam( char *dir, char *pfx )
  16. {
  17. char *s;
  18. if ( dir == NULL ) {
  19. dir = "/tmp";
  20. }
  21. /*
  22. * allocate space for dir + '/' + pfx (up to 5 chars) + 6 trailing 'X's + 0 byte
  23. */
  24. if (( s = (char *)slapi_ch_malloc( strlen( dir ) + 14 )) == NULL ) {
  25. return( NULL );
  26. }
  27. strcpy( s, dir );
  28. strcat( s, "/" );
  29. if ( pfx != NULL ) {
  30. strcat( s, pfx );
  31. }
  32. strcat( s, "XXXXXX" );
  33. mktemp( s );
  34. if ( *s == '\0' ) {
  35. slapi_ch_free( (void**)&s );
  36. }
  37. return( s );
  38. }
  39. #else /* nextstep */
  40. typedef int SHUT_UP_DAMN_COMPILER;
  41. #endif /* nextstep */