1998-10-25 11:15:45 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#ifndef HAVE_TEMPNAM
|
1998-10-25 11:15:45 +08:00
|
|
|
|
1998-11-16 13:07:27 +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>
|
1998-11-16 13:07:27 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-10-25 11:15:45 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include "lutil.h"
|
|
|
|
|
|
|
|
char *
|
1999-03-29 17:04:35 +08:00
|
|
|
(tempnam)( const char *dir, const char *pfx )
|
1998-10-25 11:15:45 +08:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
1998-11-16 13:07:27 +08:00
|
|
|
#endif /* TEMPNAM */
|