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