]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/tempnam.c
New files from Autoconf branch.
[openldap] / libraries / liblutil / tempnam.c
diff --git a/libraries/liblutil/tempnam.c b/libraries/liblutil/tempnam.c
new file mode 100644 (file)
index 0000000..9aa2187
--- /dev/null
@@ -0,0 +1,38 @@
+#include "portable.h"
+
+#ifndef HAVE_TEMPNAME
+
+#include <ac/string.h>
+
+char *tempnam( char *dir, 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 /* nextstep */