]> 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 003ff60abf0023f9fc65aa256226c0a86f60c2f5..9e208603837a77df31470154d294888f3382fb3d 100644 (file)
@@ -1,4 +1,8 @@
 /* $OpenLDAP$ */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1994  Regents of the University of Michigan.
  * All rights reserved.
@@ -14,6 +18,7 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include <sys/stat.h>
 
 #include <ac/stdlib.h>
 
 #include <ac/wait.h>
 #include <ac/unistd.h>
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
@@ -35,7 +46,6 @@
 #include <io.h>
 #endif
 
-#include <lber.h>
 #include <ldap.h>
 
 #include "ldap_defaults.h"
@@ -47,7 +57,7 @@ static int  print_attrs_and_values( FILE *fp, struct attribute *attrs, short fla
 static int  ovalues( char *attr );
 static void write_entry( void );
 
-static char *entry_temp_file;
+static char entry_temp_file[L_tmpnam];
 
 
 void
@@ -120,7 +130,7 @@ load_editor( void )
 {
        FILE *fp;
        char *cp, *editor = UD_DEFAULT_EDITOR;
-       static char template[MED_BUF_SIZE];
+       int tmpfd;
 #ifndef HAVE_SPAWNLP
        int pid;
        int status;
@@ -132,16 +142,29 @@ load_editor( void )
                printf("->load_editor()\n");
 #endif
 
-       /* write the entry into a temp file */
-       (void) strcpy(template, "/tmp/udEdit.XXXXXX");
-       if ((entry_temp_file = mktemp(template)) == NULL) {
-               perror("mktemp");
+#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);
        }
-       if ((fp = fopen(entry_temp_file, "w")) == NULL) {
-               perror("fopen");
+
+#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");
@@ -169,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;