+/* $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.
#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
#include <process.h>
#endif
-#include <lber.h>
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+
#include <ldap.h>
-#include <ldap_defaults.h>
+
+#include "ldap_defaults.h"
#include "ud.h"
static int load_editor( void );
static int ovalues( char *attr );
static void write_entry( void );
-static char *entry_temp_file;
+static char entry_temp_file[L_tmpnam];
void
{
FILE *fp;
char *cp, *editor = UD_DEFAULT_EDITOR;
- static char template[MED_BUF_SIZE];
+ int tmpfd;
#ifndef HAVE_SPAWNLP
int pid;
int status;
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");
if (verbose) {
char *p;
- if (( p = strrchr( editor, '/' )) == NULL ) {
+ if (( p = strrchr( editor, *LDAP_DIRSEP )) == NULL ) {
p = editor;
} else {
++p;