openldap/libraries/liblutil/tempnam.c
Kurt Zeilenga 403f4479bc Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
Replace old Id as needed (back-tcl).
Leave updating of contribWare to contributors (for now).
1999-09-08 19:06:24 +00:00

47 lines
698 B
C

/* $OpenLDAP$ */
#include "portable.h"
#ifndef HAVE_TEMPNAM
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include "lutil.h"
char *
(tempnam)( const char *dir, const char *pfx )
{
char *s;
if ( dir == NULL ) {
dir = "/tmp";
}
/*
* 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 */