]> git.sur5r.net Git - openldap/blobdiff - clients/ud/edit.c
From jon@symas.com - patches for consistent use of directory separators
[openldap] / clients / ud / edit.c
index de640dc3803d6be6c4be9bc84f57b26c9af02ff9..9e208603837a77df31470154d294888f3382fb3d 100644 (file)
@@ -46,7 +46,6 @@
 #include <io.h>
 #endif
 
-#include <lber.h>
 #include <ldap.h>
 
 #include "ldap_defaults.h"
@@ -143,19 +142,29 @@ load_editor( void )
                printf("->load_editor()\n");
 #endif
 
-       /* write the entry into a temp file */
-       if (tmpnam(entry_temp_file) == NULL) {
-               perror("tmpnam");
-               return -1;
-       }
-       if ((tmpfd = open(entry_temp_file, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
-               perror(entry_temp_file);
+#ifdef HAVE_MKSTEMP
+       strcpy(entry_temp_file, LDAP_TMPDIR LDAP_DIRSEP "udXXXXXX");
+
+       tmpfd = mkstemp(entry_temp_file);
+
+       if( tmpfd < 0 ) {
+               perror("mkstemp");
                return -1;
        }
+
        if ((fp = fdopen(tmpfd, "w")) == NULL) {
                perror("fdopen");
                return(-1);
        }
+
+#else
+       fp = tmpfile();
+       if ( fp == NULL ) {
+               perror("tmpfile");
+               return(-1);
+       }
+#endif
+
        fprintf(fp, "## Directory entry of %s\n", Entry.name);
        fprintf(fp, "##\n");
        fprintf(fp, "## Syntax is:\n");
@@ -183,7 +192,7 @@ load_editor( void )
        if (verbose) {
                char    *p;
 
-               if (( p = strrchr( editor, '/' )) == NULL ) {
+               if (( p = strrchr( editor, *LDAP_DIRSEP )) == NULL ) {
                        p = editor;
                } else {
                        ++p;