]> git.sur5r.net Git - openldap/blob - libraries/liblutil/tempnam.c
Framework for back-bdb
[openldap] / libraries / liblutil / tempnam.c
1 /* $OpenLDAP$ */
2 #include "portable.h"
3
4 #ifndef HAVE_TEMPNAM
5
6 #include <stdio.h>
7
8 #include <ac/stdlib.h>
9 #include <ac/string.h>
10 #include <ac/unistd.h>
11
12 #include "lutil.h"
13
14 char *
15 (tempnam)( const char *dir, const char *pfx )
16 {
17     char        *s;
18
19     if ( dir == NULL ) {
20         dir = LDAP_TMPDIR;
21     }
22
23 /*
24  * allocate space for dir + '/' + pfx (up to 5 chars) + 6 trailing 'X's + 0 byte
25  */
26     if (( s = (char *)malloc( strlen( dir ) + 14 )) == NULL ) {
27         return( NULL );
28     }
29
30     strcpy( s, dir );
31     strcat( s, "/" );
32     if ( pfx != NULL ) {
33         strcat( s, pfx );
34     }
35     strcat( s, "XXXXXX" );
36     mktemp( s );
37
38     if ( *s == '\0' ) {
39         free( s );
40         s = NULL;
41     }
42
43     return( s );
44 }
45
46 #endif /* TEMPNAM */