openldap/libraries/liblutil/tempnam.c

47 lines
703 B
C
Raw Normal View History

/* $OpenLDAP$ */
1998-10-25 11:15:45 +08:00
#include "portable.h"
#ifndef HAVE_TEMPNAM
1998-10-25 11:15:45 +08:00
#include <stdio.h>
1999-06-03 08:37:44 +08:00
#include <ac/stdlib.h>
1998-10-25 11:15:45 +08:00
#include <ac/string.h>
#include <ac/unistd.h>
1998-10-25 11:15:45 +08:00
#include "lutil.h"
char *
(tempnam)( const char *dir, const char *pfx )
1998-10-25 11:15:45 +08:00
{
char *s;
if ( dir == NULL ) {
dir = LDAP_TMPDIR;
1998-10-25 11:15:45 +08:00
}
/*
* allocate space for dir + '/' + pfx (up to 5 chars) + 6 trailing 'X's + 0 byte
*/
if (( s = (char *)malloc( strlen( dir ) + 14 )) == NULL ) {
return( NULL );
}
strcpy( s, dir );
strcat( s, "/" );
if ( pfx != NULL ) {
strcat( s, pfx );
}
strcat( s, "XXXXXX" );
mktemp( s );
if ( *s == '\0' ) {
free( s );
s = NULL;
}
return( s );
}
#endif /* TEMPNAM */